Ejemplo n.º 1
0
        public void TryAcceptReturnsNothingOnInsufficientCapacity(
            Reservation reservation,
            Reservation[] reservations,
            MaîtreD sut)
        {
            var reservedSeats = reservations.Sum(r => r.Quantity);

            sut = sut.WithCapacity(reservedSeats + reservation.Quantity - 1);

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

            Assert.True(actual.IsNothing);
            Assert.False(reservation.IsAccepted);
        }
        public void TryAcceptReturnsNullOnReservationInThePast(
            Reservation reservation,
            IReadOnlyCollection <Reservation> reservations,
            int id,
            MaîtreD sut)
        {
            reservation.IsAccepted = false;

            var actual = sut.TryAccept(reservation);

            Assert.True(
                actual.Accept(new StubReservationsVisitor <IMaybe <int> >(false, reservations, id)).IsNothing());
            Assert.False(reservation.IsAccepted);
        }
        public void TryAcceptReturnsNullOnReservationInThePast(
            Reservation reservation,
            IReadOnlyCollection <Reservation> reservations,
            int id,
            MaîtreD sut)
        {
            reservation.IsAccepted = false;

            var actual = sut.TryAccept(reservation);

            Assert.Null(
                actual.Run(new StubReservationsHandler(false, reservations, id)).Result);
            Assert.False(reservation.IsAccepted);
        }
Ejemplo n.º 4
0
        public void TryAcceptReturnsReservationInHappyPathScenario(
            Reservation reservation,
            Reservation[] reservations,
            MaîtreD sut,
            int excessCapacity)
        {
            var reservedSeats = reservations.Sum(r => r.Quantity);

            sut = sut.WithCapacity(
                reservedSeats + reservation.Quantity + excessCapacity);

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

            Assert.Equal(new Maybe <Reservation>(reservation.Accept()), actual);
        }
        public void TryAcceptReturnsNullOnInsufficientCapacity(
            Reservation reservation,
            IReadOnlyCollection <Reservation> reservations,
            int id,
            MaîtreD sut)
        {
            reservation.IsAccepted = false;
            var reservedSeats = reservations.Sum(r => r.Quantity);

            sut = sut.WithCapacity(reservedSeats + reservation.Quantity - 1);

            var actual = sut.TryAccept(reservation);

            Assert.True(
                actual.Accept(new StubReservationsVisitor <IMaybe <int> >(true, reservations, id)).IsNothing());
            Assert.False(reservation.IsAccepted);
        }
        public void TryAcceptReturnsNullOnInsufficientCapacity(
            Reservation reservation,
            IReadOnlyCollection <Reservation> reservations,
            int id,
            MaîtreD sut)
        {
            reservation.IsAccepted = false;
            var reservedSeats = reservations.Sum(r => r.Quantity);

            sut = sut.WithCapacity(reservedSeats + reservation.Quantity - 1);

            var actual = sut.TryAccept(reservation);

            Assert.Null(
                actual.Run(new StubReservationsHandler(true, reservations, id)).Result);
            Assert.False(reservation.IsAccepted);
        }
Ejemplo n.º 7
0
        public void UsageExample()
        {
            var connectionString = ConnectionStrings.Reservations;
            var maîtreD          = new MaîtreD(10);

            var reservation = new Reservation
            {
                Date     = DateTimeOffset.Now.AddDays(27),
                Name     = "Mark Seemann",
                Email    = "*****@*****.**",
                Quantity = 2
            };
            var p  = maîtreD.TryAccept(reservation);
            var id = p.Accept(new SqlReservationsProgramVisitor <int?>(connectionString));

            Assert.NotNull(id);
            Assert.NotEqual(default(int), id);
        }
Ejemplo n.º 8
0
        public void TryAcceptReturnsReservationIdInHappyPathScenario()
        {
            //Arrange
            Reservation reservation = new Reservation {
                Quantity = 10
            };
            var expected = 1;
            var repo     = new Mock <IReservationsRepository>();

            repo.Setup(r => r.ReadReservations(It.IsAny <DateTime>())).Returns(Enumerable.Empty <Reservation>());
            repo.Setup(r => r.Create(reservation)).Returns(expected);
            MaîtreD sut = new MaîtreD(20, repo.Object);

            //Act
            var actual = sut.TryAccept(reservation);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void TryAcceptReturnsReservationIdInHappyPathScenario(
            Reservation reservation,
            IReadOnlyCollection <Reservation> reservations,
            MaîtreD sut,
            int excessCapacity,
            int expected)
        {
            var reservedSeats = reservations.Sum(r => r.Quantity);

            reservation.IsAccepted = false;
            sut = sut.WithCapacity(
                reservedSeats + reservation.Quantity + excessCapacity);

            var actual = sut.TryAccept(reservation);

            Assert.Equal(
                new Just <int>(expected),
                actual.Accept(new StubReservationsVisitor <IMaybe <int> >(true, reservations, expected)));
            Assert.True(reservation.IsAccepted);
        }
Ejemplo n.º 10
0
        public void TryAcceptOnInsufficientCapacity()
        {
            Reservation reservation = new Reservation {
                Quantity = 21
            };
            var id   = 1;
            var repo = new Mock <IReservationsRepository>();

            repo.Setup(r => r.ReadReservations(It.IsAny <DateTime>())).Returns(Enumerable.Empty <Reservation>());
            repo.Setup(r => r.Create(reservation)).Returns(id);
            MaîtreD sut = new MaîtreD(20, repo.Object);

            int?expected = null;

            //Act
            var actual = sut.TryAccept(reservation);

            //Assert
            Assert.Equal(expected, actual);
        }