Using TypeMock With CSLA Broken In New Versions

0 votes

We use CSLA (http://www.cslanet.com/) for our business objects.  We have been using Typemock 7.4.3.0 and it has been working fine.  However, I recently tried to upgrade to using 8.1.4.0 and have even tried 7.5.6.1 and neither works correctly with CSLA anymore for our unit tests.  With the newer versions I get the following error within most of the unit tests:

Test Name: FullCustomThreeDayDisclosureFieldTest
Test FullName: XXXXX.Business.Export.Test.LoanApplication.Disclosures.CustomThreeDayDisclosureFieldsTest.FullCustomThreeDayDisclosureFieldTest
Test Source: c:\Development\Main\XXXXX\Business.Export.Test\LoanApplication\Disclosures\CustomThreeDayDisclosureFieldsTest.cs : line 184
Test Outcome: Failed
Test Duration: 0:00:00.0618948
 
Result Message:
Test method XXXXX.Business.Export.Test.LoanApplication.Disclosures.CustomThreeDayDisclosureFieldsTest.FullCustomThreeDayDisclosureFieldTest threw exception: 
System.InvalidOperationException: Cannot register property SectionOneDescr, a PropertyInfo with the same name already exists.
Result StackTrace:
at Csla.Core.FieldManager.PropertyInfoManager.RegisterProperty[T](Type objectType, PropertyInfo`1 info).
   at Csla.ReadOnlyBase`1.RegisterProperty[P](PropertyInfo`1 info).
   at Csla.ReadOnlyBase`1.RegisterProperty[P](Expression`1 propertyLambdaExpression).
   at XXXXX.Business.Model.Core.PartnerArmDisclosureProfile..cctor() in c:\Development\Main\XXXXX\Business.Model\Core\PartnerArmDisclosureProfile.cs:line 11.
   at TypeMock.MockManager.getReturn(Object context, String typeName, String methodName, Object methodGenericParams, Boolean isDecorated, Boolean isInterceptedType, Object[] methodArguments)
   at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
   at XXXXX.Business.Export.Test.LoanApplication.Disclosures.CustomThreeDayDisclosureFieldsTest.FullCustomThreeDayDisclosureFieldTest() in c:\Development\Main\XXXXX\Business.Export.Test\LoanApplication\Disclosures\CustomThreeDayDisclosureFieldsTest.cs:line 0
 
Our business objects are setup as follows:
public class Fee : BusinessBase<AccountFee>
{
    private static readonly PropertyInfo<FeeCalculationType?> _CalculationTypeProperty = RegisterProperty<FeeCalculationType?>(p => p.CalculationType);

    public FeeCalculationType? CalculationType
    {
        get { return GetProperty(_CalculationTypeProperty); }
        set { SetProperty(_CalculationTypeProperty, value); }
    }
}

When RegisterProperty is called the property information is added to a singleton collection and an exception is thrown if a duplicate one is added for the same object type. 

The newer versions of TypeMock seem to be re-initializing the static readonly members of the classes.  Is there a way to disable this functionality so that it works like the older version or is there a certain way that our tests need to be written to work properly with the new versions?  We do have code that uses a Mock data layer and doesn't use TypeMock and those tests work fine unless the TypeMock tests are executed first in which case then they break usually due to the PropertyInfo values being null.

 

asked Sep 3, 2015 by adam.gritt (170 points)

1 Answer

0 votes

Hi Adam,

We've made som work in this area since 7.4.

In version 8.1 we added a new tool called Insight, you can use it to see what is goning on with in your tests (static props for instance). Please run it and see if it helps you.

You can send the Insight report if you need help with it or send us a test example\small project that reproduces this issue?

 

 

 

Alex Galin | Support Team

answered Sep 6, 2015 by alex (17,890 points)
How do I get Insight to display?

To use Insight Simply

1. Open the Insight Window (Typemock->Windows->Insight)

2. Turn it on (button on the left)

See documentation

 

About your error - the static constructor is called if it was faked in the past. 
Please export the log and send it to us support [at] typemock.com

 

I emailed a code sample where I was able to reproduce the issue to Support [at] typemock.com.  Many of our unit tests are setup the same way and unless we can resolve it without rewriting all of our tests, we will be stuck on the old version of TypeMock (which is not ideal).
Solved. the fix will be available in all future releases (from 8.3 and on)

 

Alex Galin | Support Team

...