public void CanGetStartAndEndDates()
        {
            Assert.AreEqual(DateTime.Parse("2016-09-23"), ReservationHistoryUtility.GetStartDate("09/23/2016"));
            Assert.AreEqual(DateTime.Now.Date, ReservationHistoryUtility.GetStartDate(DateTime.Now.ToString()));
            Assert.AreEqual(DateTime.Now.Date, ReservationHistoryUtility.GetStartDate("invalid text"));
            Assert.AreEqual(Reservation.MinReservationBeginDate, ReservationHistoryUtility.GetStartDate(null));
            Assert.AreEqual(Reservation.MinReservationBeginDate, ReservationHistoryUtility.GetStartDate(""));

            Assert.AreEqual(DateTime.Parse("2016-09-24"), ReservationHistoryUtility.GetEndDate("09/23/2016"));
            Assert.AreEqual(DateTime.Now.Date.AddDays(1), ReservationHistoryUtility.GetEndDate(DateTime.Now.ToString()));
            Assert.AreEqual(DateTime.Now.Date.AddDays(1), ReservationHistoryUtility.GetEndDate("invalid text"));
            Assert.AreEqual(Reservation.MaxReservationEndDate, ReservationHistoryUtility.GetEndDate(null));
            Assert.AreEqual(Reservation.MaxReservationEndDate, ReservationHistoryUtility.GetEndDate(""));
        }
        public void ProcessRequest(HttpContext context)
        {
            HttpContextBase ctx = new HttpContextWrapper(context);

            ctx.Response.ContentType = "application/json";

            string command = ctx.Request["Command"];

            int clientId = Utility.ConvertTo(ctx.Request["ClientID"], 0);

            DateTime period;

            object result;

            if (command == "update-billing")
            {
                period = Convert.ToDateTime(ctx.Request["Period"]);

                Provider.Billing.Process.UpdateBilling(new UpdateBillingArgs
                {
                    BillingCategory = BillingCategory.Tool | BillingCategory.Room,
                    ClientID        = clientId,
                    Periods         = new[] { period }
                });

                result = new { Error = false, Message = "ok" };
            }
            else if (command == "reservation-history-billing-update")
            {
                bool            error                    = false;
                string          msg                      = "OK!";
                DataCleanResult dataCleanResult          = null;
                DataResult      dataResult               = null;
                Step1Result     step1Result              = null;
                PopulateSubsidyBillingResult step4Result = null;

                bool isTemp;

                try
                {
                    period = Convert.ToDateTime(ctx.Request["Period"]);

                    isTemp = Utility.IsCurrentPeriod(period);

                    dataCleanResult = Provider.Billing.Process.DataClean(new DataCleanCommand
                    {
                        BillingCategory = BillingCategory.Tool | BillingCategory.Room,
                        ClientID        = clientId,
                        StartDate       = period,
                        EndDate         = period.AddMonths(1)
                    });

                    dataResult = Provider.Billing.Process.Data(new DataCommand
                    {
                        BillingCategory = BillingCategory.Tool | BillingCategory.Room,
                        ClientID        = clientId,
                        Period          = period,
                        Record          = 0
                    });

                    step1Result = Provider.Billing.Process.Step1(new Step1Command
                    {
                        BillingCategory = BillingCategory.Tool | BillingCategory.Room,
                        ClientID        = clientId,
                        Period          = period,
                        Record          = 0,
                        Delete          = true,
                        IsTemp          = isTemp
                    });

                    // [2022-01-06 jg] Adding subsidy calculation, not sure why this wasn't already being done. Definitely need to recalculate in case account is changed from
                    //      internal to external or vice versa.

                    step4Result = Provider.Billing.Process.Step4(new Step4Command
                    {
                        ClientID = clientId,
                        Period   = period,
                        Command  = "subsidy"
                    });

                    // [2022-01-06 jg] This error check does not work for staff because repair reservations exist in ToolDataClean
                    //      but are not added to ToolData (and subsequently ToolBilling), so ToolDataClean rows loaded
                    //      can be greater than ToolData rows loaded. So now it will be skipped if the client is staff.

                    var c = Provider.Data.Client.GetClient(clientId);
                    if (!c.HasPriv(ClientPrivilege.Staff))
                    {
                        var toolDataRowsLoaded      = dataResult.WriteToolDataProcessResult.RowsLoaded;
                        var toolDataCleanRowsLoaded = dataCleanResult.WriteToolDataCleanProcessResult.RowsLoaded;
                        var step1RowsLoaded         = step1Result.PopulateToolBillingProcessResult.RowsLoaded;

                        string errmsg = string.Empty;

                        if (toolDataRowsLoaded < toolDataCleanRowsLoaded)
                        {
                            errmsg += $" Tool data row count ({toolDataRowsLoaded}) is less than tool data clean row count ({toolDataCleanRowsLoaded}).";
                        }

                        if (step1RowsLoaded < toolDataRowsLoaded)
                        {
                            errmsg += $" Step1 row count ({step1RowsLoaded}) is less than tool data row count ({toolDataRowsLoaded}).";
                        }

                        var errorCheck =
                            toolDataRowsLoaded >= toolDataCleanRowsLoaded &&
                            step1RowsLoaded >= toolDataRowsLoaded;

                        if (!errorCheck)
                        {
                            throw new Exception($"A problem occurred when trying to update billing data. {errmsg} Period: {period:yyyy-MM-dd:HH:mm:ss}, ClientID: {clientId}, Rows Loaded: DataClean = {dataCleanResult.WriteToolDataCleanProcessResult.RowsLoaded}, Data = {dataResult.WriteToolDataProcessResult.RowsLoaded}, Step1 = {step1Result.PopulateToolBillingProcessResult.RowsLoaded}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = true;
                    msg   = ex.Message;
                    SendEmail.SendDebugEmail(clientId, "LNF.Web.Scheduler.Handlers.ReservationHandler.ProcessRequest", $"[DEBUG:{DateTime.Now:yyyy-MM-dd HH:mm:ss}] An error occurred while updating billing from the Reservation History page.", msg);
                }

                result = new { Error = error, Message = msg, DataCleanResult = dataCleanResult, DataResult = dataResult, Step1Result = step1Result, Step4Result = step4Result };
            }
            else if (command == "get-clients-for-reservation-history")
            {
                bool     isok = clientId > 0;
                DateTime sd, ed;

                if (string.IsNullOrEmpty(ctx.Request.Form["StartDate"]))
                {
                    sd = Reservations.MinReservationBeginDate;
                }
                else
                {
                    isok &= DateTime.TryParse(ctx.Request.Form["StartDate"], out sd);
                }

                if (string.IsNullOrEmpty(ctx.Request.Form["EndDate"]))
                {
                    ed = Reservations.MaxReservationEndDate;
                }
                else
                {
                    isok &= DateTime.TryParse(ctx.Request.Form["EndDate"], out ed);
                }

                IEnumerable <ReservationHistoryClient> clients = null;

                if (isok)
                {
                    clients = ReservationHistoryUtility.Create(Provider).SelectReservationHistoryClients(sd, ed, clientId);
                    result  = new { Error = false, Message = "OK", Clients = clients };
                }
                else
                {
                    result = new { Error = true, Message = "One or more parameters are invalid.", Clients = clients };
                }
            }
            else if (int.TryParse(ctx.Request["ReservationID"], out int reservationId))
            {
                switch (command)
                {
                case "start-reservation":
                    clientId = ctx.CurrentUser(Provider).ClientID;
                    result   = ReservationHandlerUtility.Start(ctx, Provider, reservationId, clientId);
                    break;

                case "get-reservation":
                    result = ReservationHandlerUtility.GetReservation(ctx, Provider, reservationId);
                    break;

                case "save-reservation-history":
                    string notes       = ctx.Request["Notes"];
                    double forgivenPct = Utility.ConvertTo(ctx.Request["ForgivenPct"], 0D);
                    int    accountId   = Utility.ConvertTo(ctx.Request["AccountId"], 0);
                    bool   emailClient = Utility.ConvertTo(ctx.Request["EmailClient"], false);

                    double chargeMultiplier = 1.00 - (forgivenPct / 100.0);

                    clientId = ctx.CurrentUser(Provider).ClientID;

                    var model = new ReservationHistoryUpdate()
                    {
                        ReservationID    = reservationId,
                        AccountID        = accountId,
                        ChargeMultiplier = chargeMultiplier,
                        Notes            = notes,
                        EmailClient      = emailClient,
                        ClientID         = clientId
                    };

                    bool   updateResult = Provider.Scheduler.Reservation.UpdateReservationHistory(model);
                    string msg          = updateResult ? "OK" : "An error occurred.";
                    result = new
                    {
                        Error   = !updateResult,
                        Message = msg
                    };

                    break;

                case "test":
                    result = new { Error = false, Message = "ok" };
                    break;

                case "":
                    throw new Exception("Missing parameter: command");

                default:
                    throw new Exception("Invalid command: " + command);
                }
            }
            else
            {
                throw new Exception("Missing parameter: command");
            }

            ctx.Response.Write(JsonConvert.SerializeObject(result));
        }
        public void TestReservationCanBeForgiven()
        {
            var holidays       = Utility.GetHolidays(DateTime.Parse("2016-01-01"), DateTime.Parse("2017-01-01"));
            int maxForgivenDay = int.Parse(Utility.GetRequiredAppSetting("MaxForgivenDay"));

            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations

            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is before when the reservation ended - staff cannot forgive before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), maxForgivenDay, holidays));     //true because 'now' is still in the same day as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is after the 3rd business day after the reservation - the 3 business days are 1, 2, and 6 because 3 and 4 were weekend days and 5 was a holiday - staff cannot change accts after the 3rd business day

            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), maxForgivenDay, holidays)); //true because admin can always forgive

            //*****************************

            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-25 20:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-26 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-27 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-28 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-29 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations

            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is before when the reservation ended - staff cannot forgive before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-25 20:00:00"), maxForgivenDay, holidays));     //true because 'now' is still in the same day as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-26 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-27 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-28 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation3, DateTime.Parse("2016-07-29 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is after the 3rd business day - the 3 business days are 1, 2, and 3 because there are no weekend days or holidays during the first 3 days of August - staff cannot change accts after the 3rd business day

            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-25 20:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-26 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-27 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-28 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-29 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct

            //*****************************
            // ended 2016-09-08 17:32:30.000
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-08 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-08 20:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-09 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-10 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-11 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-12 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-13 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(weibin), Reservation5, DateTime.Parse("2016-09-14 00:00:00"), maxForgivenDay, holidays));  //false because normal lab users cannot forgive reservations

            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-08 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is before when the reservation ended - staff cannot forgive before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-08 20:00:00"), maxForgivenDay, holidays));     //true because 'now' is still in the same day as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-09 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-10 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-11 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-12 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-13 00:00:00"), maxForgivenDay, holidays));     //true because 'now' is before the 3rd business day after the reservation
            Assert.IsFalse(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(greg), Reservation5, DateTime.Parse("2016-09-14 00:00:00"), maxForgivenDay, holidays));    //false because 'now' is after the 3rd business day - the 3 business days are 9, 12, and 13 because 10 and 11 are weekend days - staff cannot change accts after the 3rd business day

            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-08 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-08 20:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-09 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-10 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-11 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-12 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-13 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationCanBeForgiven(GetClient(sandrine), Reservation5, DateTime.Parse("2016-09-14 00:00:00"), maxForgivenDay, holidays)); //true because admin can always change the acct
        }
        public void TestReservationAccountCanBeChanged()
        {
            var holidays = Utility.GetHolidays(DateTime.Parse("2016-01-01"), DateTime.Parse("2017-01-01"));

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), holidays));        //false because 'now' is before when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), holidays));         //true because 'now' is still in the same month as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month\
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), holidays));        //false because 'now' is after the 3rd business day - the 3 business days are 1, 2, and 6 because 3 and 4 were weekend days and 5 was a holiday - normal lab user cannot change accts after the 3rd business day

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), holidays));          //false because 'now' is before when the reservation ended - staff cannot modify before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), holidays));           //true because 'now' is still in the same month as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), holidays));          //false because 'now' is after the 3rd business day - the 3 business days are 1, 2, and 6 because 3 and 4 were weekend days and 5 was a holiday - staff cannot change accts after the 3rd business day

            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), holidays));       //true because admin can always change the acct

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-08-31 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-08-31 23:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-01 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-02 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-03 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-04 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-05 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-06 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation2, DateTime.Parse("2016-09-07 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver

            //*****************************

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), holidays));        //false because 'now' is before when the reservation ended - normal lab user cannot modify before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-07-31 00:00:00"), holidays));         //true because 'now' is still in the same month as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-08-01 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-08-02 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-08-03 00:00:00"), holidays));         //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(weibin), Reservation3, DateTime.Parse("2016-08-04 00:00:00"), holidays));        //false because 'now' is after the 3rd business day - the 3 business days are 1, 2, and 3 because there are no weekend days or holidays during the first 3 days of August - normal lab user cannot change accts after the 3rd business day

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), holidays));          //false because 'now' is before when the reservation ended - staff cannot modify before the reservation has ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-07-31 00:00:00"), holidays));           //true because 'now' is still in the same month as when the reservation ended
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-08-01 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-08-02 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-08-03 00:00:00"), holidays));           //true because 'now' is before the 3rd business day after the 1st of the following month
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(greg), Reservation3, DateTime.Parse("2016-08-04 00:00:00"), holidays));          //false because 'now' is after the 3rd business day - the 3 business days are 1, 2, and 3 because there are no weekend days or holidays during the first 3 days of August - staff cannot change accts after the 3rd business day

            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-07-31 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-08-01 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-08-02 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-08-03 00:00:00"), holidays));       //true because admin can always change the acct
            Assert.IsTrue(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(sandrine), Reservation3, DateTime.Parse("2016-08-04 00:00:00"), holidays));       //true because admin can always change the acct

            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-07-25 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-07-31 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-08-01 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-08-02 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-08-03 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
            Assert.IsFalse(ReservationHistoryUtility.ReservationAccountCanBeChanged(GetClient(davidPellinen), Reservation3, DateTime.Parse("2016-08-04 00:00:00"), holidays)); //false because pellinen is a normal lab user and not the reserver
        }