Question

If you have a property:

public class Fred
{
   public string UserName
   {
     set
     {
        userName=value;
     }
   }
}

how do you use Rhino Mocks to check that

fred= new Fred();
fred.UserName="Jim";

is called.

Expect.Call(mockFred.UserName).SetPropertyWithArgument("Jim");

does not compile.

Was it helpful?

Solution

You should just be able to do a verify all on the property set

[TestClass]
public class FredTests
{
    [TestMethod]
    public void TestFred()
    {
        var mocker = new MockRepository();
        var fredMock = mocker.DynamicMock<IFred>();

        fredMock.UserName = "Name";
        // the last call is actually to the set method of username
        LastCall.IgnoreArguments(); 
        mocker.ReplayAll();

        fredMock.UserName = "Some Test that does this.";
        mocker.VerifyAll();
    }

}

public interface IFred
{
    string UserName { set; }
}

OTHER TIPS

public interface IFred
{
    string UserName { set; }
}

[Test]
public void TestMethod1()
{
    IFred fred = MockRepository.GenerateMock<IFred>();
    fred.UserName = "Jim";
    fred.AssertWasCalled(x => x.UserName = "Jim");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top