Sample code for unit testing Automockfixture

 [TestClass]
   public class OutputServiceTest : AutoMockFixture<OutputService>
   {
       [TestMethod]
       public void Handle_ArrearPaymentEvent()
       {
           var policy = new PolicyBuilder().Build();
           var payment = new PaymentBuilder().Build();
           var defaultWorkflow = new DefaultWorkflowBuilder().Build();
           var eventData = new ArrearPaymentEvent(policy, defaultWorkflow, payment);
           DocumentWorkflowArrears arrearWorkflow = new DocumentWorkflowArrears();
 
           Container.GetMock<IOutputTransformerService>()
               .Setup(
                   s => s.TransformDocumentWorkflowArrears(
                       It.IsAny<PolicyDetail>(),
                       It.IsAny<string>(),
                       It.IsAny<Payment>()))
               .Returns(arrearWorkflow);
 
           Sut.Handle(eventData);
 
           Container.GetMock<IOutputTransformerService>()
               .Verify(
                   s => s.TransformDocumentWorkflowArrears(
                       policy,
                       defaultWorkflow.DefaultedInstalmentReference,
                       payment
                       ),
                   Times.Once());
 
           Container.GetMock<IEntityManager>()
               .Verify(s => s.Add(arrearWorkflow), Times.Once());
       }
 
       [TestMethod]
       public void AddComplaintEvent()
       {
           var policy = new PolicyBuilder().Build();
           var compliant = new PolicyComplaintBuilder().Build();
           var eventData = new AddComplaintEvent(policy, compliant);
           var compliantWorkflow = new DocumentWorkflowComplaints();
 
           Container.GetMock<IOutputTransformerService>()
               .Setup(
                   s => s.TransformDocumentWorkflowComplaint(
                       It.IsAny<PolicyDetail>(),
                       It.IsAny<PolicyComplaint>()))
               .Returns(compliantWorkflow);
 
           Sut.Handle(eventData);
 
           Container.GetMock<IOutputTransformerService>()
               .Verify(
                   s => s.TransformDocumentWorkflowComplaint(
                       policy,
                       compliant),
                   Times.Once());
 
           Container.GetMock<IEntityManager>()
               .Verify(s => s.Add(compliantWorkflow), Times.Once());
       }
   }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s