private async Task <Result <OrderItem> > CreateRegistrationOrderItem(ExternalRegistrationId externalRegistrationId,
                                                                      ExamId examId)
 {
     return(await _examPricingProvider.GetPriceAsync(examId)
            .OnSuccess(price => OrderItem.Create(Products.Registration.ItemName, Products.Registration.ProductType,
                                                 externalRegistrationId, 1, price)));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="OrderId">The order identifier.</param>
        /// <param name="orderItemDto">The order item dto.</param>
        /// <returns></returns>
        /// <exception cref="OrdersManager.Application.Exceptions.ServiceException">
        /// </exception>
        public virtual async Task <OrderDto> AddItem(Guid OrderId, OrderItemDto orderItemDto)
        {
            OrderDto orderDto = null;

            Order order = await orderRepository.FindOne(new OrderSpec(OrderId));

            if (order == null)
            {
                throw new ServiceException($"Order with Id {OrderId} does not exist.");
            }

            Item item = await itemRepository.FindById(orderItemDto.ItemId);

            if (item == null)
            {
                throw new ServiceException($"Item with Id {orderItemDto.ItemId} does not exist.");
            }

            try
            {
                order.AddItem(OrderItem.Create(order, item, orderItemDto.Quantity));
            }
            catch (DomainException exc)
            {
                throw new ServiceException(exc.Message);
            }

            orderDto = Mapper.Map <Order, OrderDto>(order);
            unitOfWork.Commit();
            return(orderDto);
        }
Ejemplo n.º 3
0
 private static void ParseShoppingCartItems(ICollection <ShoppingCartItem> items, Order order)
 {
     foreach (var item in items)
     {
         order.AddItem(OrderItem.Create(order, item.Product, item.Quantity));
     }
 }
Ejemplo n.º 4
0
        public async Task <ActionResult <int> > CreateAsync([FromBody] CreateOrderInput input)
        {
            var order = Order.Create(input.Address, input.Description, input.BuyerId);

            foreach (var item in input.Items)
            {
                order.Items.Add(OrderItem.Create(item.ProductName, item.UnitPrice, item.Quantity));
            }

            await _context.Orders.AddAsync(order);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetAsync), new { id = order.Id }, order));
        }
        public void RemoveItem_WithValidItemData_ReturnsUpdatedOrder()
        {
            //Arrange
            Mock <Item> MockedItem = new Mock <Item>();

            MockedItem.SetupGet(i => i.Id).Returns(ItemId);

            var _Order     = Order.Create(CustomerId);
            var _OrderItem = OrderItem.Create(_Order, MockedItem.Object, 2);

            _Order.AddItem(_OrderItem);

            //Act
            _Order.RemoveItem(ItemId);

            //Assert
            Assert.AreEqual(_Order.Items.Count, 0);
            Assert.AreEqual(0, _Order.Total);
        }
        public void AddItem_WithValidItemData_ReturnsConstructedOrder()
        {
            //Arrange
            var newOrder = Order.Create(CustomerId);

            Mock <Item> MockedItem = new Mock <Item>();

            MockedItem.SetupGet(i => i.Price).Returns(20);
            var newItem = OrderItem.Create(newOrder, MockedItem.Object, 3);

            //Act
            newOrder.AddItem(newItem);

            //Assert
            Assert.IsTrue(newOrder.Items[0].ItemId == MockedItem.Object.Id);
            var expectedTotal = 60;

            Assert.AreEqual(expectedTotal, newOrder.Total);
        }
        public void UpdateOrder_ChangeExistingItemQuantity_ReturnsUpdatedOrder()
        {
            //Arrange
            Mock <Item> MockedItem = new Mock <Item>();

            MockedItem.SetupGet(i => i.Id).Returns(ItemId);
            MockedItem.SetupGet(i => i.Price).Returns(20);

            var _Order     = Order.Create(CustomerId);
            var _OrderItem = OrderItem.Create(_Order, MockedItem.Object, 2);

            _Order.AddItem(_OrderItem);

            //Act
            _OrderItem.Quantity = 5;
            _Order.AddItem(_OrderItem);

            //Assert
            Assert.AreEqual(_Order.Items.Count, 1);
            Assert.IsTrue(_Order.Items[0].Quantity == 5);
            Assert.AreEqual(100, _Order.Total);
        }
 public static OrderItem CreateItem(Guid externalId, Currency currency)
 {
     return(OrderItem.Create("Item", "PRODUCT", externalId, 1, CreatePrice(100, 23, currency)).Value);
 }
Ejemplo n.º 9
0
        public void ShouldReturnExpectedResult(string name, Guid externalId, int quantity, Price price, bool expected, string because)
        {
            var itemResult = OrderItem.Create(name, "REGISTRATION", externalId, quantity, price);

            itemResult.IsSuccess.Should().Be(expected, because);
        }
Ejemplo n.º 10
0
 public static OrderItem CreateOrderItem(Order order, ShoppingCartItem shoppingCartItem)
 {
     return(OrderItem.Create(order, shoppingCartItem.Product, shoppingCartItem.Quantity));
 }