public void CreateOrder_Command_Should_Run_Correctly_If_Product_DoesNot_Have_Campaign() { _productRepositoryMock.Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >())) .ReturnsAsync(FakeObjects.GenerateProduct()); _productRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <ProductEntity>())) .Returns(Task.CompletedTask); _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >())) .ReturnsAsync(new List <CampaignEntity>()); _campaignRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <CampaignEntity>())) .Returns(Task.CompletedTask); _orderRepositoryMock.Setup(x => x.AddAsync(It.IsAny <OrderEntity>())). ReturnsAsync(FakeObjects.GenerateOrder()); var result = _handler.Handle(_createOrderFaker.Generate(), CancellationToken.None).Result; _productRepositoryMock.Verify(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once); _productRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <ProductEntity>()), Times.Once); _campaignRepositoryMock.Verify(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <CampaignEntity>()), Times.Never); _orderRepositoryMock.Verify(x => x.AddAsync(It.IsAny <OrderEntity>()), Times.Once); result.Should().NotBeNull(); }
public void CreateProduct_Command_Should_Return_Repository_Product() { var product = FakeObjects.GenerateProduct(); _productRepositoryMock.Setup(x => x.AddAsync(It.IsAny <ProductEntity>())) .ReturnsAsync(product); var response = _handler.Handle(_createProductFaker.Generate(), CancellationToken.None); response.Result.Product.Should().Be(product); }
public void GetProductInfo_Should_Run_Correctly_If_Dont_Have_Campaign() { _productRepositoryMock.Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >())). ReturnsAsync(FakeObjects.GenerateProduct()); _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >())) .ReturnsAsync(new List <CampaignEntity>()); var result = _handler.Handle(_getProductInfoFaker.Generate(), CancellationToken.None).Result; _productRepositoryMock.Verify(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once()); _productPriceServiceMock.Verify(x => x.CalculateDiscountedPrice(It.IsAny <CampaignEntity>(), It.IsAny <decimal>(), It.IsAny <int>()), Times.Once); result.Should().NotBeNull(); }
public void CreateProduct_Command_Should_Run_Correctly() { var product = FakeObjects.GenerateProduct(); _productRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >())) .ReturnsAsync(false); _productRepositoryMock.Setup(x => x.AddAsync(It.IsAny <ProductEntity>())) .ReturnsAsync(product); var result = _handler.Handle(_createProductFaker.Generate(), CancellationToken.None).Result; _productRepositoryMock.Verify(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once); _productRepositoryMock.Verify(x => x.AddAsync(It.IsAny <ProductEntity>()), Times.Once); result.Should().NotBeNull(); }