【问题标题】:Rhino mocks assertwascalled with indexer and argsRhino mocks assertwascalled with indexer 和 args
【发布时间】:2012-12-13 16:54:18
【问题描述】:

我试图断言以下被调用

cacheManager.Site[typeName] = items.Where(x => !requestContext.DefaultSites.Contains(x.SiteId)).ToList();

我无法计算出带有 args 的索引器的语法,我有这个

manager.Site.AssertWasCalled(x => x[TypeName] = Arg<IList<FcCacheObject>>.Matches(y => y.Count.Equals(1)));

但它要求索引器也使用 args,我该怎么做?

【问题讨论】:

  • 您使用的是模拟还是存根?显示您尝试测试的方法的完整签名以及测试设置代码会有所帮助。

标签: c# unit-testing rhino-mocks rhino-mocks-3.5


【解决方案1】:

这很简单:)

我假设您的索引器参数类型是string。然后在断言中而不是

x[TypeName]

使用

x[Arg<string>.Is.Equal(TypeName)]

因此你的断言应该是这样的:

manager.Site.AssertWasCalled(x => x[Arg<string>.Is.Equal(TypeName)] = Arg<IList<FcCacheObject>>.Matches(y => y.Count.Equals(1)));

【讨论】:

    猜你喜欢
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多