0
[TestClass]
public class FooTests {
[TestMethod]
public void TestFoo() {
var fooMock = MockRepository.GenerateMock<IFoo>();
// MUT
FooUser.Run(fooMock);
var stream = fooMock.Content;
stream.Position = 0;
var first = stream.ReadByte();
Assert.AreEqual(0x77, (byte) first);
var second = stream.ReadByte();
Assert.AreEqual(0x78, (byte) second);
}
}
public class Foo :IFoo {
public Stream Content { get; set; }
}
public class FooUser {
public static void Run(IFoo foo) {
foo.Content = new MemoryStream(new byte[] {0x77, 0x78});
}
}
public interface IFoo {
Stream Content { get; set; }
}
AssertWasCalled
似乎不適合驗證流。如何使用Rhino Mocks捕獲Stream屬性的值?
fooMock.Content.Stub(aStream => stream = aStream);
拋出異常:
System.ArgumentNullException: You cannot mock a null instance
Parameter name: mock
注:好像痣會的工作對於這個問題更好。