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