使用FluentAssertion 3.1.229,您如何比较两个不同MemoryStream
的内容?
写actualStream.Should().Be(expectedStream);
会产生以下错误:
System.IO.MemoryStream
{
CanRead = True
CanSeek = True
CanTimeout = False
CanWrite = True
Capacity = 8
Length = 8
Position = 0
ReadTimeout = "[Property 'ReadTimeout' threw an exception: 'Exception has been thrown by the target of an invocation.']"
WriteTimeout = "[Property 'WriteTimeout' threw an exception: 'Exception has been thrown by the target of an invocation.']"
}, but found
System.IO.MemoryStream
{
CanRead = True
CanSeek = True
CanTimeout = False
CanWrite = True
Capacity = 8
Length = 8
Position = 0
ReadTimeout = "[Property 'ReadTimeout' threw an exception: 'Exception has been thrown by the target of an invocation.']"
WriteTimeout = "[Property 'WriteTimeout' threw an exception: 'Exception has been thrown by the target of an invocation.']"
}.
是的,我可以使用NUnit Assert.That(actualStream, Is.EqualTo(expectedStream));
但是可以使用FluentAssertions吗?
感谢。
答案 0 :(得分:2)
也许这对你有用吗?
actualStream.ToArray().Should().Be(expectedStream.ToArray());
答案 1 :(得分:0)
您的NUnit解决方案也不起作用,因为MemoryStream
的{{1}}实现不会进行逐字节比较。相反,使用
Equals
。
actualStream.GetBuffer().ShouldBeEquivalentTo(expectedStream.GetBuffer())
返回对内部字节数组的引用,并在其上调用GetBuffer
将导致集合断言进行逐字节比较。