Пример #1
0
        private ReservationData GetReservationData(int resourceId, int clientId, int accountId, int activityId, bool autoEnd, bool keepAlive, string notes, DateTime selectedDate, int startTimeHour, int startTimeMinute, int duration)
        {
            var beginDateTime = selectedDate.AddHours(startTimeHour).AddMinutes(startTimeMinute);
            var rd            = ReservationDuration.FromMinutes(beginDateTime, duration);

            var result = new ReservationData()
            {
                ResourceID          = resourceId,
                ClientID            = clientId,
                AccountID           = accountId,
                ActivityID          = activityId,
                AutoEnd             = autoEnd,
                KeepAlive           = keepAlive,
                Notes               = notes,
                ReservationDuration = rd
            };

            return(result);
        }
Пример #2
0
        public void CanCreateAndModifyReservationWithInsertForModification()
        {
            ReservationItem rsv1, rsv2;
            ResourceItem    res;

            int      resourceId    = 62020;
            DateTime beginDateTime = DateTime.Parse("2016-10-02 08:00:00");

            using (ContextManager.StartRequest(1600))
            {
                // Step 0: Purge
                int purgedRows = PurgeReservations(resourceId, beginDateTime, beginDateTime.AddHours(24));
                Console.WriteLine("Purged rows: {0}", purgedRows);

                // Step 1: Get a resource
                res = CacheManager.Current.ResourceTree().GetResource(resourceId).GetResourceItem();
                Assert.AreEqual(res.ResourceName, "EnerJet Evaporator");

                // Step 2: Create a reservation

                // Step 2.1: Init process info, and add
                var processInfos = new Models.Scheduler.ReservationProcessInfoItem[]
                {
                    new Models.Scheduler.ReservationProcessInfoItem()
                    {
                        ProcessInfoLineID = 110,
                        Value             = 100
                    }
                };

                // Step 2.2: Create the new Reservation
                rsv1 = ReservationUtility.Create(new ReservationData(processInfos)
                {
                    ClientID            = 1301,
                    ResourceID          = res.ResourceID,
                    AccountID           = 67,
                    ActivityID          = 6,
                    AutoEnd             = true,
                    KeepAlive           = true,
                    Notes               = "created by unit test",
                    ReservationDuration = new ReservationDuration(beginDateTime, res.Granularity)
                });

                Assert.IsTrue(rsv1.ReservationID > 0);
                Console.WriteLine("Created ReservationID: {0}", rsv1.ReservationID);
            }

            using (ContextManager.StartRequest(1600))
            {
                // Step 4: Modify existing

                // Step 4.1: Init process info, change value
                var processInfos           = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv1.ReservationID);
                processInfos.First().Value = 200;

                // Step 4.2: Modify the existing Reservation
                rsv2 = ReservationUtility.Modify(rsv1, new ReservationData(processInfos)
                {
                    ClientID            = 1301,
                    ResourceID          = res.ResourceID,
                    AccountID           = rsv1.AccountID,
                    ActivityID          = rsv1.ActivityID,
                    AutoEnd             = true,
                    KeepAlive           = true,
                    Notes               = "modified by unit test",
                    ReservationDuration = ReservationDuration.FromMinutes(beginDateTime, res.Granularity.TotalMinutes * 2)
                });

                Assert.IsFalse(ReferenceEquals(rsv1, rsv2));
                Assert.IsTrue(rsv2.ReservationID > 0);
                Console.WriteLine("Modified ReservationID: {0}", rsv2.ReservationID);
            }

            using (ContextManager.StartRequest(1600))
            {
                var processInfos1 = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv1.ReservationID);
                Assert.AreEqual(1, processInfos1.Count);
                Assert.AreEqual(100, processInfos1.First().Value);

                var processInfos2 = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv2.ReservationID);
                Assert.AreEqual(1, processInfos2.Count);
                Assert.AreEqual(200, processInfos2.First().Value);
            }
        }