I am trying to assert that a property in a mock object was set with a given type. The property has an abstract type and is set with one of a number of concrete types.
This is what I'm trying to do, and it's always passing the test regardless of the value that Foo.DoSomething() sets Foo.Bar with:
[Test]
public void DoSomething_SetsCorrectBar()
{
// Arrange
Foo foo = MockRepository.GenerateMock<Foo>(); // Creates mock in Replay mode (what I want for AAA syntax).
// Act
foo.DoSomething();
// Assert that DoSomething set Foo.Bar to an instance of CorrectBarSubclass
foo.AssertWasCalled(foo => foo.Bar = null, options => options.WhenCalled(invocation => Assert.That(invocation.Arguments[0] is CorrectBarSubclass)));
}
The Rhino 3.5 / AAA Documentation describes how to set expectations on property sets having a given value, but I just want to check the type of the value.
How does one assert on a property set, specifically on a property set having a given parameter type?
Update: The example above is oversimplified. What I'm actually testing is an individual state class. It's one of several states that a "parent object" (the object having the state, Foo in this case) can be in. I was verifying that the state under test (call it BarOne) correctly set Foo.State to an instance of BarTwo when it was time to transition states.
A clearer example (with the accepted solution implemented) would be:
[Test]
public void BarOne_DoSomething_SetsNextState()
{
// Arrange
Foo foo = MockRepository.GenerateMock<Foo>(); // Creates mock in Replay mode (what I want for AAA syntax).
foo.Stub(x => x.CreateBarTwoState()).Return(new BarTwo(foo));
BarOne bar = new BarOne(foo); // We are testing the BarOne state independently of Foo, that's why we mock Foo but instantiate BarOne.
// Act
bar.DoSomething();
// Assert that DoSomething set Foo.Bar to an instance of BarTwo
foo.AssertWasCalled(foo => foo.Bar = Arg<BarTwo>.Is.TypeOf);
}