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);
        }
Example #2
0
      /// <summary>
      ///    Create and add a new order line
      /// </summary>
      /// <param name="productId">the product identifier</param>
      /// <param name="amount">the number of items</param>
      /// <param name="unitPrice">the unit price of each item</param>
      /// <param name="discount">applied discount</param>
      /// <returns>added new order line</returns>
      public OrderLine AddNewOrderLine(Guid productId, int amount, decimal unitPrice, decimal discount)
      {
         //check precondition
         if (amount <= 0 || productId == Guid.Empty) {
            throw new ArgumentException(Messages.exception_InvalidDataForOrderLine);
         }

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

         if (discount > 100) { discount = 100; }

         //create new order line
         var newOrderLine = new OrderLine()
         {
            OrderId = this.Id,
            ProductId = productId,
            Amount = amount,
            Discount = discount,
            UnitPrice = unitPrice
         };
         //set identity
         newOrderLine.GenerateNewIdentity();

         //add order line
         this.OrderLines.Add(newOrderLine);

         //return added orderline
         return newOrderLine;
      }
Example #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;
        }
        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);
        }
Example #5
0
        /// <summary>
        /// Add new order-line (Order Details) into this order
        /// </summary>
        /// <param name="line">The new order-line to add</param>
        public void AddOrderLine(OrderLine line)
        {
            if (line == null)
                throw new ArgumentNullException("line");

            //Fix relation
            line.OrderId = this.Id;

            this.OrderLines.Add(line);
        }