A.Fake <Stream> (). Read (...) throwing InvalidOperationException

Using NUnit 2.6.4 and FakeItEasy 1.25.2 in unit test C # code in Visual Studio 2013 Community Edition

The following test fragment runs as expected.

[Test] public void test_whatIsUpWithStreamRead() { Stream fakeStream = A.Fake<Stream>(); byte[] buffer = new byte[16]; int numBytesRead = fakeStream.Read(buffer, 0, 16); Assert.AreEqual(0, numBytesRead); } 

however, as soon as I decorate my fake using the CallTo / Returns () or ReturnsLazily () operator ...

 [Test] public void test_whatIsUpWithStreamRead() { Stream fakeStream = A.Fake<Stream>(); A.CallTo(() => fakeStream.Read(A<byte[]>.Ignored, A<int>.Ignored, A<int>.Ignored)).Returns(1); byte[] buffer = new byte[16]; int numBytesRead = fakeStream.Read(buffer, 0, 16); Assert.AreEqual(1, numBytesRead); } 

fakeStream.Read() throws a System.InvalidOperationException message with the message:

"The number of setpoints for the out and ref parameters does not match the number of out and ref parameters in the call."

from FakeItEasy.Configuration.BuildableCallRule.ApplyOutAndRefParametersValueProducer(IInterceptedFakeObjectCall fakeObjectCall) , which seems pretty strange to me since Stream.Read() has no out / ref parameters.

Is this a bug I have to report at https://github.com/FakeItEasy , or am I missing something?

THX

+6
source share
1 answer

Update : The error has been fixed in FakeItEasy 1.25.3 and FakeItEasy 2.0.0 .


Yes, this is a bug that seems to have been introduced in 1.23.0. I created a question 508 . I will be working on the fix in the near future and will discuss with other project owners in which release we want to release the fix. Continue if you have an opinion.

In the meantime, one of the possible ways to solve the problem is to return to FakeItEasy 1.22.0 if you do not need any improvements and bug fixes that were added in subsequent releases.

If this is not an option, perhaps consider abstraction Stream.Read and fake abstraction. Or come back and I will be happy to discuss other ways.

+2
source

All Articles