Beispiel #1
0
        private static SmoothSponsorshipRestrictionLimits CalculateRestrictionLimitsForAllCompetitorsWhenCalculationTypeIsPercentage(SmoothSponsorshipRunningTotals input)
        {
            var totalSponsoredProduct = input.SponsoredProducts.Sum(x => x.Value);

            if (totalSponsoredProduct == 0)
            {
                return(AllCompetitorsWithUnlimitedAvailibility(input));
            }

            var output = new SmoothSponsorshipRestrictionLimits();
            var competitorsAndRestrictionValues = input.GetRestrictionValuesForCompetitors();
            var alreadyBookedCompetitorsInTotal = input.AlreadyPlacedCompetitors.Sum(x => x.Value);

            foreach (var item in competitorsAndRestrictionValues)
            {
                var productId           = item.Key;
                var maximumAllowedValue = CalculateRestrictionValueForPercentage(item.Value, totalSponsoredProduct);
                var availValueRemaining = maximumAllowedValue - alreadyBookedCompetitorsInTotal;
                if (availValueRemaining > 0)
                {
                    output.AvailabilitiesForCompetitors.Add(productId, availValueRemaining);
                }
            }
            return(output);
        }
        internal void GivenTheProductsAreAssignedToClashCodesAndAdvertiserIdentifierWhenTheRestrictionValuesAreSetForEachCode_ThenTheProductsWithMoreRestrictionValuesAssignToThemGetTheMinimumRestrictionValue()
        {
            var runningTotal = new SmoothSponsorshipRunningTotals();

            runningTotal.AddCompetitorToClashCode("p1", "c1");
            runningTotal.AddCompetitorToClashCode("p2", "c1");
            runningTotal.AddCompetitorToClashCode("p1", "c2");
            runningTotal.AddCompetitorToAdvertiserIdentifier("p1", "a1");
            runningTotal.AddCompetitorToAdvertiserIdentifier("p2", "a1");
            runningTotal.AddCompetitorToAdvertiserIdentifier("p1", "a2");

            runningTotal.SetRestrictionValueForClashCode("c1", 10);
            runningTotal.SetRestrictionValueForClashCode("c2", 20);
            runningTotal.SetRestrictionValueForClashCode("c1", 1);
            runningTotal.SetRestrictionValueForClashCode("c2", 2);
            runningTotal.SetRestrictionValueForClashCode("a1", 100);
            runningTotal.SetRestrictionValueForClashCode("a2", 200);
            runningTotal.SetRestrictionValueForClashCode("a1", 10);
            runningTotal.SetRestrictionValueForClashCode("a2", 20);

            var restrictionValuesForCompetitors = runningTotal.GetRestrictionValuesForCompetitors();

            Assert.Equal(new ProductExternalReference[] { "p1", "p2", "c1", "c2", "a1", "a2" }, restrictionValuesForCompetitors.Keys.ToArray());
            Assert.Equal(1, restrictionValuesForCompetitors["p1"]);
            Assert.Equal(1, restrictionValuesForCompetitors["p2"]);
            Assert.Equal(1, restrictionValuesForCompetitors["c1"]);
            Assert.Equal(2, restrictionValuesForCompetitors["c2"]);
            Assert.Equal(10, restrictionValuesForCompetitors["a1"]);
            Assert.Equal(20, restrictionValuesForCompetitors["a2"]);
        }
Beispiel #3
0
        private static SmoothSponsorshipRestrictionLimits CalculateRestrictionLimitsForAllCompetitorsWhenCalculationTypeIsFlat(SmoothSponsorshipRunningTotals input)
        {
            var output = new SmoothSponsorshipRestrictionLimits();
            var competitorsAndRestrictionValues = input.GetRestrictionValuesForCompetitors();
            var alreadyBookedCompetitorsInTotal = input.AlreadyPlacedCompetitors.Sum(x => x.Value);

            foreach (var item in competitorsAndRestrictionValues)
            {
                var productId           = item.Key;
                var availValueRemaining = item.Value - alreadyBookedCompetitorsInTotal;

                if (availValueRemaining > 0)
                {
                    output.AvailabilitiesForCompetitors.Add(productId, availValueRemaining);
                }
            }
            return(output);
        }
        internal void GivenNoProductsAreAssignedToClashCodesAndAdvertiserIdentifierWhenTheRestrictionValuesAreSetForEachCodeClashAndAdvertiserThenTheClashesAndAdvertisersWillBeInTheRrestrictionValue()
        {
            var runningTotal = new SmoothSponsorshipRunningTotals();

            runningTotal.SetRestrictionValueForClashCode("c1", 10);
            runningTotal.SetRestrictionValueForClashCode("c2", 20);
            runningTotal.SetRestrictionValueForClashCode("c1", 1);
            runningTotal.SetRestrictionValueForClashCode("c2", 2);
            runningTotal.SetRestrictionValueForClashCode("a1", 100);
            runningTotal.SetRestrictionValueForClashCode("a2", 200);
            runningTotal.SetRestrictionValueForClashCode("a1", 10);
            runningTotal.SetRestrictionValueForClashCode("a2", 20);

            var restrictionValuesForCompetitors = runningTotal.GetRestrictionValuesForCompetitors();

            Assert.Equal(new ProductExternalReference[] { "c1", "c2", "a1", "a2" }, restrictionValuesForCompetitors.Keys.ToArray());
            Assert.Equal(1, restrictionValuesForCompetitors["c1"]);
            Assert.Equal(2, restrictionValuesForCompetitors["c2"]);
            Assert.Equal(10, restrictionValuesForCompetitors["a1"]);
            Assert.Equal(20, restrictionValuesForCompetitors["a2"]);
        }