public void Handle(ClearBasketCommand cmd) { var basket = this.cBRepo.Get(cmd.CustomerId); basket.ClearBasket(); this.cBRepo.Save(basket); }
public async Task Clear_Basket_Should_Clear_All_Items_In_The_Basket() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Guid basketId = Faker.Random.Uuid(); Guid itemId = Faker.Random.Uuid(); const int quantity = 2; var addItemToBasketCommand = new AddItemToBasketCommand(basketId, itemId, quantity); var clearBasketCommand = new ClearBasketCommand(basketId); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- await Sut.Send(addItemToBasketCommand); await Sut.Send(clearBasketCommand); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- Basket basket = await Read(async context => { return(await context.Baskets.Include(x => x.Items).FirstOrDefaultAsync(x => x.Id == basketId)); }); basket.Should().NotBeNull(); basket.Items.Count.Should().Be(0); basket.Items.Should().NotContain(x => x.Id == itemId); }
public IActionResult Clear(int customerId) { var cmd = new ClearBasketCommand { CustomerId = customerId }; this.basketService.Submit(cmd); return(NoContent()); }
public void ShouldClearCustomerBasketGivenClearBasketMessage() { //arrange var msg = new ClearBasketCommand { CustomerId = expectedBasketDto.CustomerId }; var sut = new BasketManagementClient(this.clientBaseUri); //act var result = sut.ClearBasket(msg); //assert Assert.Equal(expectedBasketDto.CustomerId, result.CustomerId); Assert.Empty(result.Items); }
public BasketDto ClearBasket(ClearBasketCommand msg) { BasketDto basketDto = null; var uri = this.GenerateRequestUri($"{msg.CustomerId}"); var response = this.Put(uri, content: null); if (response.IsSuccessStatusCode) { basketDto = this.GetBasket(new GetBasketQuery { CustomerId = msg.CustomerId }); } return(basketDto); }
public void Clear_Basket_Should_Throw_AggregateNotFoundException_If_Basket_Does_Not_Exist() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Guid basketId = Faker.Random.Uuid(); var clearBasketCommand = new ClearBasketCommand(basketId); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Func <Task> act = () => Sut.Send(clearBasketCommand); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.Should().Throw <Exceptions.AggregateNotFoundException>().WithMessage(string.Format(Messages.AggregateNotFoundExceptionMessage, basketId)); }
public ClearBasketCommandHandlerTest() { basketRedisService = new Mock <IBasketRedisService>(); command = new ClearBasketCommand(userId); commandHandler = new ClearBasketCommandHandler(basketRedisService.Object); }