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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Unexpected non-assertability of methods called in constructor called via Isolate.Fake.Instance<T>(Members.CallOriginal)

0 votes

In the scenario pictured below, a CallOriginal()'d static method is called from a constructor invoked via Isolate.Fake.Instance<AbstractClass>(Members.CallOriginal).

As you can see from console output "StaticClass.StaticMethod() called", StaticClass.StaticMethod() is called, but Isolator appears to not record in its internal call history data structure that this call took place, leading to test failure upon asserting that StaticClass.StaticMethod() was called:

Is this behavior intended? I was hoping to be able to test an abstract class's constructor without resorting to a hackish testing-only subclass which would have a directly invokable constructor - with directly invoked constructors not exhibiting this unexpected behavior:

First screenshot as text:

using System;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;

public static class StaticClass
{
	public static void StaticMethod()
	{
		Console.WriteLine("StaticClass.StaticMethod() called");
	}
}

public abstract class AbstractClass
{
	public AbstractClass()
	{
		StaticClass.StaticMethod();
	}
}

[TestFixture, Isolated]
public class Tests
{
	[Test]
	public void Test()
	{
		Isolate.WhenCalled(() => StaticClass.StaticMethod()).CallOriginal();
		//
		Isolate.Fake.Instance<AbstractClass>(Members.CallOriginal);
		//
		Isolate.Verify.WasCalledWithExactArguments(() => StaticClass.StaticMethod());
	}
}

 

asked Aug 3, 2015 by NeilJustice (81,570 points)
edited Aug 4, 2015 by NeilJustice

1 Answer

0 votes
Hi Neil,

Thank you for the update.

We fixed it and will be included in the next release.
answered Aug 4, 2015 by Bar (3,560 points)
Thank you Bar!
...