public async Task Handle_BasketHasProductWithOldPrice_UpdateUnitPrice( [Frozen] Mock <IBasketRepository> mockBasketRepository, ProductPriceChangedIntegrationEventHandler sut, ProductPriceChangedIntegrationEvent productPriceChangedEvent, string user1, string user2 ) { //Arrange mockBasketRepository.Setup(_ => _.GetUsers()) .Returns(new string[] { user1, user2 }); var basket_user1 = new CustomerBasket { Items = new List <BasketItem> { new BasketItem { ProductNumber = productPriceChangedEvent.ProductNumber, UnitPrice = productPriceChangedEvent.OldPrice } } }; var basket_user2 = new CustomerBasket { Items = new List <BasketItem> { new BasketItem { ProductNumber = productPriceChangedEvent.ProductNumber, UnitPrice = productPriceChangedEvent.OldPrice } } }; mockBasketRepository.Setup(_ => _.GetBasketAsync(It.Is <string>(_ => _ == user1))) .ReturnsAsync(basket_user1); mockBasketRepository.Setup(_ => _.GetBasketAsync(It.Is <string>(_ => _ == user2))) .ReturnsAsync(basket_user2); //Act await sut.Handle(productPriceChangedEvent); //Assert mockBasketRepository.Verify(_ => _.UpdateBasketAsync( It.Is <CustomerBasket>(_ => _ == basket_user1) )); mockBasketRepository.Verify(_ => _.UpdateBasketAsync( It.Is <CustomerBasket>(_ => _ == basket_user2) )); basket_user1.Items[0].UnitPrice.Should().Be(productPriceChangedEvent.NewPrice); basket_user1.Items[0].OldUnitPrice.Should().Be(productPriceChangedEvent.OldPrice); basket_user2.Items[0].UnitPrice.Should().Be(productPriceChangedEvent.NewPrice); basket_user2.Items[0].OldUnitPrice.Should().Be(productPriceChangedEvent.OldPrice); }
public async Task Handle_BasketDoesNotHaveProduct_BasketNotUpdated( [Frozen] Mock <IBasketRepository> mockBasketRepository, ProductPriceChangedIntegrationEventHandler sut, ProductPriceChangedIntegrationEvent productPriceChangedEvent, string user1, CustomerBasket basket ) { //Arrange mockBasketRepository.Setup(_ => _.GetUsers()) .Returns(new string[] { user1 }); mockBasketRepository.Setup(_ => _.GetBasketAsync(It.Is <string>(_ => _ == user1))) .ReturnsAsync(basket); //Act await sut.Handle(productPriceChangedEvent); //Assert mockBasketRepository.Verify(_ => _.UpdateBasketAsync( It.IsAny <CustomerBasket>() ), Times.Never ); }