-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behaviour with MockExtensions.Reset #220
Comments
I'm also experiencing this confusion with what this method is supposed to accomplish. I think it does exactly what it says it does, but perhaps the documentation around it is a bit misleading about what "mock state, including setups" means. For example, all of these tests fail on the [TestClass]
public class MoqResetVerifyTests {
[TestMethod]
[TestCategory("Unit")]
public void Loose()
{
var myMock = new Mock<IEnumerable<int>>(MockBehavior.Loose);
myMock
.Setup(a => a.ToString())
.Returns("Hello");
myMock.Reset();
Assert.AreNotEqual("Hello", myMock.Object.ToString());
myMock.VerifyAll();
}
[TestMethod]
[TestCategory("Unit")]
public void Strict()
{
var myMock = new Mock<IEnumerable<int>>(MockBehavior.Strict);
myMock
.Setup(a => a.ToString())
.Returns("Hello");
myMock.Reset();
Assert.AreNotEqual("Hello", myMock.Object.ToString());
myMock.VerifyAll();
}
[TestMethod]
[TestCategory("Unit")]
public void LooseNoCall()
{
var myMock = new Mock<IEnumerable<int>>(MockBehavior.Loose);
myMock
.Setup(a => a.ToString())
.Returns("Hello");
myMock.Reset();
myMock.VerifyAll();
}
[TestMethod]
[TestCategory("Unit")]
public void StrictNoCall()
{
var myMock = new Mock<IEnumerable<int>>(MockBehavior.Strict);
myMock
.Setup(a => a.ToString())
.Returns("Hello");
myMock.Reset();
myMock.VerifyAll();
}
} |
Could you post the failures too, for the record? On Thu, Jun 23, 2016 at 3:27 PM Christopher Corley notifications@github.com
|
Sure, sorry for leaving that out! This is with Moq 4.5.10, targeting .NET 4.5.2. The project is blank, with the exception of UnitTest1.cs, which contains previous class.
|
The only test for Reset shows that for a loose mock set up with a return value, after Reset has been called, the return value defaults. Aside from the additional reset calls is this the only intended behaviour ? I ask as this is not what I expected from the documentation ( although I am not familiar with Testeroids if this is the sole purpose )
I expected that the mock would behave as if no setup had been done. e.g a strict mock will not throw when invoking a method that has been setup but will when reset has subsequently been called.
The text was updated successfully, but these errors were encountered: