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
Hi,

I am attempting to fake an instance of class and ignore the constructor for said class. When i step into the code the first constructor below is called even though i have the constructwillbe.ignored set. Any ideas as to why, I don't think i am doing anything tricky here.

Heres the code i am using

ProductCatalog target = Isolate.Fake.Instance<ProductCatalog>(Members.CallOriginal, ConstructorWillBe.Ignored);

Product Catalog is a class that has 3 constructors as such below

public ProductCatalog(string siteName, string catalogName, ICredentials credential)
{
//code
}

public ProductCatalog(string siteName, string catalogName)
: this(siteName, catalogName, System.Net.CredentialCache.DefaultNetworkCredentials)
{ }

public ProductCatalog(string catalogName, IProductCatalogDao dao)
{
//code
}
asked by Locke12 (600 points)

4 Answers

0 votes
Hello,

You're right, this should work. Unfortunately I'm not able to reproduce this issue here, would it be possible for you to post the rest of ProductCatalog? Or perhaps make a small project with a reproduction?

Thank you.
answered by igal (5.7k points)
0 votes
Using v6.03

I am attempting to fake an instance of a Windows form like this:

var fakeForm = Isolate.Fake.Instance<Form>(Members.ReturnRecursiveFakes, ConstructorWillBe.Ignored, BaseConstructorWillBe.Ignored);

when I run the test, Isolator complains:

DataLibTests.ConnectionManagerTests.ParseConnectionStringStyleSettings:
TypeMock.TypeMockException :
*** Typemock cannot evaluate new instance constructors of mocked type.

The stack trace looks like this which clearly shows the Forms..ctor() is being called.

at e1.a()
at h1.a(String A_0, Mock A_1, gy A_2, Int32& A_3)
at h1.a(String A_0, Object A_1, Object A_2, Type& A_3, String A_4)
at System.Windows.Forms.Form..ctor()
at if.CreateFakeInstance[T](Members behavior, Constructor constructorFlag, Constructor baseConstructorFlag, Type baseType, Object[] ctorArgs)
at if.Instance[T](Members behavior, ConstructorWillBe constructorBehavior, BaseConstructorWillBe baseConstructorBehavior)
at DataLibTests.ConnectionManagerTests.ParseConnectionStringStyleSettings() in c:\dev7\Source\Tests\DataLibTests\ConnectionManagerTests.cs:line 41
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at DataLibTests.ConnectionManagerTests.ParseConnectionStringStyleSettings() in c:\dev7\Source\Tests\DataLibTests\ConnectionManagerTests.cs:line 38
answered by ksummerlin (4k points)
0 votes
Just for kicks I tested this using NUnit-x86 instead of the 64-bit NUnit. The test runs in the 32-bit NUnit but not in the 64-bit NUnit.

So this issue may be related to the 64-bit version of TypeMock only. Hope this helps.
answered by ksummerlin (4k points)
0 votes
Unfortunately I was not able to reproduce this issue. I've tried running it using x64 and x86 but the error hasn't occoured.

Let's take it offline - please send a test project to support AT typemock.com so I'll be able to continue investigating this issue.

On a side note - if you create a recursive fake object you do not need to specific that the c'tor will be ignored - it would be ignored by default.
In fact because recursive fake is the default mode when creating a fake instance you only need to following line:
var fakeForm = Isolate.Fake.Instance<Form>();
answered by dhelper (11.9k points)
...