public void EnumerableOrderLineToListOrderLineDTOAdapter()
        {
            //Arrange
            Product product = new Software();
            product.Id = IdentityGenerator.NewSequentialGuid();
            product.Title = "The product title";
            product.Description = "The product description";

            OrderLine orderLine = new OrderLine()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Amount = 1,
                Discount = 0,
                UnitPrice = 10,
                ProductId = product.Id,
            };
            orderLine.SetProduct(product);

            IEnumerable<OrderLine> lines = new List<OrderLine>(){orderLine};

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderLinesDTO = adapter.Adapt<IEnumerable<OrderLine>, List<OrderLineDTO>>(lines);

            //Assert
            Assert.IsNotNull(orderLinesDTO);
            Assert.IsTrue(orderLinesDTO.Any());

            Assert.AreEqual(orderLinesDTO[0].Amount, orderLine.Amount);
            Assert.AreEqual(orderLinesDTO[0].Id, orderLine.Id);
            Assert.AreEqual(orderLinesDTO[0].Discount, orderLine.Discount);
            Assert.AreEqual(orderLinesDTO[0].ProductId, orderLine.ProductId);
            Assert.AreEqual(orderLinesDTO[0].ProductTitle, orderLine.Product.Title);
            Assert.AreEqual(orderLinesDTO[0].UnitPrice, orderLine.UnitPrice);
            Assert.AreEqual(orderLinesDTO[0].TotalLine, orderLine.TotalLine);
        }
        public void OrderLineToOrderLineDTOAdapter()
        {
            //Arrange
            Product product = new Software();
            product.Id = IdentityGenerator.NewSequentialGuid();
            product.Title = "The product title";
            product.Description = "The product description";

            OrderLine orderLine = new OrderLine()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Amount = 1,
                Discount = 0,
                UnitPrice = 10,
                ProductId = product.Id,
            };
            orderLine.SetProduct(product);

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderLineDTO = adapter.Adapt<OrderLine, OrderLineDTO>(orderLine);

            //Assert
            Assert.AreEqual(orderLineDTO.Amount, orderLine.Amount);
            Assert.AreEqual(orderLineDTO.Id, orderLine.Id);
            Assert.AreEqual(orderLineDTO.Discount, orderLine.Discount);
            Assert.AreEqual(orderLineDTO.ProductId, orderLine.ProductId);
            Assert.AreEqual(orderLineDTO.ProductTitle, orderLine.Product.Title);
            Assert.AreEqual(orderLineDTO.UnitPrice, orderLine.UnitPrice);
            Assert.AreEqual(orderLineDTO.TotalLine, orderLine.TotalLine);
        }
示例#3
0
        /// <summary>
        /// Create a new order line
        /// </summary>
        /// <param name="product">The associated product</param>
        /// <param name="amount">the number of items</param>
        /// <param name="discount">the selected discount for this line</param>
        /// <returns>The new order line</returns>
        public OrderLine CreateOrderLine(Product product, int amount, decimal unitPrice, decimal discount)
        {
            //check precondition
            if (amount <= 0
               ||
                product.IsTransient())
            {
                throw new ArgumentException(Messages.exception_InvalidDataForOrderLine);
            }

            //check discount values
            if (discount < 0)
                discount = 0;

            if (discount > 100)
                discount = 100;

            //create and return order line

            var line =  new OrderLine()
            {
                OrderId = this.Id,
                Amount = amount,
                Discount = discount,
                UnitPrice = unitPrice
            };

            line.SetProduct(product);

            return line;
        }