1
我是新来嘲笑,所以我需要一点关于如何嘲笑HttpPostedFileBase犀牛嘲笑的指导。我想验证我的ToByteArray()扩展按预期工作,这是我到目前为止有:嘲笑HttpPostedFileBase与犀牛嘲笑
[Test]
public void Should_return_a_byte_array_with_a_length_of_eleven()
{
// Arrange
var stream = new MemoryStream(System.Text.Encoding.Default.GetBytes("TestContent"));
var httpPostedFileBase = MockRepository.GenerateMock<HttpPostedFileBase>();
httpPostedFileBase.Expect(x => x.InputStream).Return(stream);
httpPostedFileBase.Expect(x => x.ContentLength).Return(11);
// Act
var byteArray = httpPostedFileBase.ToByteArray();
// Assert
Assert.That(byteArray.Length, Is.EqualTo(11));
}
我可以告诉大家,值获取设置,而是由时间我extensionmethod得到HttpPostedFileBase它已经失去了所有的价值。任何帮助将非常感激。
/的Kristoffer
感谢您的回复! 我试过这个,但我仍然在“预计:11但是:0”。在ToByteArray()和ToByteArray()之后调用ToByteArray()和VerifyAllExpectations()之前,我放置了Replay()。 我以前听说过有关嘲笑的观点,但我不确定我是否会以另一种方式验证这一点。你会如何做到这一点? – 2009-06-04 12:36:24