public static IInvoice InvoiceForInserting(IAddress billTo, decimal total) { var status = new InvoiceStatus() { Key = Constants.DefaultKeys.InvoiceStatus.Unpaid, Active = true, Alias = "unpaid", Name = "Unpaid", SortOrder = 0 }; var invoice = new Invoice(status); invoice.SetBillingAddress(billTo); invoice.Total = total; return invoice; }
/// <summary> /// Create a fake product with fake data for testing /// </summary> /// <param name="id"></param> /// <returns></returns> private Invoice CreateFakeInvoice(int id, Guid key) { var customer = new AnonymousCustomer(100.00m, 100.00m, DateTime.Now) { FirstName = "John", LastName = "Jones", Email = "*****@*****.**", MemberId = 1004, Key = key, Id = 1001 }; var address = new CustomerAddress(customer, "Address") { Address1 = "123 Test St.", Address2 = "Apt 1", Locality = "USA", Region = "USA", PostalCode = "97333-0123", CountryCode = "US", Phone = "555-555-5555", Company = "Test Company" }; var invoiceStatus = new InvoiceStatus() { Alias = "unpaid", Name = "Unpaid", Active = true, Reportable = true, SortOrder = 1 }; return new Invoice(customer, address, invoiceStatus, 100.00m) { Id = id }; }
public void NewInvoiceReturnsCorrectInvoice() { //// Arrange Guid key = Guid.NewGuid(); bool wasCalled = false; int id = 1; Invoice invoice = CreateFakeInvoice(id, key); var customer = new AnonymousCustomer(100.00m, 100.00m, DateTime.Now); customer.FirstName = "John"; customer.LastName = "Jones"; customer.Email = "*****@*****.**"; customer.MemberId = 1004; var address = new CustomerAddress(customer, "Address") { Address1 = "123 Test St.", Address2 = "Apt 1", Locality = "USA", Region = "USA", PostalCode = "97333-0123", CountryCode = "US", Phone = "555-555-5555", Company = "Test Company" }; var invoiceStatus = new InvoiceStatus() { Alias = "unpaid", Name = "Unpaid", Active = true, Reportable = true, SortOrder = 1 }; var MockInvoiceService = new Mock<IInvoiceService>(); MockInvoiceService.Setup(cs => cs.CreateInvoice(customer, address, invoiceStatus, "Test Invoice 1")).Returns(invoice).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); //// Act Invoice result = null; //Invoice result = ctrl.NewInvoice(customer, address, invoiceStatus, "Test Invoice 1"); //// Assert Assert.AreEqual(invoice, result); Assert.True(wasCalled); }