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.