In a specific unit test, I try to raise an event several times, and then to confirm the value of the property after the final event has been raised. I have something like
public void TurnRight() { var mockFoo = new Mock<IFoo>(); SomeService someService= new SomeService (); someService.Foo= mockFoo.Object; mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); mockFoo.VerifySet(foo=> foo.Orientation = Orientation.West); }
The orientation actually only changed east (as I believe, the event only rises once). Am I doing something wrong? This is the first time I've used moq, so I probably missed something.
Cheers J
change ... the correct code that I had to use
public void TurnRight() { var mockFoo = new Mock<IFoo>(); SomeService someService= new SomeService (); someService.Foo= mockFoo.Object; mockFoo.SetupProperty(foo=> foo.Orientation); mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); mockFoo.Raise(foo=> foo.TurnedRight += null, EventArgs.Empty); Assert.AreEqual(mockFoo.Object.Orientation, Orientation.South); }
c # unit-testing moq
James hay
source share