Maybe something like this:
[Test] public void AddPlayer_GivesGameEnoughPlayersToStart_SetsNextState() { // Arrange Foo foo = MockRepository.GenerateMock<Foo>(); // Creates mock in Replay mode (what I want for AAA syntax). foo.Expect(m => m.Bar = Arg<CorrectBarSubclass>.Is.TypeOf); // Act foo.DoSomething(); //Assert foo.VerifyAllExpectations(); }
So what's going on ..
We changed the statement as Pending. I find it a little cleaner, also waiting allows us a cleaner test of what type is. We say, โWe expect Bar be installed in the instance of CorrectBarSubclass . Then we act and claim that our expectation is fulfilled.
A couple of things: every time you mock a class, all you have to do is call Expect or Stub should be virtual or abstract, so in this case Bar should be virtual. As a rule of thumb, itโs always better to make fun of the interface and check how the class uses dependency, rather than test how the class uses itself (which is usually a sign of excessive testing or incorrect separation of problems).
In your case, is this even a layout? You simply use a somewhat complicated syntax to claim the result of real behavior, but nothing really mocks but the property setter. Sometimes it's just easier and, more appropriate, checking for real behavior. Why not do something like this:
var foo = new Foo(); foo.DoSomething(); Assert.That(foo.Bar is CorrectBarSubclass);
source share