public void CanCreateRelative()
 {
     var schedule = new PricingSchedule(10M, 30);
     Assert.IsFalse(schedule.IsAbsolute);
     Assert.AreEqual(10M, schedule.Cost);
     Assert.AreEqual(30, schedule.RelativeDays);
 }
 public void CanCreateAbsolute()
 {
     var schedule = new PricingSchedule(10M, new DateTime(2000, 1, 1));
     Assert.AreEqual(10M, schedule.Cost);
     Assert.AreEqual(new DateTime(2000, 1, 1), schedule.AbsoluteDate.Value);
     Assert.IsTrue(schedule.IsAbsolute);
 }
        public static void CaptureCostScheduleData(EventOccurrenceV2 source, EventOccurrence target)
        {
            Decimal? sourceEarlyCost = GetDecimalValue(source.EarlyCost);
            var sourceEarlyCostEndDate = GetDateTime(source.EarlyCostEndDate);
            var sourceEarlyCostEndDays = GetNullableInt(source.EarlyCostEndDays);

            var earlyScheduleHasNecessaryValues = sourceEarlyCost.HasValue && (sourceEarlyCostEndDate.HasValue || sourceEarlyCostEndDays.HasValue);

            if (earlyScheduleHasNecessaryValues)
            {
                var hasEarlyDateValue = sourceEarlyCostEndDate.HasValue;
                if (hasEarlyDateValue)
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(sourceEarlyCost.Value, sourceEarlyCostEndDate.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
                else
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(sourceEarlyCost.Value, sourceEarlyCostEndDays.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
            }
            else
            {
                target.SetEarlyRegistrationPrice(null);
            }

            Decimal? sourceLateCost = GetDecimalValue(source.LateCost);
            var sourceLateCostStartDate = GetDateTime(source.LateCostStartDate);
            var sourceLateCostStartDays = GetNullableInt(source.LateCostStartDays);

            var lateScheduleHasNecessaryValues = sourceLateCost.HasValue && (sourceLateCostStartDate.HasValue || sourceLateCostStartDays.HasValue);
            if (lateScheduleHasNecessaryValues)
            {
                var hasLateDateValue = sourceLateCostStartDate.HasValue;
                if (hasLateDateValue)
                {
                    var LateCostPriceSchedule = new PricingSchedule(sourceLateCost.Value, sourceLateCostStartDate.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
                else
                {
                    var LateCostPriceSchedule = new PricingSchedule(sourceLateCost.Value, sourceLateCostStartDays.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
            }
            else
            {
                target.SetLateRegistrationPrice(null);
            }
        }
        public void TestAddDate_DisablePricingSchedule()
        {
            var occurrence = new EventOccurrence() { Event = new Event() };
            occurrence.AddOccurrenceDate(new DateTime(2000, 1, 1), new DateTime(2000, 1, 2));

            var earlySchedule = new PricingSchedule(10M, new DateTime(1999, 01, 01));
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            var lateSchedule = new PricingSchedule(10M, new DateTime(1999, 12, 01));
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            occurrence.EnablePricingSchedule();

            occurrence.AddOccurrenceDate(new DateTime(1999, 12, 30), new DateTime(1999, 12, 31));

            Assert.IsFalse(occurrence.IsPriceScheduleEnabled);
        }
        public void TestCalculateCost_EarlyAbsolute()
        {
            var earlyCuttofDate = new DateTime(2000, 1, 1);
            var defaultCost = 10M;
            var earlyCost = 5M;
            var ev = new Event();
            ev.Cost = defaultCost;
            var occurrence = new EventOccurrence() { Event = ev, Cost = defaultCost };
            occurrence.AddOccurrenceDate(new DateTime(2000, 3, 1), new DateTime(2000, 3, 2));
            var earlySchedule = new PricingSchedule(earlyCost, earlyCuttofDate);
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            occurrence.EnablePricingSchedule();

            Assert.AreEqual(earlyCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(-1)));
            Assert.AreEqual(earlyCost, occurrence.CalculateCost(earlyCuttofDate));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(1)));

            occurrence.DisablePricingSchedule();

            Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(-1)));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(1)));
        }
        public void TestIsEarlyAndLateAbsoluteMode_lateAbsolute()
        {
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };

            var lateSchedule = new PricingSchedule(10M, new DateTime(1999, 01, 01));
            occurrence.SetLateRegistrationPrice(lateSchedule);

            Assert.IsTrue(occurrence.IsEarlyAndLateAbsoluteMode);
        }
        public void TestIsEarlyAndLateAbsoluteMode_earlyRelative()
        {
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };

            var earlySchedule = new PricingSchedule(10M, 30);
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            Assert.IsFalse(occurrence.IsEarlyAndLateAbsoluteMode);
        }
        public void TestIsEarlyAndLateAbsoluteMode_earlyAbsoluteLateRelative()
        {
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };

            var earlySchedule = new PricingSchedule(10M, new DateTime(1999, 01, 01));
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            var lateSchedule = new PricingSchedule(10M, 10);
            occurrence.SetLateRegistrationPrice(lateSchedule);

            // this case shouldn't be allowed in the wild...
            // still though, this test should pass
            Assert.IsFalse(occurrence.IsEarlyAndLateAbsoluteMode);
        }
        public void TestEnablePricingSchedule_LateSpecified()
        {
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };
            var pricingSchedule = new PricingSchedule(10M, 30);
            occurrence.SetLateRegistrationPrice(pricingSchedule);
            occurrence.EnablePricingSchedule();

            Assert.IsTrue(occurrence.IsPriceScheduleEnabled);
        }
        public void TestEnablePricingSchedule()
        {
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };
            var earlySchedule = new PricingSchedule(10M, 30);
            occurrence.SetEarlyRegistrationPrice(earlySchedule);
            var lateSchedule = new PricingSchedule(20M, 30);
            occurrence.SetLateRegistrationPrice(lateSchedule);
            occurrence.EnablePricingSchedule();

            Assert.IsTrue(occurrence.IsPriceScheduleEnabled);
        }
        public void TestCalculateCost_LateRelative()
        {
            var firstOccurrenceDate = new DateTime(2000, 1, 1);
            var lateDays = 5;
            var defaultCost = 10M;
            var lateCost = 15M;
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };
            occurrence.AddOccurrenceDate(firstOccurrenceDate, firstOccurrenceDate.AddHours(1));
            occurrence.Cost = defaultCost;
            var lateSchedule = new PricingSchedule(lateCost, lateDays);
            occurrence.SetLateRegistrationPrice(lateSchedule);
            occurrence.SetRegistrationDates(null, firstOccurrenceDate.AddDays(-1));

            occurrence.EnablePricingSchedule();

            Assert.AreEqual(defaultCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-6)));
            Assert.AreEqual(lateCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-5)));
            Assert.AreEqual(lateCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-4)));

            occurrence.DisablePricingSchedule();

            Assert.AreEqual(defaultCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-6)));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-5)));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(firstOccurrenceDate.AddDays(-4)));
        }
        public void TestCalculateCost_LateAbsolute()
        {
            var lateDate = new DateTime(2000, 1, 1);
            var defaultCost = 10M;
            var lateCost = 15M;
            var ev = new Event();
            var occurrence = new EventOccurrence() { Event = ev };
            occurrence.AddOccurrenceDate(lateDate.AddDays(30), lateDate.AddDays(31));
            occurrence.Cost = defaultCost;
            var lateSchedule = new PricingSchedule(lateCost, lateDate);
            occurrence.SetLateRegistrationPrice(lateSchedule);

            occurrence.EnablePricingSchedule();

            Assert.AreEqual(defaultCost, occurrence.CalculateCost(lateDate.AddDays(-1)));
            Assert.AreEqual(lateCost, occurrence.CalculateCost(lateDate));
            Assert.AreEqual(lateCost, occurrence.CalculateCost(lateDate.AddDays(1)));

            occurrence.DisablePricingSchedule();

            Assert.AreEqual(defaultCost, occurrence.CalculateCost(lateDate.AddDays(-1)));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(lateDate));
            Assert.AreEqual(defaultCost, occurrence.CalculateCost(lateDate.AddDays(1)));
        }
        /// <summary>
        /// Sets the early registration price.
        /// </summary>
        /// <param name="schedule">The schedule.</param>
        public void SetEarlyRegistrationPrice(PricingSchedule schedule)
        {
            if (schedule == null)
            {
                EarlyCost = null;
                EarlyCostEndDate = null;
                EarlyCostEndDays = null;
                return;
            }

            EarlyCost = schedule.Cost;
            EarlyCostEndDate = schedule.AbsoluteDate;
            EarlyCostEndDays = schedule.RelativeDays;
        }
 /// <summary>
 /// Sets the late registration price.
 /// </summary>
 /// <param name="schedule">The schedule.</param>
 public void SetLateRegistrationPrice(PricingSchedule schedule)
 {
     if (schedule == null)
     {
         LateCost = null;
         LateCostStartDate = null;
         LateCostStartDays = null;
         return;
     }
     LateCost = schedule.Cost;
     LateCostStartDate = schedule.AbsoluteDate;
     LateCostStartDays = schedule.RelativeDays;
 }
        private static void CaptureCostScheduleData(EventOccurrence source, EventOccurrence target)
        {
            var earlyScheduleHasNecessaryValues = source.EarlyCost.HasValue && (source.EarlyCostEndDate.HasValue || source.EarlyCostEndDays.HasValue);

            if (earlyScheduleHasNecessaryValues)
            {
                var hasEarlyDateValue = source.EarlyCostEndDate.HasValue;
                if (hasEarlyDateValue)
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(source.EarlyCost.Value, source.EarlyCostEndDate.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
                else
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(source.EarlyCost.Value, source.EarlyCostEndDays.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
            }
            else
            {
                target.SetEarlyRegistrationPrice(null);
            }

            var lateScheduleHasNecessaryValues = source.LateCost.HasValue && (source.LateCostStartDate.HasValue || source.LateCostStartDays.HasValue);
            if (lateScheduleHasNecessaryValues)
            {
                var hasLateDateValue = source.LateCostStartDate.HasValue;
                if (hasLateDateValue)
                {
                    var LateCostPriceSchedule = new PricingSchedule(source.LateCost.Value, source.LateCostStartDate.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
                else
                {
                    var LateCostPriceSchedule = new PricingSchedule(source.LateCost.Value, source.LateCostStartDays.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
            }
            else
            {
                target.SetLateRegistrationPrice(null);
            }
        }