chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes

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
 
According to https://www.typemock.com/mscorlib-types , Isolator supports faking these mscorlib types: DateTime, Environment, File, Directory, FileStream, and X509Certificate.
 
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)));
	}
}

 

 

asked by NeilJustice (14.1k points)
edited by NeilJustice

Please log in or register to answer this question.

...