Search code examples
c#unit-testingrhino-mocksrhino-mocks-3.5

Rhino mocks assertwascalled with indexer and args


I'm trying to assert the following was called

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

and I can't work out the syntax for indexers with args, I have this

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

but its asking for the indexer to use args as well, how do I do this?


Solution

  • It's pretty simple :)

    I assume your indexer parameter type is string. Then in assertion instead of

    x[TypeName]
    

    use

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

    As result your assert should look:

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