Tevya
Tevya

Reputation: 864

How do I specify that the collection parameter for a mocked method should have exactly one element

I am setting expectations for a method that takes a single IList<> parameter.

How do I express in NMock3 the following statement:

Method XX of the mock should be called exactly once with a list object that contains exactly one item.

The solution I imagine would be something like the following:

theMock.Expects.One.Method(_ =>_XX(null)).With(***mystery-mocking-goes-here***);

Upvotes: 0

Views: 174

Answers (1)

Use Is.Match:

theMock.Expects.One.Method(_ =>_XX(null)).With(Is.Match<IList<string>>(l => l.Count == 1));

Explanation for Anantha Raju C

If you have a method to test _XX(T). In the With method you have to pass a T object or a matcher. Is.Match create it and need a Predicate as argument.

In this example, the Predicate will return true if the list contains only one item (l.Count == 1).

Upvotes: 0

Related Questions