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
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 by NeilJustice (14.1k points)
edited 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 by Bar (3.3k points)
Thank you Bar!
...