Beispiel #1
0
        private void UpdateCampaign(UpdateCampaignInfoInput updateCampaignInfoInput, Campaign campaign, int campaignStatus)
        {
            int     totalsales         = campaign.TotalSales + updateCampaignInfoInput.Quantity;
            decimal turnover           = campaign.Turnover + updateCampaignInfoInput.Price;
            decimal averegateitemprice = turnover / totalsales;

            _campaignRepository.UpdateCampaignInfo(new UpdateCampaignInfoRequest(
                                                       campaign.Id,
                                                       totalsales,
                                                       turnover,
                                                       averegateitemprice,
                                                       campaignStatus
                                                       ));
        }
Beispiel #2
0
        public void UpdateCampaignInfo(UpdateCampaignInfoInput updateCampaignInfoInput)
        {
            var campaign = _campaignRepository.GetCampaignById(updateCampaignInfoInput.CampaignId);

            if (campaign != null && campaign.Status == (int)Dto.CampaignStatusEnum.Active)
            {
                int totalSales = (updateCampaignInfoInput.Quantity + campaign.TotalSales);
                if (totalSales >= campaign.TargetSalesCount)
                {
                    UpdateCampaign(updateCampaignInfoInput, campaign, (int)CampaignStatusEnum.Ended);
                }
                else
                {
                    UpdateCampaign(updateCampaignInfoInput, campaign, (int)CampaignStatusEnum.Active);
                }
            }
        }
Beispiel #3
0
        public void When_UpdateCampaign_IsNull()
        {
            UpdateCampaignInfoInput input = new UpdateCampaignInfoInput
            {
                CampaignId  = Guid.Empty,
                ProductCode = "P1",
                Price       = 100,
                Quantity    = 10
            };
            Product product = new Product("P1", 100, 1000);

            mockProductRepository.Setup(x => x.GetProduct("P1")).Returns(product);
            Campaign campaign = new Campaign("C1", "P1", 10, 20, 100);

            mockCampaignRepository.Setup(x => x.GetCampaign("C1")).Returns(campaign);

            Assert.DoesNotThrow(() => campaignService.UpdateCampaignInfo(input));

            mockCampaignRepository.Verify(x => x.UpdateCampaignInfo(It.IsAny <UpdateCampaignInfoRequest>()), Times.Never());
        }
Beispiel #4
0
        public void When_UpdateCampaignInfo_IsSuccessful()
        {
            Product product = new Product("P1", 100, 1000);

            mockProductRepository.Setup(x => x.GetProduct("P1")).Returns(product);
            Campaign campaign = new Campaign("C1", "P1", 10, 20, 100);

            mockCampaignRepository.Setup(x => x.GetCampaignById(campaign.Id)).Returns(campaign);


            UpdateCampaignInfoInput input = new UpdateCampaignInfoInput
            {
                CampaignId  = campaign.Id,
                ProductCode = "P1",
                Price       = 100,
                Quantity    = 10
            };

            Assert.DoesNotThrow(() => campaignService.UpdateCampaignInfo(input));

            mockCampaignRepository.Verify(x => x.UpdateCampaignInfo(It.IsAny <UpdateCampaignInfoRequest>()), Times.Once());
        }