public void YouCanUseAssertWasCalledWithPropertiesOnAStub() { // Create a stub. ISampleClass stub = CreateStub(); // Set the property. stub.Property = "foo"; // Get the property. stub.Property.Should(Be.EqualTo("foo")); // Check that the property was set and get. stub.Received().Property = "foo"; stub.Received().Property.Should(Be.Null); }
public void YouCanCheckToSeeIfAMethodWasCalledACertainNumberOfTimes() { // Create a stub. ISampleClass stub = CreateStub(); // Call some methods. stub.MethodThatReturnsInteger("foo"); stub.MethodThatReturnsInteger("bar"); // This will pass. stub.Received(1).MethodThatReturnsInteger("foo"); // Call the method a second time. stub.MethodThatReturnsInteger("foo"); // Now this will fail because we called it a second time. Assert.Throws <ReceivedCallsException>(() => stub.Received(1).MethodThatReturnsInteger("foo")); // Some other options. stub.Received(2).MethodThatReturnsInteger("foo"); }
public void YouCanCheckToSeeIfAMethodWasCalled() { // Create a stub. ISampleClass stub = CreateStub(); // Call some method. stub.MethodThatReturnsInteger("foo"); // Check that particular method was called. stub.Received().MethodThatReturnsInteger("foo"); stub.ReceivedWithAnyArgs().MethodThatReturnsInteger(Arg.Any <string>()); }
public void YouCanClearReceivedCalls() { // Create a stub. ISampleClass stub = CreateStub(); // Call some method. stub.MethodThatReturnsInteger("foo"); // Check that method was called. stub.Received().MethodThatReturnsInteger("foo"); stub.ClearReceivedCalls(); // Check that method was not called. stub.DidNotReceiveWithAnyArgs().MethodThatReturnsInteger(Arg.Any <string>()); }