Exemplo n.º 1
0
        public void TestCancelMultipleinARowAndBookAppointShouldGetTheSmallestDateInTheCancelledSet()
        {
            const uint appointmentBookSize = 24;

            var a   = new AppointmentMap(DateTime.Parse("12/7/2017"), appointmentBookSize);
            var po  = new PrivateObject(a);
            var map = (byte[])po.GetField("_availabilityMap");

            Assert.IsTrue(map.Length == appointmentBookSize);
            Assert.IsTrue((DateTime)po.GetField("_referenceDate") == DateTime.Parse("12/4/2017"));

            var firstAppointmentDate = DateTime.Now.Date;

            Dictionary <int, DateTime> allocatedDates = new Dictionary <int, DateTime>();

            DateTime firstAllocationExpectedDate = GetExpectedReservationDate();
            DateTime referenceDate = firstAllocationExpectedDate;

            for (var i = 0; i < 100; i++)
            {
                var result = a.ReserveFirstAvailableExcludeRequestedDate();
                Assert.IsTrue(result.Item1);

                Assert.IsTrue(result.Item2.Date == referenceDate);
                referenceDate = GetNextExpectedReservationDate(referenceDate);

                allocatedDates.Add(i, result.Item2.Date);
            }

            List <Tuple <int, DateTime> > cancelledList = new List <Tuple <int, DateTime> >();
            // Run Cancel/allocation loop multiple time...

            var random = new Random();

            for (int i = 0; i < 20; i++)
            {
                var j = random.Next(0, allocatedDates.Keys.Count);
                if (allocatedDates.ContainsKey(j))
                {
                    a.CancelAppointment(allocatedDates[j]);
                    cancelledList.Add(new Tuple <int, DateTime>(j, allocatedDates[j]));
                }
            }

            cancelledList.Sort();
            var r = a.ReserveFirstAvailableExcludeRequestedDate();

            Assert.IsTrue(r.Item1);
            Assert.IsTrue(r.Item2.Date == cancelledList[0].Item2);
        }
Exemplo n.º 2
0
        public void TestRangeQueryWhereAppointmentHasHolesinReservedSpots()
        {
            const uint appointmentBookSize = 24;

            var a = new AppointmentMap(DateTime.Parse("03/1/2018"), appointmentBookSize);

            Dictionary <int, DateTime> allocatedDates = new Dictionary <int, DateTime>();

            for (var i = 0; i < 100; i++)
            {
                var result = a.ReserveFirstAvailableExcludeRequestedDate();
                Assert.IsTrue(result.Item1);
                allocatedDates.Add(i, result.Item2);
            }

            const int rangeSize = 10;

            var cancelledAppointments = new SortedSet <DateTime>();

            var random = new Random();

            for (int i = 0; i < rangeSize; i++)
            {
                var j = random.Next(0, allocatedDates.Count);
                if (allocatedDates.ContainsKey(j))
                {
                    a.CancelAppointment(allocatedDates[j]);
                    cancelledAppointments.Add(allocatedDates[j]);
                }
            }

            var tempList = cancelledAppointments.ToList();


            var availableAppointmentRange = a.RetrieveFirstAvailableDateRangeExcludeRequestedDate(rangeSize);

            for (int i = 0; i < Math.Min(availableAppointmentRange.Count, tempList.Count); i++)
            {
                Assert.IsTrue(tempList[i] == availableAppointmentRange[i],
                              string.Format("failed Comarison for {0}: {1}, {2}",
                                            i, tempList[i], availableAppointmentRange[i]));
            }
        }
Exemplo n.º 3
0
        public void TestBookMultipleAppointmentsInTheFuture_Cancel_One_And_BookAgainShouldReturnTheCancelledOne()
        {
            const uint appointmentBookSize = 24;

            var a   = new AppointmentMap(DateTime.Parse("12/7/2017"), appointmentBookSize);
            var po  = new PrivateObject(a);
            var map = (byte[])po.GetField("_availabilityMap");

            Assert.IsTrue(map.Length == appointmentBookSize);
            Assert.IsTrue((DateTime)po.GetField("_referenceDate") == DateTime.Parse("12/4/2017"));

            var firstAppointmentDate = DateTime.Now.Date;

            Dictionary <int, DateTime> allocatedDates = new Dictionary <int, DateTime>();

            DateTime firstAllocationExpectedDate = GetExpectedReservationDate();
            DateTime referenceDate = firstAllocationExpectedDate;

            for (var i = 0; i < 100; i++)
            {
                var result = a.ReserveFirstAvailableExcludeRequestedDate();
                Assert.IsTrue(result.Item1);
                Assert.IsTrue(result.Item2.Date == referenceDate);
                referenceDate = GetNextExpectedReservationDate(referenceDate);

                allocatedDates.Add(i, result.Item2.Date);
            }


            // Run Cancel/allocation loop multiple time...
            for (int i = 0; i < 10; i++)
            {
                var j = new Random().Next(0, allocatedDates.Keys.Count);
                if (allocatedDates.ContainsKey(j))
                {
                    a.CancelAppointment(allocatedDates[j]);
                    var result = a.ReserveFirstAvailableExcludeRequestedDate();

                    Assert.IsTrue(result.Item1);
                    Assert.IsTrue(result.Item2.Date == allocatedDates[j]);
                }
            }
        }