Esempio n. 1
0
        public override bool Equals(object obj)
        {
            OrderItemLine line = obj as OrderItemLine;

            if (line != null)
            {
                return(line.Id == this.Id);
            }
            return(base.Equals(obj));
        }
        public void AddingLineWithAlreadyExistingSkuWillSetItBackToEmpty()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine();
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            OrderItemLine newLine2 = new OrderItemLine(1, "1234-56789", null, null, 2, null, false);
            newLine2.Id = line2.Id;
            presenter.OnChangedOrderItemLine(newLine2);

            Assert.AreEqual(2, view.OrderItemsLines.Count);
            OrderItemLine updatedLine = view.OrderItemsLines[1];
            Assert.AreEqual(line2.Id, updatedLine.Id);
            Assert.IsTrue(String.IsNullOrEmpty(updatedLine.Sku));
            Assert.IsTrue(String.IsNullOrEmpty(updatedLine.Name));
            Assert.IsNull(updatedLine.Price);
            Assert.IsFalse(updatedLine.ProductId > 0);
        }
        public void ShouldUpdateProductPriceOnChangeOrderItemLine()
        {
            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            decimal fakePrice = 0.01m;
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "Fake product name", fakePrice, 10, 0m, false);
            view.OrderItemsLines.Add(line1);

            presenter.OnChangedOrderItemLine(line1);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(1.99m, view.OrderItemsLines[0].Price);
            Assert.AreEqual("#2 Pencil Pack", view.OrderItemsLines[0].Name);
        }
        public void ShouldUpdateOrderItemSkuOnProductSelected()
        {
            view.OrderItemsLines = new List<OrderItemLine>();
            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.EditingOrderItemLine = line1;

            presenter.OnProductSelected("1234-56789");

            Assert.IsTrue(view.SetEditingProductCalled);
            Assert.AreEqual("1234-56789", view.ShownSku);
            Assert.AreEqual("#2 Pencil Pack", view.ShownName);
            Assert.AreEqual(1.99m, view.ShownPrice);
        }
        public void ShouldUpdateItemTotalAndOrderTotalOnOrderItemLineChanged()
        {
            decimal? price = 1.99m;

            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            productService.AddProduct(new Product(2, "9876-54321", "Stencil Pad", 0.79m, null));

            //Total set to 0, so it can be updated by the presenter.
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", price, 10, 0m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            short newQty = 20;
            OrderItemLine lineUpdated = new OrderItemLine(1, line1.Sku, line1.Name, line1.Price, newQty, 0, false);
            lineUpdated.Id = line1.Id;

            presenter.OnChangedOrderItemLine(lineUpdated);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(newQty, view.OrderItemsLines[0].Quantity);
            Assert.AreEqual(price * newQty, view.OrderItemsLines[0].Total);
            Assert.AreEqual(line1.Total + line2.Total, view.OrderTotalPrice);
        }
        public void ShouldSubmitOrderItemsToControllerOnSave()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            presenter.OnSave();

            Assert.IsTrue(controller.SaveCurrentOrderAsDraftCalled);
            Assert.AreEqual(2, controller.CurrentOrder.Details.Count);
            Assert.AreEqual(1, controller.CurrentOrder.Details[0].ProductId);
            Assert.AreEqual(2, controller.CurrentOrder.Details[1].ProductId);
        }
        public void ShouldMaintainSelectedValueWhenEditingOrderLine()
        {
            view.OrderItemsLines = new List<OrderItemLine>();
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            bool selectedValue = true;
            int rowIndex = 1;

            presenter.OnEditOrderItemLine(rowIndex, selectedValue);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(selectedValue, view.OrderItemsLines[rowIndex].Selected);
        }
        public void ShouldIgnoreInvalidOrderItemsWhenPassingToControllerOnSave()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", null, 10, 7.9m, false); //Invalid, no UnitPrice
            OrderItemLine line3 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 0, 7.9m, false); //Invalid, quantity is zero
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.OrderItemsLines.Add(line3);

            presenter.OnSave();

            Assert.AreEqual(1, controller.CurrentOrder.Details.Count);
            Assert.AreEqual(1, controller.CurrentOrder.Details[0].ProductId);
        }
        public void ShouldDeleteCorrectOrderLinesOnDelete()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.90m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            OrderItemLine line3 = new OrderItemLine(3, "4356-43239", "#6 Pencil Pack", 1.99m, 10, 19.90m, false);
            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.OrderItemsLines.Add(line3);

            List<OrderItemLine> lines = new List<OrderItemLine>();
            lines.Add(line1);
            lines.Add(line3);

            presenter.OnDeleteOrderItemLines(lines);

            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(1, view.OrderItemsLines.Count);
            Assert.AreEqual(line2, view.OrderItemsLines[0]);
        }
        public void ShouldDeleteAndShowRemainingOrderItemLinesOnDelete()
        {
            List<OrderItemLine> lines = new List<OrderItemLine>();
            OrderItemLine orderItemLine = new OrderItemLine();
            view.OrderItemsLines.Add(orderItemLine);
            lines.Add(orderItemLine);

            presenter.OnDeleteOrderItemLines(lines);

            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(0, view.OrderItemsLines.Count);
        }
        public void RepeatedSkuIsNotValid()
        {
            string sku = "1234-56789";
            OrderItemLine line1 = new OrderItemLine(1, sku, "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            view.OrderItemsLines.Add(line1);

            string errorMessage = string.Empty;
            Assert.IsFalse(presenter.IsSkuValid(sku, out errorMessage));
            Assert.IsFalse(string.IsNullOrEmpty(errorMessage));
        }
        public void NotUsedSkuIsValid()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            view.OrderItemsLines.Add(line1);

            Product product = new Product(1, "9876-54321", "#2 Pencil Pack", 1.99m, "#2 Pencil Pack");
            productService.AddProduct(product);

            string errorMessage = string.Empty;
            Assert.IsTrue(presenter.IsSkuValid("9876-54321", out errorMessage));
            Assert.IsTrue(string.IsNullOrEmpty(errorMessage));
        }