Hi,
I'm trying to migrate some old tests so that they don't make use of external dependencies. I was making good progress until I ran into a situation where a test throws the exception
TypeMock.TypeMockException:
*** Cannot use WhenCalled without a complementing behavior statement
There are a couple of odd things about this, including the stack trace:
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Boolean A_5, Object[] A_6)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
at Symantec.ProvisioningApi.Implementation.UnitTest.ProvisionOrganisationHandlerTest.ProvisionOrganisationWithRoamingTest() in C:piApplicationsusplat_Prov_API_DLPProvisioningApiImplementation.UnitTestProvisionOrganisationHandlerTest.cs:line 0
The exception is thrown when I reach the end of the test, not when a call to WhenCalled is made. The InnerException is null.
To try and figure this out, I've been moving back up the test, commenting out lines of code until I isolated it to the following line (commenting it out makes the exception go away, but it isn't thrown at this line):
Isolate.WhenCalled(() => fakeProvisioningCustomerApi.ProvisionWebUrlFilteringService(null));
I can actually step through all the lines that have been commented out, but the exception seems to be thrown when the method exits, so the mocking is working, but... I realise the following code won't make much sense to others, but I include it below. What could I be doing wrong?
Merry Christmas, :)
Tali
[TestMethod()]
[DeploymentItem("Symantec.ProvisioningApi.Implementation.dll")]
[DeploymentItem(@"ProvisioningApiServiceHostXmlDocumentsAxaptaId.xml", "XmlDocuments")]
[Isolated]
public void ProvisionOrganisationWithRoamingTest()
{
const int testNewCustomerId = 867867868;
const string testNewFinanceId = "XXX1234";
const int testCustomerTemplateId = 278678;
//const int testRoamingLicenceCount = 2;
const int testPartnerCustomerId = 1411;
Isolate.WhenCalled(() => UserDetailsExtension.Current).ReturnRecursiveFake();
Isolate.WhenCalled(() => UserDetailsExtension.Current.IsInRole(default(CustomerApi.RoleType), default(CustomerApi.ServiceTypes))).WillReturn(true);
CustomerApiMethods fakeCustomerApi = Isolate.Fake.Instance<CustomerApiMethods>(Members.ReturnRecursiveFakes);
ProvisioningCustomerApiMethods fakeProvisioningCustomerApi = Isolate.Fake.Instance<ProvisioningCustomerApiMethods>(Members.ReturnRecursiveFakes);
CrmExecuter fakeCrmExecutor = Isolate.Fake.Instance<CrmExecuter>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled((CustomerApi.ReadCustomerRequest r) => fakeCustomerApi.ReadCustomer(r))
.AndArgumentsMatch(r => r.CustomerId == testPartnerCustomerId)
.WillReturn(new ReadCustomerResponse()
{
Customer = new Customer()
{
IsPartner = true,
InternalReference = "PAR1999"
}
});
Isolate.WhenCalled((CustomerApi.ReadCustomerRequest r) => fakeCustomerApi.ReadCustomer(r))
.AndArgumentsMatch(r => r.CustomerId == testCustomerTemplateId)
.WillReturn(new ReadCustomerResponse()
{
Customer = new Customer()
{
IsPartner = false,
InternalReference = "XXX1111",
Services = CustomerApi.ServiceTypes.WebUrlFiltering
}
});
Isolate.WhenCalled(() => fakeProvisioningCustomerApi.CustomerValuesCheck(null))
.WillReturn(new ReadUniqueCustomerValuesCheckResponse()
{
CustomerUnique = UniquenessResults.Unique,
ExternalReferenceUnique = UniquenessResults.Unique
});
Isolate.WhenCalled(() => fakeProvisioningCustomerApi.ProvisionOrganisation(null))
.WillReturn(new ProvisionOrganizationResponse()
{
CustomerId = testNewCustomerId,
InternalReference = testNewFinanceId,
OptimisticLockValue = new byte[8]
});
Isolate.WhenCalled(() => fakeProvisioningCustomerApi.WritePrimaryLogin(null)).ReturnRecursiveFake();
Isolate.WhenCalled((CustomerApi.ReadCustomerRequest r) => fakeCustomerApi.ReadCustomer(r))
.AndArgumentsMatch(r => r.CustomerId == testNewCustomerId)
.WillReturn(new ReadCustomerResponse()
{
Customer = new Customer()
{
ParentId = testPartnerCustomerId,
Id = testNewCustomerId,
Services = CustomerApi.ServiceTypes.None
}
});
Isolate.WhenCalled((CustomerApi.ReadWebUrlFilteringServiceRequest r) => fakeCustomerApi.ReadWebUrlFilteringService(r))
.AndArgumentsMatch(r => r.CustomerId == testCustomerTemplateId)
.WillReturn(new ReadWebUrlFilteringServiceResponse()
{
WebUrlFilteringService = new CustomerApi.WebUrlFilteringService()
{
CustomerId = testPartnerCustomerId,
OptimisticLockValue = new byte[8],
WebFilteringAlert = new CustomerApi.WebScanningCustomAlert()
{
CustomText = "XXX",
DefaultText = "UYYY",
UseDefault = true
},
WebQuotasAlert = new CustomerApi.WebScanningCustomAlert()
{
CustomText = "WWW",
DefaultText = "VVV",
UseDefault = true
}
}
});
Isolate.WhenCalled(() => fakeCustomerApi.ReadWebUrlFilteringPolicySummary(null))
.WillReturn(new ReadWebUrlFilteringPolicySummaryResponse()
{