public async Task ReservationFails()
        {
            var repo = new FakeReservationsRepository();
            var sut  = new ReservationsController(10, repo);

            var reservation = new Reservation(
                date: new DateTimeOffset(2018, 8, 13, 16, 53, 0, TimeSpan.FromHours(2)),
                email: "*****@*****.**",
                name: "Mark Seemann",
                quantity: 11);
            var actual = await sut.Post(reservation);

            Assert.False(reservation.IsAccepted);
            Assert.False(repo.Contains(reservation));
            Assert.IsAssignableFrom <InternalServerErrorActionResult>(actual);
        }
        public async Task ReservationSucceeds()
        {
            var repo = new FakeReservationsRepository();
            var sut  = new ReservationsController(10, repo);

            var reservation = new Reservation(
                date: new DateTimeOffset(2018, 8, 13, 16, 53, 0, TimeSpan.FromHours(2)),
                email: "*****@*****.**",
                name: "Mark Seemann",
                quantity: 4);
            var actual = await sut.Post(reservation);

            Assert.True(repo.Contains(reservation.Accept()));
            var expectedId = repo.GetId(reservation.Accept());
            var ok         = Assert.IsAssignableFrom <OkActionResult>(actual);

            Assert.Equal(expectedId, ok.Value);
        }
示例#3
0
        public void PostValidDtoWhenNoPriorReservationsExist(
            NonNegativeInt capacitySurplus,
            PositiveInt quantity)
        {
            var repository = new FakeReservationsRepository();
            var capacity   = capacitySurplus.Item + quantity.Item;
            var sut        = new ReservationsController(repository, capacity);

            var dto = new ReservationDto
            {
                Date     = "2019-08-20",
                Quantity = quantity.Item
            };
            var actual = sut.Post(dto);

            Assert.IsAssignableFrom <OkObjectResult>(actual);
            Assert.NotEmpty(repository);
        }
示例#4
0
        public void PostValidDtoWhenSoldOut(
            PositiveInt capacity,
            PositiveInt excessQuantity)
        {
            var repository = new FakeReservationsRepository();
            var quantity   = capacity.Item + excessQuantity.Item;
            var sut        = new ReservationsController(repository, capacity.Item);

            var dto = new ReservationDto
            {
                Date     = "2019-08-20",
                Quantity = quantity
            };
            var actual = sut.Post(dto);

            var c = Assert.IsAssignableFrom <ObjectResult>(actual);

            Assert.Equal(StatusCodes.Status500InternalServerError, c.StatusCode);
        }
        public void PostValidDtoWhenSoldOut(int capacity, int quantity)
        {
            var repository = new FakeReservationsRepository();
            var now        = new DateTime(2019, 9, 27);
            var sut        = new ReservationsController(
                TimeSpan.FromHours(2.5),
                new[] { new Table(capacity) },
                repository,
                new ConstantClock(now));

            var dto = new ReservationDto
            {
                Date     = now.AddDays(2).ToString(),
                Quantity = quantity
            };
            var actual = sut.Post(dto);

            var c = Assert.IsAssignableFrom <ObjectResult>(actual);

            Assert.Equal(StatusCodes.Status500InternalServerError, c.StatusCode);
        }
        public void PostValidDtoWhenNoPriorReservationsExist(
            int capacity,
            int quantity)
        {
            var repository = new FakeReservationsRepository();
            var now        = new DateTime(2019, 9, 24);
            var sut        = new ReservationsController(
                TimeSpan.FromHours(2.5),
                new[] { new Table(capacity) },
                repository,
                new ConstantClock(now));

            var dto = new ReservationDto
            {
                Date     = now.AddDays(1).ToString(),
                Quantity = quantity
            };
            var actual = sut.Post(dto);

            Assert.IsAssignableFrom <OkResult>(actual);
            Assert.NotEmpty(repository);
        }
        public void PostPastReservationWhenNoPriorReservationsExist(
            int capacity,
            int quantity)
        {
            var repository = new FakeReservationsRepository();
            var now        = new DateTime(2019, 8, 21);
            var sut        = new ReservationsController(
                TimeSpan.FromHours(2.5),
                new[] { new Table(capacity) },
                repository,
                new ConstantClock(now));

            var dto = new ReservationDto
            {
                Date     = now.Subtract(TimeSpan.FromDays(1)).ToString(),
                Quantity = quantity
            };
            var actual = sut.Post(dto);

            var br  = Assert.IsAssignableFrom <BadRequestObjectResult>(actual);
            var msg = Assert.IsAssignableFrom <string>(br.Value);

            Assert.NotEmpty(msg);
        }