You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normally it would fail on MockException, but if that is caught, Verify will pass.
See following code:
[TestClass]publicclassStrictVerify{[TestMethod]publicvoidTest(){varmock=newMock<IToMock>(MockBehavior.Strict);
mock.Setup(m => m.Action("mistake"));varsut=new Sut();
sut.DoSomething(mock.Object,"action");// won't throw MockException due to catch inside.
mock.Verify(m => m.Action("action"), Times.Once());//passes}}publicinterfaceIToMock{voidAction(stringparam);}publicclassSut{publicvoidDoSomething(IToMockobj,stringparam){try{
obj.Action(param);}catch(Exception){//handle exception without rethrow.}}}
I would expect Verify to respect MockBehavior.Strict and fail in this case, because even though invocation was performed once, it was prohibited by mock and should not count as correct one.
The text was updated successfully, but these errors were encountered:
Swallowing all exceptions is hardly a good practice. Your code should only handle what it can recover from. It's unlikely it can recover from anything, like a ThreadAbort, OutOfMemory or the like. Likewise, it shouldn't be able to recover from a MockExcepcion
Normally it would fail on MockException, but if that is caught, Verify will pass.
See following code:
I would expect Verify to respect MockBehavior.Strict and fail in this case, because even though invocation was performed once, it was prohibited by mock and should not count as correct one.
The text was updated successfully, but these errors were encountered: