예제 #1
0
 public GetBasketQueryHandlerTest()
 {
     basketRedisService = new Mock <IBasketRedisService>();
     query        = new GetBasketQuery(userId);
     queryHandler = new GetBasketQueryHandler(basketRedisService.Object);
     basketDto    = new UserBasketDto {
         Products = new List <BasketProduct> {
             new BasketProduct()
         }
     };
 }
예제 #2
0
        public void ShouldRetrieveExistingCustomerBasketGivenCustomerGetBasketMessage()
        {
            //arrange
            var msg = new GetBasketQuery {
                CustomerId = expectedBasketDto.CustomerId
            };
            var sut = new BasketManagementClient(this.clientBaseUri);

            //act
            var result = sut.GetBasket(msg);

            //assert
            Assert.Equal(expectedBasketDto.CustomerId, result.CustomerId);
        }
        public IActionResult GetBasketById(int customerId)
        {
            var qry = new GetBasketQuery {
                CustomerId = customerId
            };

            var basket = this.basketService.Query <GetBasketQuery, BasketDto>(qry);

            if (basket == null)
            {
                return(NotFound());
            }

            return(Ok(basket));
        }
        public BasketDto GetBasket(GetBasketQuery msg)
        {
            BasketDto basketDto = null;

            var uri = this.GenerateRequestUri($"{msg.CustomerId}");

            var response = this.Get(uri, content: null);

            if (response.IsSuccessStatusCode)
            {
                basketDto = response.Content.ReadAsAsync <BasketDto>().Result;
            }

            return(basketDto);
        }
        public async Task Handle_ReturnsBasketFromCache_ForGivenBasketId()
        {
            var basketId = Guid.NewGuid();

            var request = new GetBasketQuery
            {
                BasketId = basketId
            };

            var response = await _sut.Handle(request, default(CancellationToken));

            response.Should().NotBeNull();
            response.Should().NotBeEmpty();
            _mockBasket.Verify(x => x.GetAsync(basketId));
        }
        public async Task Handle_ReturnsEmptyBasket_IfBasketDoesNotExist()
        {
            _mockBasket.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync((ApprenticeshipFavouritesBasket)null);

            var basketId = Guid.NewGuid();

            var request = new GetBasketQuery
            {
                BasketId = basketId
            };

            var response = await _sut.Handle(request, default(CancellationToken));

            response.Should().NotBeNull();
            response.Should().BeEmpty();
            _mockBasket.Verify(x => x.GetAsync(basketId));
        }
예제 #7
0
        public async Task <IActionResult> GetBasketAsync()
        {
            var query = new GetBasketQuery
            {
                UserId = User.GetId()
            };

            var result = await _mediator.Send(query);

            if (result.Failure)
            {
                ModelState.AddModelError(string.Empty, result.Error);
                return(BadRequest(ModelState));
            }

            var viewModel = _mapper.Map <BasketDto, BasketViewModel>(result.Value);

            return(View("Basket", viewModel));
        }
예제 #8
0
        public async Task Handle_BasketExists_ReturnBasket(
            [Frozen] Mock <IBasketRepository> mockBasketRepository,
            GetBasketQueryHandler sut,
            GetBasketQuery query,
            CustomerBasket basket
            )
        {
            //Arrange
            mockBasketRepository.Setup(_ => _.GetBasketAsync(
                                           It.IsAny <string>()
                                           ))
            .ReturnsAsync(basket);

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().BeEquivalentTo(basket);
            mockBasketRepository.Verify(x => x.GetBasketAsync(
                                            It.IsAny <string>()
                                            ));
        }
        public void CountryShippingTest()
        {
            IGetBasketQuery          basketLoader       = new GetBasketQuery();
            IAddToBasketCommand      addToBasket        = new AddToBasketCommand();
            IGetShippingOptionsQuery getShippingOptions = new GetShippingOptions();

            Dictionary <string, ShippingBase> shippingOptions =
                getShippingOptions.Invoke(new GetShippingOptionsRequest()).ShippingOptions;


            var lineItemList = new List <LineItem>
            {
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.Europe,
                    ShippingAmount = 1m
                },
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.Europe,
                    ShippingAmount = 0.5m
                },
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.UK,
                    ShippingAmount = 0.5m
                },
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.UK,
                    ShippingAmount = 0.0m
                },
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.RestOfTheWorld,
                    ShippingAmount = 2m
                },
                new LineItem
                {
                    Amount         = 1.5m,
                    ProductId      = "1",
                    Shipping       = shippingOptions["CustomShipping"],
                    SupplierId     = 1,
                    DeliveryRegion = RegionShippingCost.Regions.RestOfTheWorld,
                    ShippingAmount = 1.5m
                }
            };

            foreach (LineItem item in lineItemList)
            {
                addToBasket.Invoke(new AddToBasketRequest {
                    LineItem = item
                });
            }

            Basket basket = basketLoader.Invoke(new BasketRequest());

            foreach (LineItem item in basket.LineItems)
            {
                LineItem sampleListItem = lineItemList.FirstOrDefault(a => a.Id == item.Id);

                Assert.AreEqual(sampleListItem.SupplierId, item.SupplierId, "SupplierId are not equal");
                Assert.AreEqual(sampleListItem.DeliveryRegion, item.DeliveryRegion, "Region are not equal");
                Assert.AreEqual(sampleListItem.ShippingAmount, item.ShippingAmount, "Amount are not equal");
            }
        }