Esempio n. 1
0
        public void TestAddingSameLaneReturnsFalse()
        {
            var lane1 = new Lane { Name = "42" };
            var lane2 = new Lane { Name = "45" };
            this._session.Save(lane1);
            this._session.Save(lane2);

            Reservation resv = new Reservation();

            Assert.That(resv.AddLane(lane1), Is.True);
            Assert.That(resv.AddLane(lane2), Is.True);
            Assert.That(resv.AddLane(lane1), Is.False);
        }
Esempio n. 2
0
        public void TestGetReservationsForGivenDay()
        {
            for (int i = 0; i < this.lanes.Count-5; i++)
            {
                var reservation = new Reservation()
                {
                    CreatedAt = DateTime.Now,
                    Name = "Gert",
                    NumberOfPlayers = 4,
                    PhoneNumber = 1234,
                    PlayAt = DateTime.Now
                };

                reservation.AddLane(this.lanes[i]);
                reservation.AddTimeSlot((from y in this.timeSlots select y).First<TimeSlot>());

                this._session.Save(reservation);
            }

            var reservationService = new ReservationsService();
            var request = new Reservations {
                Date = DateTime.Now
            };

            ReservationsResponse response = reservationService.OnGet(request) as ReservationsResponse;
            Assert.That(response.ReservationList.Count, Is.EqualTo(5), "We expect that there are 5 reservations today");

            foreach (var r in response.ReservationList)
            {
                Assert.That(r, Is.Not.Null);
            }
        }
        public void TestImpossibleReservationsDueToLackOfTimeSlots()
        {
            for (int i = 0; i < this.lanes.Count; i++)
            {
                var reservation = new Reservation()
                {
                    CreatedAt = DateTime.Now,
                    Name = "Gert",
                    NumberOfPlayers = 4,
                    PhoneNumber = 1234,
                    PlayAt = DateTime.Now
                };

                reservation.AddLane(this.lanes[i]);
                reservation.AddTimeSlot((from y in this.timeSlots select y).First<TimeSlot>());

                this._session.Save(reservation);
            }
            // since we filled out all lanes at that timeslot, the next booking for that timeslot should not be possible
            var service = new ReservationPossibleService();
            var request = new ReservationPossible()
            {
                Reservation = new ReservationType()
                {
                    HowManyHours = 2,
                    NumberOfPlayers = 8,
                    PlayAt = DateTime.Now,
                    TimeOfDay = (from y in this.timeSlots select y).First<TimeSlot>().Start
                }
            };

            ReservationPossibleResponse response = service.OnPost(request) as ReservationPossibleResponse;
            Assert.That(response.IsPossible, Is.False);
            Assert.That(response.Suggestions.Count, Is.EqualTo(2));
        }
        public List<Reservation> Convert(LaneSchedulerState state, out Reservation newReservation)
        {
            int [,] internalState = state.State;
            int current = 0;
            newReservation = new Reservation();
            int laneCount = this.laneRepos.GetAll().Count();
            int timeSlotCount = this.timeSlotRepos.GetAll().Count();

            List<ReservationLaneTimeSlotPair> pairs = new List<ReservationLaneTimeSlotPair>();

            for (int i = 0; i < timeSlotCount; i++)
            {
                for (int j = 0; j < laneCount; j++)
                {
                    current = internalState[i, j];
                    if (current == 0)
                    {
                        continue;
                    }
                    var pair = new ReservationLaneTimeSlotPair()
                    {
                        LaneId = j+1,
                        TimeSlotId = i+1,
                        ReservationId = current
                    };

                    pairs.Add(pair);
                }
            }

            // load all reservations besides -1 by first gettting the distinct list of
            // ids, then loading these from db and converting to a dictionary
            // then finally clearing all lane and timeslots from these
            var distinctReservations = (from y in pairs
                                            where y.ReservationId != -1
                                            select y.ReservationId).Distinct<int>().ToList();
            var distinctTimeSlots = (from y in pairs
                                     select y.TimeSlotId).Distinct<int>().ToList();
            var distinctLanes = (from y in pairs
                                 select y.LaneId).Distinct<int>().ToList();

            var reservations = (from y in reservationRepos.GetAll()
                                where distinctReservations.Contains(y.Id)
                                select y).ToDictionary(t => t.Id, t => t);

            var timeslots = (from y in timeSlotRepos.GetAll()
                             where distinctTimeSlots.Contains(y.Id)
                             select y).ToDictionary(t => t.Id, t => t);

            var lanes = (from y in laneRepos.GetAll()
                         where distinctLanes.Contains(y.Id)
                         select y).ToDictionary(t => t.Id, t => t);

            foreach (var r in reservations)
            {
                r.Value.Lanes.Clear();
                r.Value.TimeSlots.Clear();
            }

            // now we can reschedule all of the reservations, and add the lanes and timeslots
            // to the new reservation as well
            foreach (var pair in pairs)
            {
                if (pair.ReservationId == -1)
                {
                    newReservation.AddLane(lanes[pair.LaneId]);
                    newReservation.AddTimeSlot(timeslots[pair.TimeSlotId]);
                    continue;
                }

                reservations[pair.ReservationId].AddLane(lanes[pair.LaneId]);
                reservations[pair.ReservationId].AddTimeSlot(timeslots[pair.TimeSlotId]);

            }

            var toReturn = new List<Reservation>();
            foreach(var r in reservations)
            {
                toReturn.Add(r.Value);
            }
            distinctLanes = null;
            distinctReservations = null;
            distinctTimeSlots = null;

            return toReturn;
        }
        public void TestValidResrvationWithSomeOtherReservations()
        {
            var reservation = new Reservation()
            {
                CreatedAt = DateTime.Now,
                Name = "Gert",
                NumberOfPlayers = 4,
                PhoneNumber = 1234,
                PlayAt =DateTime.Now
            };

            reservation.AddLane((from y in this.lanes select y).First<Lane>());
            reservation.AddTimeSlot((from y in this.timeSlots select y).First<TimeSlot>());

            this._session.Save(reservation);

            var service = new ReservationPossibleService();

            var request = new ReservationPossible()
            {
                Reservation = new ReservationType()
                {
                    HowManyHours = 2,
                    NumberOfPlayers = 8,
                    PlayAt = DateTime.Now,
                    TimeOfDay = (from y in this.timeSlots select y).First<TimeSlot>().Start
                }
            };

            ReservationPossibleResponse response = service.OnPost(request) as ReservationPossibleResponse;
            Assert.That(response.IsPossible, Is.True);
        }