Hi
I get the following exception when running a unit test using Natural TypeMocks:
TestCase 'Sanlam.SanQuote.Business.Domain.UnitTest.FinaliseApplicationTransitionFixture.TestValidFinaliseApplicationTransition'
failed: System.Reflection.AmbiguousMatchException : Ambiguous match found.
at System.DefaultBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] canidates, Object[]& args, ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, Object& state)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.a(Type A_0, Constructor A_1, Object[] A_2)
at TypeMock.MockManager.b(Type A_0)
at TypeMock.RecorderManager.a(MethodInfo A_0, String A_1, Object A_2, Object[] A_3, MethodBase A_4, Boolean A_5, Type A_6)
at TypeMock.RecorderManager.a(String A_0, String A_1, Object A_2, Object[] A_3, MethodBase A_4, Object A_5)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Object[] A_4)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Object p1, Object p2)
C:ProjectsPhoenix 3.0CodeSanlam.SanQuote.Business.DomainAgreementServicesDocumentGeneratorService.cs(29,0): at Sanlam.SanQuote.Business.Domain.Agreement.DocumentGeneratorService.GenerateDocumentInAgreement(Agreement agreement, DocumentType documentType)
C:ProjectsPhoenix 3.0CodeSanlam.SanQuote.Business.Domain.UnitTestAgreementStateTransitionsFinaliseApplicationTransitionFixture.cs(73,0): at Sanlam.SanQuote.Business.Domain.UnitTest.FinaliseApplicationTransitionFixture.TestValidFinaliseApplicationTransition()
Here is the actual unit test:
[Test]
public void TestValidFinaliseApplicationTransition()
{
MockManager.Init();
using (Session session = DataLayerRegistry.Instance.DomainModel.CreateSession())
{
Domain.Agreement.Agreement agreement = CreateInProgressApplication(session);
AgreementStateTransition stateTransition =
AgreementStateTransitionFactory.Create(agreement, AgreementTransition.FinaliseApplication);
ValidationContext context = new ValidationContext();
context.Action = (long)Actions.Finalise;
IList<DocumentType> documentTypes = new DocumentType[] { DocumentType.Application , DocumentType.Declaration,
DocumentType.DebitOrder, DocumentType.DepositSlip };
// Mock external calls to other service classes that happens on the transition and verify
// that they were executed with the right arguments
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(agreement.GetAllowedDocumentTypes(), documentTypes);
DocumentGeneratorService.GenerateDocumentAndPdfAttachmentInAgreement(agreement, DocumentType.Application);
DocumentGeneratorService.GenerateDocumentInAgreement(agreement, DocumentType.Declaration);
DocumentGeneratorService.GenerateDocumentInAgreement(agreement, DocumentType.DebitOrder);
DocumentGeneratorService.GenerateDocumentInAgreement(agreement, DocumentType.DepositSlip);
UpdateMasterPartyService.UpdateMasterParty(context, agreement);
recorder.CheckArguments();
}
RuleResult result = stateTransition.Execute(context);
// Ensure no validation errors
Assert.IsTrue(result.HasNoErrors, "No error should occur on a valid finalise transition");
}
MockManager.Verify();
}
The exception occurs as soon as the 2nd call is made to the DocumentGeneratorService. Here is the code for the DocumentGeneratorService:
public static class DocumentGeneratorService
{
public static void GenerateDocumentAndPdfAttachmentInAgreement(Agreement agreement, DocumentType documentType)
{
ValidationHelper.ValidateParameterIsCompleted(agreement, "agreement");
ValidationHelper.ValidateParameterIsCompleted(documentType, "documentType");
Document document = GenerateDocumentInAgreement(agreement, documentType);
if (document.Content != null)
{
Attachment attachment = GenerateAttachmentInAgreement(agreement, documentType.PdfAttachmentType);
AttachmentPage page = attachment.CreateAttachmentPage();
page.Content = PdfConverter.ConvertToPdf(document.Content);
attachment.AddAttachmentPage(page);
}
}
public static Document GenerateDocumentInAgreement(Agreement agreement, DocumentType documentType)
{
Document document = agreement.FindDocument(documentType);
if (document != null)
{
agreement.RemoveDocument(document);
}
document = agreement.CreateDocument(documentType);
agreement.AddDocument(document);
return document;
}
public static Attachment GenerateAttachmentInAgreement(Agreement agreement, AttachmentType attachmentType)
{
Attachment attachment = agreement.FindAttachment(attachmentType);
if (atta