public void GetBillProducts_TwoSameProductsDue2Months_ReturnsProductQuantity4(int addHours)
        {
            var plans = new List <ApiPaymentPlan>()
            {
                new ApiPaymentPlan()
                {
                    Id             = 1,
                    ProductName    = ProductNameA,
                    NextChargeDate = NowMonth.AddMonths(-1),
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid
                },
                new ApiPaymentPlan()
                {
                    Id             = 2,
                    ProductName    = ProductNameA,
                    NextChargeDate = NowMonth.AddMonths(-1),
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaidTrial
                }
            };

            var result = Model.GetBillProducts(CreateContact(), plans, _now.AddHours(addHours));

            Assert.Single(result);
            Assert.Equal(ProductNameA, result[0].Name);
            Assert.Equal(ProductPrice, result[0].Price);
            Assert.Equal(4, result[0].Quantity);
        }
        public void GetBillProducts_TwoSameProductsDueDiffAmount_ReturnsTwoProducts(int addHours)
        {
            var plans = new List <ApiPaymentPlan>()
            {
                new ApiPaymentPlan()
                {
                    Id             = 1,
                    ProductName    = ProductNameA,
                    NextChargeDate = NowMonth,
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid
                },
                new ApiPaymentPlan()
                {
                    Id             = 2,
                    ProductName    = ProductNameA,
                    NextChargeDate = NowMonth,
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid,
                    StartDate      = NowMonth.AddDays(-15)
                }
            };

            var result = Model.GetBillProducts(CreateContact(), plans, _now.AddHours(addHours));

            Assert.Equal(2, result.Count);
            Assert.Equal(ProductNameA, result[0].Name);
            Assert.Equal(ProductPrice, result[0].Price);
            Assert.Equal(1, result[0].Quantity);
            Assert.Equal(ProductNameA, result[1].Name);
            Assert.InRange(result[1].Price, ProductPrice * .4m, ProductPrice * .6m);
            Assert.Equal(1, result[1].Quantity);
        }
        public void GetBillProducts_PostpaidTrialPlusPaid_ReturnsEmpty()
        {
            // Trial will be charged on the next billing cycle.
            var plans = new List <ApiPaymentPlan>()
            {
                new ApiPaymentPlan()
                {
                    Id = 1,
                    //NextChargeDate = _now,
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaidTrial,
                    PeriodQty      = 20,
                    StartDate      = _now.AddDays(-15)
                },
                new ApiPaymentPlan()
                {
                    Id             = 2,
                    NextChargeDate = NowMonth.AddMonths(1),
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid
                }
            };

            var result = Model.GetBillProducts(CreateContact(), plans, _now);

            Assert.Empty(result);
        }
        public void GetBillProducts_PostpaidDueTwoMonths_ReturnsDoublePrice(int addHours)
        {
            var plans = new List <ApiPaymentPlan>()
            {
                new ApiPaymentPlan()
                {
                    Id             = 1,
                    NextChargeDate = NowMonth.AddMonths(-1),
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid
                }
            };

            var result = Model.GetBillProducts(CreateContact(), plans, _now.AddHours(addHours));

            Assert.Single(result);
            Assert.Equal(ProductPrice * 2, result[0].Price * result[0].Quantity);
        }
        public void GetBillProducts_PostpaidDueThreeHalfMonths_ReturnsThreeHalfPrice(int addHours)
        {
            var plans = new List <ApiPaymentPlan>()
            {
                new ApiPaymentPlan()
                {
                    Id             = 1,
                    NextChargeDate = NowMonth.AddMonths(-2),
                    PricePerPeriod = ProductPrice,
                    PeriodUnit     = PaymentPeriodUnit.MonthPostpaid,
                    StartDate      = NowMonth.AddDays(-106)
                }
            };

            var result = Model.GetBillProducts(CreateContact(), plans, _now.AddHours(addHours));

            Assert.Single(result);
            Assert.InRange(result[0].Price, ProductPrice * 3.4m, ProductPrice * 3.6m);
            Assert.Equal(1, result[0].Quantity);
        }