public void Setup() { var products = new[] { new Product {Number = "1", Name = "Product1"}, new Product {Number = "2", Name = "Product2"}, new Product {Number = "3", Name = "Product3"} }; var customers = new[] { new Customer {Number = "1", Name = "Cust1"}, new Customer {Number = "2", Name = "Cust2"}, new Customer {Number = "3", Name = "Cust3"} }; RepositoryMock = new Mock<IRepository>(); RepositoryMock.Setup(rep => rep.GetAllProducts()).Returns(products); RepositoryMock.Setup(rep => rep.GetAllCustomers()).Returns(customers); CacheMock = new Mock<ICache>(); var invoice = new Invoice(); invoice.AddLine(new InvoiceLine()); CacheMock.SetupGet(cache => cache["Invoice"]).Returns(invoice); CacheMock.SetupGet(cache => cache["Products"]).Returns(products); }
public ActionResult Submit(Invoice model) { //Didn't manged to implement standard validation for Lines //that's why employed explicit validation if (ModelState.IsValidField("CustomerId") && Invoice.Lines.Count() > 0) { try { ViewData["InvoiceId"] = Repository.Submit(Invoice); ClearCache(); return View("Submitted"); } catch (Exception exception) { ViewData.Model = new HandleErrorInfo(exception, "Invoice", "Submit"); return View("Exception"); } } InitializeCreate(model.CustomerId); return View("Create", Invoice); }
public ActionResult Create(Invoice model) { return RedirectToAction("Create", new {CustomerId = model.CustomerId}); }
public void SubmitCreatesCurrentInvoiceLines() { //Arrange var invoice = new Invoice(); invoice.AddLine(new InvoiceLine()); invoice.AddLine(new InvoiceLine()); invoice.AddLine(new InvoiceLine()); var sut = new Facade { Session = SessionMock.Object }; //Act sut.Submit(invoice); //Assert CurInvoiceLineUtilMock.Verify(currentInvoice => currentInvoice.Create(It.IsAny<ICurrentInvoice>()), Times.Exactly(3)); }
public void ProductsDoesNotContainAlreadyAddedToInvoice() { //Arrange var invoice = new Invoice(); invoice.AddLine(new InvoiceLine {ProductId = "3"}); invoice.AddLine(new InvoiceLine { ProductId = "4" }); CacheMock.SetupGet(cache => cache["Invoice"]).Returns(invoice); CacheMock.SetupGet(cache => cache["Products"]).Returns(new[] { new Product {Number = "2"}, new Product {Number = "3"} }); var sut = new InvoiceLineController { Cache = CacheMock.Object}; //Act var actual = sut.Products; //Assert Assert.AreEqual(1, actual.Count()); Assert.AreEqual("2", actual.First().Number); }
public string Submit(Invoice invoice) { var debtor = Session.Debtor.FindByNumber(invoice.CustomerId); var currentInvoice = Session.CurrentInvoice.Create(debtor); foreach (var invoiceLine in invoice.Lines) { var currentInvoiceLineData = Session.CurrentInvoiceLine.Create(currentInvoice); currentInvoiceLineData.Product = Session.Product.FindByNumber(invoiceLine.ProductId); currentInvoiceLineData.Quantity = invoiceLine.Quantity; } return currentInvoice.Book().Number.ToString(); }
public void RemoveProductFromLinesAndRedirectsToCreate() { //Arrange var invoice = new Invoice(); invoice.AddLine(new InvoiceLine { ProductId = "5" }); invoice.AddLine(new InvoiceLine{ProductId = "8"}); CacheMock.SetupGet(cache => cache["Invoice"]).Returns(invoice); var sut = new InvoiceController {Cache = CacheMock.Object}; //Act var actual = sut.RemoveProduct("5") as RedirectToRouteResult; //Assert Assert.IsNotNull(actual); Assert.AreEqual("Create", actual.RouteValues["action"]); Assert.AreEqual(1, invoice.Lines.Count()); Assert.AreEqual("8", invoice.Lines.First().ProductId); }