コード例 #1
0
        public void Test_Invoice_Saving()
        {
            Invoice invoice = new Invoice {
                Id    = Guid.NewGuid(),
                Lines = new List <InvoiceLine> {
                    new InvoiceLine {
                        Id          = Guid.NewGuid(),
                        Description = "Test Line",
                        Qty         = 5,
                        Rate        = 12
                    }
                },
            };

            var unitOfWork = new TestUnitOfWork();

            unitOfWork.Invoices.Add(invoice);
            unitOfWork.Commit();

            Invoice result = unitOfWork.Invoices.GetById(invoice.Id);

            Assert.NotNull(result);
        }
コード例 #2
0
        public void Test_Invoice_Paid()
        {
            Guid invoiceId = Guid.NewGuid();

            var unitOfWork          = new TestUnitOfWork();
            var mapperMock          = new Mock <IMapper>();
            var serviceProviderMock = new Mock <IServiceProvider>();
            var paymentServiceMock  = new Mock <PaymentService>(mapperMock.Object, serviceProviderMock.Object, unitOfWork);
            var invoiceServiceMock  = new Mock <InvoiceService>(mapperMock.Object, serviceProviderMock.Object, unitOfWork);

            serviceProviderMock.Setup(p => p.GetService(typeof(IInvoiceService)))
            .Returns(invoiceServiceMock.Object);

            Invoice invoice = new Invoice {
                Id    = invoiceId,
                Lines = new List <InvoiceLine> {
                    new InvoiceLine {
                        Qty  = 4,
                        Rate = 25m
                    }
                }
            };

            unitOfWork.Invoices.Add(invoice);
            unitOfWork.Commit();

            PaymentDto paymentDto = new PaymentDto {
                InvoiceId = invoiceId,
                Amount    = 100m,
            };

            paymentServiceMock.Object.ProcessNewPayment(paymentDto);

            Invoice updatedInvoice = unitOfWork.Invoices.GetById(invoiceId);

            Assert.Equal(0m, updatedInvoice.Balance);
        }
 void Commit(TestUnitOfWork uow)
 {
     uow.Commit();
     Console.WriteLine(" - committed - ");
     Console.WriteLine();
 }