Exemplo n.º 1
0
        public void When_Campaign_Create_IsActive_Return_True()
        {
            var campaign = new CampaignEntity("C1", "P1", 10, 10, 10, 0);

            var isActive = campaign.IsActive(4);

            Assert.True(isActive);
        }
Exemplo n.º 2
0
        public void When_Campaign_Expired_IsActive_Must_Be_Return_False()
        {
            var campaign = new CampaignEntity("C1", "P1", 10, 10, 10, 0);

            var isActive = campaign.IsActive(10);

            Assert.False(isActive);
        }
Exemplo n.º 3
0
        public decimal CalculateDiscountedPrice(CampaignEntity campaign, decimal listingPrice, int currentTime)
        {
            if (listingPrice <= 0)
            {
                throw new ValueMustBeBiggerThanZeroException(nameof(listingPrice), listingPrice);
            }

            if (campaign == null || !campaign.IsActive(currentTime))
            {
                return(listingPrice);
            }

            var manipulationPercentageByHour = campaign.PriceManipulationLimit / campaign.Duration;
            var discountPercentage           = manipulationPercentageByHour * (currentTime - campaign.CreatedTime + 1); //saat 0 oldugunda hesaplama hatasi olmamasi icin +1 ekleniyor

            return(listingPrice - listingPrice / 100 * discountPercentage);
        }