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
I've detected the behavior in Moq 4.2.1502.0911, and it's probably related to #156
Let's consider Stream as an example, see the relevant excerpts of the implementation of Stream:
public class Stream : IDisposable
{
public void Dispose()
{
Close();
}
public virtual void Close()
{
.....
}
}
Note: Dispose() does not have the virtual identifier (but is inherited from an interface) and Close is virtual.
I've used to test the usage of a Stream as follows:
var streamMock = new Mock<Stream>();
using(var stream = streamMock.Object) { }
// non-mocked Dispose methods calls Close which is virtual and can thus be verified
streamMock.Verify(x => x.Close());
However, with the current Moq version this fails, resulting in the following error:
Expected invocation on the mock once, but was 0 times: x => x.Close()
No setups configured.
Performed invocations:
IDisposable.Dispose()
so actually Mock mocks (intercepts) IDispoable.Dispose(). But verifying that Dispose was called fails:
streamMock.Verify(x => x.Dispose());
results in:
System.NotSupportedException : Invalid verify on a non-virtual (overridable in VB) member: x => x.Dispose()
However i think the current behavior is inconsistent.
I don't mind Moq intercepting the Dispose method, but then i would expect streamMock.Verify(x => x.Dispose()) to pass.
The text was updated successfully, but these errors were encountered:
I've detected the behavior in Moq 4.2.1502.0911, and it's probably related to #156
Let's consider
Stream
as an example, see the relevant excerpts of the implementation ofStream
:Note:
Dispose()
does not have the virtual identifier (but is inherited from an interface) andClose
is virtual.I've used to test the usage of a
Stream
as follows:However, with the current Moq version this fails, resulting in the following error:
so actually Mock mocks (intercepts)
IDispoable.Dispose()
. But verifying that Dispose was called fails:results in:
I've found a workaround, which is:
However i think the current behavior is inconsistent.
I don't mind Moq intercepting the
Dispose
method, but then i would expectstreamMock.Verify(x => x.Dispose())
to pass.The text was updated successfully, but these errors were encountered: