示例#1
0
        public void CreateCampaign_Command_Should_Run_Correctly()
        {
            var command = _createCampaignCommandFaker.Generate();

            _productRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()))
            .ReturnsAsync(true);

            _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()))
            .ReturnsAsync(new List <CampaignEntity>());

            _campaignRepositoryMock.Setup(x => x.AnyAsync(MoqHelper.IsExpression <CampaignEntity>(campaign => campaign.Name == command.CampaignName)))
            .ReturnsAsync(false);

            _campaignRepositoryMock.Setup(x => x.AddAsync(It.IsAny <CampaignEntity>()))
            .ReturnsAsync(FakeObjects.GenerateCampaign());

            var result = _handler.Handle(command, CancellationToken.None).Result;

            result.Campaign.Should().NotBeNull();

            _productRepositoryMock.Verify(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once);
            _campaignRepositoryMock.Verify(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once);
            _campaignRepositoryMock.Verify(x => x.AnyAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once);
            _campaignRepositoryMock.Verify(x => x.AddAsync(It.IsAny <CampaignEntity>()), Times.Once);
        }
示例#2
0
        public void CreateCampaign_Command_ShouldBe_Throw_Exception_When_There_Is_ActiveCampaign_For_SameProduct()
        {
            _productRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()))
            .ReturnsAsync(true);

            _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()))
            .ReturnsAsync(new List <CampaignEntity> {
                FakeObjects.GenerateCampaign()
            });

            Assert.ThrowsAsync <AlreadyActiveCampaignForProductException>(async() =>
            {
                await _handler.Handle(_createCampaignCommandFaker.Generate(), CancellationToken.None);
            }).Wait();
        }
示例#3
0
        public void GetProductInfo_Should_Run_Correctly_If_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>()
            {
                FakeObjects.GenerateCampaign()
            });

            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();
        }
示例#4
0
        public void CreateOrder_Command_Should_Run_Correctly_If_Product_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);

            var campaign = FakeObjects.GenerateCampaign();

            ((IEntityBase)campaign).SetId(1234);

            _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()))
            .ReturnsAsync(new List <CampaignEntity> {
                campaign
            });

            _campaignRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <CampaignEntity>()))
            .Returns(Task.CompletedTask);

            var order = FakeObjects.GenerateOrder();

            _orderRepositoryMock.Setup(x => x.AddAsync(It.IsAny <OrderEntity>())).
            ReturnsAsync(order);

            _createOrderServiceMock.Setup(x =>
                                          x.Create(It.IsAny <ProductEntity>(), It.IsAny <int>(), It.IsAny <CampaignEntity>(), It.IsAny <int>()))
            .Returns(order);

            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.Once);

            _orderRepositoryMock.Verify(x => x.AddAsync(It.IsAny <OrderEntity>()), Times.Once);

            result.Should().NotBeNull();
        }
示例#5
0
        public void GetCampaignInfo_Should_Run_Correctly()
        {
            var campaign = FakeObjects.GenerateCampaign();

            _campaignRepositoryMock.Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()))
            .ReturnsAsync(campaign);

            var query = new GetCampaignInfoQuery
            {
                CampaignName = campaign.Name
            };

            var result = _handler.Handle(query, CancellationToken.None).Result;

            _campaignRepositoryMock.Verify(x => x.FindOneAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once);

            result.Should().NotBeNull();
            result.Name.Should().Be(campaign.Name);
            result.TargetSales.Should().Be(campaign.TargetSalesCount);
            result.TotalSales.Should().Be(campaign.TotalSalesCount);
            result.AverageItemPrice.Should().Be(campaign.AverageItemPrice);
            result.IsActive.Should().Be(true);
        }