Exemplo n.º 1
0
        public void GetBookingsShould_ReturnViewWithCorrectModel_WhenPassedIdIsNotNull()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            var placeId = Guid.NewGuid();
            var booking = new Booking()
            {
                PlaceId = placeId
            };
            var model = new List <Booking>()
            {
                booking
            };

            bookingsServiceMock.Setup(s => s.GetBookingsOfPlace(placeId)).Returns(model.AsQueryable());

            controller
            .WithCallTo(c => c.GetBookings(placeId.ToString()))
            .ShouldRenderPartialView("_PlaceBookings");
        }
Exemplo n.º 2
0
        public void BookTablesShould_ReturnViewWithCorrectModel_WhenPassedDataIsNotNull()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);
            var bookingId  = Guid.NewGuid();
            var placeId    = Guid.NewGuid();
            var consumable = new Consumable();
            var list       = new List <Consumable>()
            {
                consumable
            };

            consumableServiceMock.Setup(s => s.GetAllConsumablesOf(placeId)).Returns(list.AsQueryable());
            var model = new OrderFormViewModel()
            {
                BookingId = bookingId, PlaceMenu = list
            };

            factoryMock.Setup(f => f.CreateOrderFormViewModel(bookingId, list)).Returns(model);

            controller
            .WithCallTo(c => c.Order(placeId, bookingId))
            .ShouldRenderDefaultView()
            .WithModel(model);
        }
Exemplo n.º 3
0
        public void GetBookingFormShould_ReturnLoginMessageView_WhenUserIsNotAuthenticated()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            var placeId = Guid.NewGuid();
            var model   = new BookingViewModel()
            {
                PlaceId = placeId
            };

            factoryMock.Setup(f => f.CreateBookingFormViewModel(placeId)).Returns(model);
            authProviderMock.Setup(ap => ap.IsAuthenticated).Returns(false);

            controller.WithCallTo(c => c.GetBookingForm(placeId))
            .ShouldRenderPartialView("_LoginMessage");
        }
Exemplo n.º 4
0
        public void BookTablesShould_ReturnSameView_WhenModelIsNotValid()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            controller.ModelState.AddModelError("key", "message");

            var model = new BookingFormViewModel()
            {
                DateTime = DateTime.Now, PlaceId = Guid.NewGuid()
            };

            controller
            .WithCallTo(c => c.BookTables(model))
            .ShouldRenderPartialView("_AvailableTables")
            .WithModel(model);
        }
Exemplo n.º 5
0
        public void GetAvailableTablesShould_ReturnViewWithCorrectModel_WhenModelIsValid(int peoplePerTable)
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            var model = new BookingViewModel()
            {
                DateTime = DateTime.Now, PlaceId = Guid.NewGuid()
            };
            var booking = new Booking()
            {
                Id = Guid.NewGuid()
            };
            var list = new List <Booking>()
            {
                booking
            };
            var table = new Table()
            {
                Id = Guid.NewGuid(), NumberOfPeople = peoplePerTable
            };
            var bookedTable = new BookedTables()
            {
                BookingId = booking.Id, TableId = table.Id, Table = table, TablesCount = 3
            };

            bookingsServiceMock.Setup(s => s.FindAllOn(model.DateTime, model.PlaceId)).Returns(list.AsQueryable());
            bookedTableServiceMock.Setup(s => s.GetBookedTable(booking.Id)).Returns(bookedTable);
            tableServiceMock.Setup(s => s.GetTablesCount(model.PlaceId, peoplePerTable)).Returns(10);
            var returnModel = new BookingFormViewModel()
            {
                TwoPeopleTablesCount  = 7,
                FourPeopleTablesCount = 0,
                SixPeopleTablesCount  = 0,
                DateTime = model.DateTime,
                PlaceId  = model.PlaceId
            };

            factoryMock.Setup(f => f.CreateBookingFormViewModel(7, 0, 0, model.PlaceId, model.DateTime)).Returns(returnModel);

            controller
            .WithCallTo(c => c.GetAvailableTables(model))
            .ShouldRenderPartialView("_AvailableTables")
            .WithModel(returnModel);
        }
Exemplo n.º 6
0
        public void CancelBookingShould_ReturnErrorView_WhenPassedIdIsNull()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            controller
            .WithCallTo(c => c.CancelBooking(null))
            .ShouldRenderView("Error");
        }
Exemplo n.º 7
0
        public void CancelBookingShould_ReturnJson_WhenPassedIdIsNotNull()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);
            var bookingId = Guid.NewGuid();

            controller
            .WithCallTo(c => c.CancelBooking(bookingId))
            .ShouldReturnEmptyResult();
        }
Exemplo n.º 8
0
        public void BookTablesShould_ReturnViewWithCorrectModel_WhenModelIsValid()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            var model = new BookingFormViewModel()
            {
                DateTime        = DateTime.Now,
                PlaceId         = Guid.NewGuid(),
                TwoPeopleInput  = 1,
                FourPeopleInput = 0,
                SixPeopleInput  = 0
            };
            var userId = Guid.NewGuid().ToString();

            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            var booking = new Booking()
            {
                Id = Guid.NewGuid()
            };

            bookingsServiceMock.Setup(s => s.CreateBooking(model.PlaceId, userId, model.DateTime, 2)).Returns(booking);
            var table = new Table()
            {
                Id = Guid.NewGuid()
            };

            tableServiceMock.Setup(s => s.GetByPlaceAndNumberOfPeople(model.PlaceId, 2)).Returns(table);

            controller
            .WithCallTo(c => c.BookTables(model))
            .ShouldRenderPartialView("_SuccessfullBooking")
            .WithModel(model);
        }
Exemplo n.º 9
0
        public void PostOrderShould_ReturnSameView_WhenModelIsNotValid()
        {
            var bookingsServiceMock    = new Mock <IBookingService>();
            var placeServiceMock       = new Mock <IPlaceService>();
            var consumableServiceMock  = new Mock <IConsumableService>();
            var tableServiceMock       = new Mock <ITablesService>();
            var bookedTableServiceMock = new Mock <IBookedTablesService>();
            var authProviderMock       = new Mock <IAuthenticationProvider>();
            var factoryMock            = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.BookingsController(authProviderMock.Object, placeServiceMock.Object,
                                                                    bookingsServiceMock.Object, factoryMock.Object, consumableServiceMock.Object,
                                                                    bookedTableServiceMock.Object, tableServiceMock.Object);

            controller.ModelState.AddModelError("key", "message");

            var model = new OrderFormViewModel();

            controller
            .WithCallTo(c => c.Order(model))
            .ShouldRenderDefaultView()
            .WithModel(model);
        }