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 (1,110 points)
edited Aug 5, 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.

 

Bar David | Support Team

answered Aug 4, 2015 by Bar (3,540 points)
Thank you Bar!
...