コード例 #1
0
        public OutputDtoQueryOrder GetById(int orderId)
        {
            var orderFromDb  = _orderRepository.GetById(orderId);
            var orderedItems = _orderedItemRepository.GetByOrderId(orderFromDb.Id);
            var userOrder    = new UserOrder();

            userOrder.AddOrderedItems(orderedItems);

            return(new OutputDtoQueryOrder
            {
                Id = orderFromDb.Id,
                IsPaid = orderFromDb.IsPaid,
                OrderedAt = orderFromDb.OrderedAt,
                TotalPrice = userOrder.ComputeOrderPrice(),
                Ordered = new OutputDtoQueryOrder.User
                {
                    Id = orderFromDb.Orderer.Id,
                    Firstname = orderFromDb.Orderer.Firstname,
                    Lastname = orderFromDb.Orderer.Lastname,
                    Email = orderFromDb.Orderer.Email,
                },
                OrderedItems = userOrder.OrderedItems.Select(orderedItem => new OutputDtoQueryOrder.Item
                {
                    Id = orderedItem.Id,
                    ItemId = orderedItem.ItemOrdered.Id,
                    Label = orderedItem.ItemOrdered.Label,
                    Price = orderedItem.ItemOrdered.Price,
                    ImageItem = orderedItem.ItemOrdered.ImageItem,
                    DescriptionItem = orderedItem.ItemOrdered.DescriptionItem,
                    Quantity = orderedItem.Quantity,
                    Size = orderedItem.Size
                })
            });
        }
コード例 #2
0
        public void Add_DuplicateItems_ContinueWithoutAdding()
        {
            // arrange
            var userOrder = new UserOrder();
            var orderedItemsWithDuplicate = new[] { CreateOrderedItem(1), CreateOrderedItem(1) };

            // act
            userOrder.AddOrderedItems(orderedItemsWithDuplicate);

            // assert
            Assert.AreEqual(1, userOrder.OrderedItems.Count);
        }
コード例 #3
0
        public void Add_OrderedItems_AreContained()
        {
            // arrange
            var userOrder    = new UserOrder();
            var orderedItems = CreateListOfOrdrItems();

            // act
            userOrder.AddOrderedItems(orderedItems);

            // assert
            Assert.AreEqual(orderedItems, userOrder.OrderedItems);
        }
コード例 #4
0
        public void Add_OrderedItems_ComputeTotalPrice(float[] prices, int[] quantities, float expected)
        {
            // arrange
            var userOrder    = new UserOrder();
            var orderedItems =
                prices.Select((price, i) => CreateOrderedItem(i, price, quantities[i]));

            userOrder.AddOrderedItems(orderedItems);

            // act
            var totalPrice = userOrder.ComputeOrderPrice();

            // assert
            Assert.IsTrue(Math.Round(expected, 2).Equals(Math.Round(totalPrice, 2)));
        }