It is interesting in Isolator how various mscorlib types differ in whether or not they throw when faked:
Isolate.Fake.Instance<System.IO.Stream>(); // Does not throw
Isolate.Fake.Instance<System.IO.TextReader>(); // Does not throw
Isolate.Fake.Instance<System.IO.TextWriter>(); // Does not throw
Isolate.Fake.Instance<System.IO.StreamReader>(); // Does not throw
Isolate.Fake.Instance<System.IO.StreamWriter>(); // Does not throw
Isolate.Fake.Instance<System.Text.RegularExpressions.Match>(); // Does not throw
Isolate.Fake.Instance<System.Threading.Thread>(); // Throws
Isolate.Fake.Instance<System.Text.StringBuilder>(); // Throws
Isolate.Fake.Instance<System.IO.FileInfo>(); // Throws
Isolate.Fake.Instance<System.IO.BinaryReader>(); // Throws
Isolate.Fake.Instance<System.IO.BinaryWriter>(); // Throws
For unlisted-yet-fakable type System.IO.StreamWriter, its behavior when faked is rather interesting in that the fake allows asserting that StreamWriter.Write() was called but disallows by way of NullReferenceException asserting that StreamWriter.WriteLine() was called:
Edit: Right click "Open image in new tab" in Chrome shows this screenshot in full size.
Code in screenshot as text:
[TestFixture, Isolated]
public class Tests
{
[Test]
public void TestFakabilityOfStreamWriterWrite()
{
var fakeStreamWriter = Isolate.Fake.Instance<StreamWriter>(Members.MustBeSpecified);
Isolate.WhenCalled(() => fakeStreamWriter.Write((string)null)).IgnoreCall();
//
fakeStreamWriter.Write("Value"); // Does not throw
//
Isolate.Verify.WasCalledWithExactArguments(() => fakeStreamWriter.Write("Value"));
Assert.AreEqual(1, Isolate.Verify.GetTimesCalled(() => fakeStreamWriter.Write((string)null)));
}
[Test]
public void TestFakabilityOfStreamWriterWriteLine()
{
var fakeStreamWriter = Isolate.Fake.Instance<StreamWriter>(Members.MustBeSpecified);
Isolate.WhenCalled(() => fakeStreamWriter.WriteLine((string)null)).IgnoreCall();
//
fakeStreamWriter.WriteLine("Value"); // Throws with NullReferenceException
//
Isolate.Verify.WasCalledWithExactArguments(() => fakeStreamWriter.WriteLine("Value"));
Assert.AreEqual(1, Isolate.Verify.GetTimesCalled(() => fakeStreamWriter.WriteLine((string)null)));
}
}