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

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:DevelopmentMainXXXXXBusiness.Export.TestLoanApplicationDisclosuresCustomThreeDayDisclosureFieldsTest.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:DevelopmentMainXXXXXBusiness.ModelCorePartnerArmDisclosureProfile.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:DevelopmentMainXXXXXBusiness.Export.TestLoanApplicationDisclosuresCustomThreeDayDisclosureFieldsTest.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 by adam.gritt (1.1k 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 examplesmall project that reproduces this issue?

 

 

answered by alex (17k 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)
...