Esempio n. 1
0
        public void AcceptWhenOtherReservationsEndBeforeReservationStarts(
            double seatingDuration,
            int[] seats,
            int[] reservations,
            int quantity)
        {
            var dt          = new DateTime(2019, 11, 22, 18, 30, 0);
            var reservation = new Reservation
            {
                Date     = dt,
                Quantity = quantity
            };
            var sut = new MaîtreD(
                TimeSpan.FromMinutes(seatingDuration),
                seats.Select(s => new Table(s)).ToArray());

            var actual = sut.CanAccept(
                reservations.Select(x =>
                                    new Reservation
            {
                Date     = dt.Subtract(TimeSpan.FromMinutes(seatingDuration)),
                Quantity = x
            }).ToArray(),
                reservation);

            Assert.True(actual);
        }
Esempio n. 2
0
        public void CanAcceptReturnsCorrectResult(
            int[] seats,
            int[] reservations,
            int quantity,
            bool expected)
        {
            var dt          = new DateTime(2019, 11, 21);
            var reservation = new Reservation
            {
                Date     = dt,
                Quantity = quantity
            };
            var sut = new MaîtreD(
                TimeSpan.FromHours(2),
                seats.Select(s => new Table(s)).ToArray());

            var actual = sut.CanAccept(
                reservations
                .Select(x => new Reservation {
                Date = dt, Quantity = x
            })
                .ToList(),
                reservation);

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void AcceptWhenTableIsAvailable(int quantity)
        {
            var reservation = new Reservation
            {
                Date     = new DateTime(2019, 11, 20),
                Quantity = quantity
            };
            var sut = new MaîtreD(TimeSpan.FromHours(2), new Table(quantity));

            var actual = sut.CanAccept(new Reservation[0], reservation);

            Assert.True(actual);
        }
Esempio n. 4
0
        public void RejectWhenRestaurantHasNoTables(int quantity)
        {
            var reservation = new Reservation
            {
                Date     = new DateTime(2019, 11, 21),
                Quantity = quantity
            };
            var sut = new MaîtreD(TimeSpan.FromHours(2));

            var actual = sut.CanAccept(new Reservation[0], reservation);

            Assert.False(actual);
        }
Esempio n. 5
0
        public void RejectAnyReservationLargerThanTheBiggestTable(int[] seats)
        {
            var dt           = new DateTime(2019, 10, 10);
            var biggestTable = seats.Max();
            var reservation  = new Reservation
            {
                Date     = dt,
                Quantity = biggestTable + 1
            };
            var sut = new MaîtreD(
                TimeSpan.FromHours(2),
                seats.Select(s => new Table(s)).ToArray());

            var actual = sut.CanAccept(new Reservation[0], reservation);

            Assert.False(actual);
        }
Esempio n. 6
0
        public void RejectReservationOverTotalCapacity(int[] seats)
        {
            var dt          = new DateTime(2017, 3, 8);
            var capacity    = seats.Sum();
            var reservation = new Reservation
            {
                Date     = dt,
                Quantity = capacity + 1
            };
            var sut = new MaîtreD(
                TimeSpan.FromHours(2),
                seats.Select(s => new Table(s)).ToArray());

            var actual = sut.CanAccept(new Reservation[0], reservation);

            Assert.False(actual);
        }
Esempio n. 7
0
        public void RejectReservationWhenTableIsAlreadyTaken(int quantity)
        {
            var dt          = new DateTime(2019, 10, 3);
            var reservation = new Reservation
            {
                Date     = dt,
                Quantity = quantity
            };
            var sut = new MaîtreD(TimeSpan.FromHours(2), new Table(quantity));

            var actual = sut.CanAccept(
                new[] { new Reservation {
                            Date = dt, Quantity = quantity
                        } },
                reservation);

            Assert.False(actual);
        }
Esempio n. 8
0
        public void CanAcceptWhenCommunalTableHasEnoughCapacity(
            string date,
            int quantity,
            int capacity)
        {
            var reservation = new Reservation
            {
                Date     = DateTime.Parse(date),
                Quantity = quantity
            };
            var sut = new MaîtreD(
                TimeSpan.FromHours(2),
                new Table(capacity));

            var actual = sut.CanAccept(new Reservation[0], reservation);

            Assert.True(actual);
        }
Esempio n. 9
0
        public void CanNotAcceptWhenCommunalTableHasInsufficientCapacity(
            int quantity,
            int capacity)
        {
            DateTime dt          = new DateTime(2018, 8, 30);
            var      reservation = new Reservation
            {
                Date     = dt,
                Quantity = quantity
            };
            var sut = new MaîtreD(TimeSpan.FromHours(2), new Table(capacity));

            var actual = sut.CanAccept(
                new[] { new Reservation {
                            Date = dt, Quantity = 7
                        } },
                reservation);

            Assert.False(actual);
        }
Esempio n. 10
0
        public void RejectAnyReservationWhenSoldOut(int[] seats)
        {
            var dt          = new DateTime(2018, 3, 2);
            var reservation = new Reservation
            {
                Date     = dt,
                Quantity = 1
            };
            var sut = new MaîtreD(
                TimeSpan.FromHours(2),
                seats.Select(s => new Table(s)).ToArray());

            var actual = sut.CanAccept(
                seats.Select(s => new Reservation {
                Date = dt, Quantity = s
            }),
                reservation);

            Assert.False(actual);
        }
Esempio n. 11
0
        public Property CanAcceptReturnsReservationInHappyPathScenario()
        {
            return(Prop.ForAll((
                                   from rs in GenerateReservation.ListOf()
                                   from r in GenerateReservation
                                   from cs in Arb.Default.NonNegativeInt().Generator
                                   select(rs, r, cs.Item)).ToArbitrary(),
                               x =>
            {
                var(reservations, reservation, capacitySurplus) = x;
                var reservedSeats = reservations.Sum(r => r.Quantity);
                var capacity =
                    reservation.Quantity + reservedSeats + capacitySurplus;
                var sut = new MaîtreD(capacity);

                var actual = sut.CanAccept(reservations, reservation);

                Assert.True(actual);
            }));
        }
Esempio n. 12
0
        public Property CanAcceptOnInsufficientCapacity()
        {
            return(Prop.ForAll((
                                   from r in GenerateReservation
                                   from eq in Arb.Default.PositiveInt().Generator
                                   from cs in Arb.Default.NonNegativeInt().Generator
                                   from rs in GenerateReservation.ListOf()
                                   select(r, eq.Item, cs.Item, rs)).ToArbitrary(),
                               x =>
            {
                var(reservation, excessQuantity, capacitySurplus, reservations) = x;
                var reservedSeats = reservations.Sum(r => r.Quantity);
                var quantity = capacitySurplus + excessQuantity;
                var capacity = capacitySurplus + reservedSeats;
                reservation.Quantity = quantity;
                var sut = new MaîtreD(capacity);

                var actual = sut.CanAccept(reservations, reservation);

                Assert.False(actual);
            }));
        }