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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 4
0
        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);
        }