Example #1
0
        public void CreateAsync_CallsService_WhenValidState()
        {
            var viewModel = CreateModifyOrderDetailsViewModel();

            _orderDetailsController.CreateAsync(viewModel);

            A.CallTo(() => _orderDetailsService.CreateAsync(A <OrderDetailsDto> ._)).MustHaveHappenedOnceExactly();
        }
        public PizzaOrderMutation(IPizzaDetailsService pizzaDetailsService, IOrderDetailsService orderDetailsService)
        {
            Name = nameof(PizzaOrderMutation);

            FieldAsync <OrderDetailsType>(
                name: "createOrder",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OrderDetailsInputType> > {
                Name = "orderDetails"
            }),
                resolve: async context =>
            {
                var order = context.GetArgument <OrderDetailsModel>("orderDetails");

                var orderDetails = new OrderDetails(order.AddressLine1, order.AddressLine2, order.MobileNo, order.Amount);
                orderDetails     = await orderDetailsService.CreateAsync(orderDetails);

                var pizzaDetails = order.PizzaDetails.Select(x => new PizzaDetails(x.Name, x.Toppings, x.Price, x.Size, orderDetails.Id));
                pizzaDetails     = await pizzaDetailsService.CreateBulkAsync(pizzaDetails, orderDetails.Id);

                orderDetails.PizzaDetails = pizzaDetails.ToList();
                return(orderDetails);
            });

            FieldAsync <OrderDetailsType>(
                name: "updateStatus",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <OrderStatusEnumType> > {
                Name = "status"
            }),
                resolve: async context =>
            {
                int orderId             = context.GetArgument <int>("id");
                OrderStatus orderStatus = context.GetArgument <OrderStatus>("status");

                return(await orderDetailsService.UpdateStatusAsync(orderId, orderStatus));
            });


            FieldAsync <OrderDetailsType>(
                name: "deletePizzaDetails",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "pizzaDetailsId"
            }),
                resolve: async context =>
            {
                int pizzaDetailsId = context.GetArgument <int>("pizzaDetailsId");

                int orderId = await pizzaDetailsService.DeletePizzaDetailsAsync(pizzaDetailsId);

                return(await orderDetailsService.GetOrderDetailsAsync(orderId));
            });
        }
Example #3
0
        public void AddAsync_CreatesNewDetails_WhenNotExists()
        {
            var testGameDto = new GameDto();

            A.CallTo(() => _gameService.GetByKeyAsync(A <string> ._, Culture)).Returns(testGameDto);
            A.CallTo(() => _orderDetailsService.FindSingleAsync(A <Expression <Func <OrderDetails, bool> > > ._))
            .Returns((OrderDetails)null);

            _basketService.AddAsync(GameKey, CustomerId);

            A.CallTo(() => _orderDetailsService.CreateAsync(A <OrderDetailsDto> ._)).MustHaveHappenedOnceExactly();
        }
Example #4
0
        private async Task CreateDetailsAsync(string gameKey, string orderId)
        {
            var gameDto = await _gameService.GetByKeyAsync(gameKey);

            var detailsDto = new OrderDetailsDto
            {
                GameId   = gameDto.Id,
                Price    = gameDto.Price,
                Discount = gameDto.Discount,
                OrderId  = orderId
            };
            await _orderDetailsService.CreateAsync(detailsDto);
        }
Example #5
0
        public async Task <IActionResult> CreateAsync(ModifyOrderDetailsViewModel modifyOrderDetailsViewModel)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = await _modifyOrderDetailsViewModelFactory.CreateAsync(modifyOrderDetailsViewModel);

                return(View("Create", viewModel));
            }

            var orderDetailsDto = _mapper.Map <OrderDetailsDto>(modifyOrderDetailsViewModel);
            await _orderDetailsService.CreateAsync(orderDetailsDto);

            return(RedirectToAction("ListAsync", "Order"));
        }
        public async Task CreateAsync_ThrowsException_WhenNullDto()
        {
            Func <Task> action = async() => await _orderDetailsService.CreateAsync(null);

            await action.Should().ThrowAsync <InvalidServiceOperationException>();
        }
Example #7
0
        public async Task <OrderDetailsDto> Post(OrderDetailsDto orderDetails)
        {
            await _orderDetailsService.CreateAsync(orderDetails);

            return(orderDetails);
        }