Reputation: 7372
I have the following function signature:
T SomeMethod(Expression<Func<T, string>> param1,
, params Expression<Func<T, object>>[] items);
I want it to throw an exception everytime it's executed.
I tried to do the following setup:
myMock.Setup(x => x.SomeMethod(Moq.It.IsAny<Expression<Func<SomeClass, string>>>()))
.Throws(new Exception());
Everything works find but when I arrive to this method it does't throw an exception (although the object is my mock).
I assume my setup is incorrect.
I tried many variation for a while and now I'm a bit frustrated.
I would have put more code but it is restricted. Each piece I want to upload I should alter so excuse me for being cheap with information.
Hope it's enough and some one can assist me.
Upvotes: 10
Views: 15070
Reputation: 12654
Looks like the problem is in the params
parameter. Try adding it to the setup
myMock.Setup(x => x.SomeMethod(
Moq.It.IsAny<Expression<Func<SomeClass, string>>>()),
Moq.It.IsAny<Expression<Func<T, object>>[]>())
).Throws(new Exception());
Upvotes: 15