コード例 #1
0
        public void Post_BookTicket_ShouldRedirectToSearchWhenBusIsAlreadyReserved()
        {
            //Arrange
            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            this.ticketService.Setup(t => t.GetAlreadyReservedTickets(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
            });

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new RoutesController(null, routeService.Object, ticketService.Object, companyService.Object, null);

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            //Act
            var form   = this.GenerateBookTicketForm();
            var result = controller.BookTicket(form);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            result.As <RedirectToActionResult>().ActionName.Should().Be(nameof(RoutesController.Search), WebConstants.Controller.Routes);
            result.As <RedirectToActionResult>().RouteValues[RouteValueStartTownKey].Should().Be(form.StartTownId);
            result.As <RedirectToActionResult>().RouteValues[RouteValueEndTownKey].Should().Be(form.EndTownId);
            result.As <RedirectToActionResult>().RouteValues[RouteValueDateKey].Should().Be(form.DepartureDateTime.Date);
            result.As <RedirectToActionResult>().RouteValues[RouteValueCompanyIdKey].Should().Be(form.CompanyId);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.RouteSoldOut, form.StartStation, form.EndStation, form.DepartureDateTime.Date.ToYearMonthDayFormat(), form.DepartureDateTime.TimeOfDay));
        }
コード例 #2
0
        public void Post_BookTicket_ShouldRedirectToHomeWithPastData()
        {
            //Arrange
            var departureTime     = new TimeSpan(10, 11, 12);
            var date              = new DateTime(2017, 11, 11);
            var departureDateTime = new DateTime(date.Year, date.Month, date.Day, departureTime.Hours, departureTime.Minutes, departureTime.Seconds);

            routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            var controller = new RoutesController(null, routeService.Object, null, null, null);

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            //Act
            var result = controller.BookTicket(new BookTicketFormModel()
            {
                DepartureDateTime = departureDateTime
            });

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            result.As <RedirectToActionResult>().ActionName.Should().Be(nameof(HomeController.Index), WebConstants.Controller.Home);
            this.customMessage.Should().Be(WebConstants.Message.InvalidRoute);
        }
コード例 #3
0
        public void Post_BookTicket_ShouldRedirectToHomeAfterSuccessfullReservation()
        {
            //Arrange
            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            this.routeService.Setup(r => r.GetRouteTicketBookingInfo(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new RouteBookTicketInfoServiceModel()
            {
                BusType = BusType.Mini, ReservedTickets = new List <int>()
            });

            this.ticketService.Setup(t => t.GetAlreadyReservedTickets(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new List <int>()
            {
                1, 2, 3, 4
            });

            this.ticketService.Setup(t => t.Add(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <IEnumerable <int> >(), It.IsAny <string>()))
            .Returns(true);

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new RoutesController(null, this.routeService.Object, this.ticketService.Object, this.companyService.Object, this.userManager.Object);

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            //Act
            var form = this.GenerateBookTicketForm();

            form.Seats.FirstOrDefault(s => s.Value == 10).Checked = true;
            form.Seats.FirstOrDefault(s => s.Value == 11).Checked = true;

            var reservedTickets = new List <int>()
            {
                10, 11
            };

            var result = controller.BookTicket(form);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.Index);
            model.ControllerName.Should().Be(WebConstants.Controller.Home);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.SuccessfullyTicketReservation, string.Join(", ", reservedTickets), form.StartStation, form.EndStation, form.DepartureDateTime));
        }
コード例 #4
0
        public void Post_BookTicket_ShouldReturnBusSchemaWhenSomeOfTheSelectedSeatsAreAlreadyReserved()
        {
            //Arrange
            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            this.routeService.Setup(r => r.GetRouteTicketBookingInfo(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new RouteBookTicketInfoServiceModel()
            {
                BusType = BusType.Mini, ReservedTickets = new List <int>()
            });

            this.ticketService.Setup(t => t.GetAlreadyReservedTickets(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new List <int>()
            {
                1, 2, 3, 4
            });

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new RoutesController(null, this.routeService.Object, this.ticketService.Object, this.companyService.Object, this.userManager.Object);

            controller.ModelState.AddModelError(string.Empty, "Error");

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            var matchingSeats = new List <int>()
            {
                1, 2
            };

            //Act
            var form   = this.GenerateBookTicketForm();
            var result = controller.BookTicket(form);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <BookTicketFormModel>();
        }
コード例 #5
0
        public void Post_BookTicket_ShouldRedirectToHomeWithNonExistingRoute()
        {
            //Arrange
            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(false);

            var controller = new RoutesController(null, routeService.Object, null, null, null);

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            //Act
            var result = controller.BookTicket(new BookTicketFormModel());

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            result.As <RedirectToActionResult>().ActionName.Should().Be(nameof(HomeController.Index), WebConstants.Controller.Home);
            this.customMessage.Should().Be(WebConstants.Message.InvalidRoute);
        }
コード例 #6
0
        public void Post_BookTicket_ShouldRedirectToHomeWithInvalidData()
        {
            //Arrange
            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            this.routeService.Setup(r => r.GetRouteTicketBookingInfo(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new RouteBookTicketInfoServiceModel()
            {
                BusType = BusType.Mini, ReservedTickets = new List <int>()
            });

            this.ticketService.Setup(t => t.GetAlreadyReservedTickets(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(new List <int>()
            {
                1, 2, 3, 4
            });

            this.ticketService.Setup(t => t.Add(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <IEnumerable <int> >(), It.IsAny <string>()))
            .Returns(false);

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new RoutesController(null, this.routeService.Object, this.ticketService.Object, this.companyService.Object, this.userManager.Object);

            this.PrepareTempData();
            this.SetControllerTempData(controller);

            //Act
            var form   = this.GenerateBookTicketForm();
            var result = controller.BookTicket(form);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.Index);
            model.ControllerName.Should().Be(WebConstants.Controller.Home);
            this.customMessage.Should().Be(WebConstants.Message.InvalidRoute);
        }
コード例 #7
0
        public void Get_BookTicket_ShouldReturnBusSchemaWithValidData()
        {
            //Arrange
            var departureTime     = new TimeSpan(23, 10, 10);
            var date              = DateTime.UtcNow.ToLocalTime().Date;
            var departureDateTime = new DateTime(date.Year, date.Month, date.Day, departureTime.Hours, departureTime.Minutes, departureTime.Seconds);

            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            this.routeService.Setup(r => r.GetRouteTicketBookingInfo(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(this.GetRouteInfo());

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(true);

            var controller = new RoutesController(null, routeService.Object, null, companyService.Object, null);

            //Act
            var result = controller.BookTicket(RouteId, departureTime, date, CompanyId);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <BookTicketFormModel>();
            var form = model.As <BookTicketFormModel>();

            form.BusSeats.Should().Be(20);
            form.RouteId.Should().Be(RouteId);
            form.StartStation.Should().Be("Albena");
            form.EndStation.Should().Be("Balchik");
            form.StartTownId.Should().Be(1);
            form.EndTownId.Should().Be(2);
            form.CompanyName.Should().Be("Azimut");
            form.DepartureDateTime.Should().Be(departureDateTime);
            form.Duration.Should().Be(new TimeSpan(23, 10, 10));
            form.CompanyId.Should().Be(CompanyId);
        }
コード例 #8
0
        public void Post_BookTicket_ShouldReturnViewForInvalidModel()
        {
            //Arrange
            var departureTime     = new TimeSpan(23, 10, 10);
            var date              = DateTime.UtcNow.ToLocalTime().Date;
            var departureDateTime = new DateTime(date.Year, date.Month, date.Day, departureTime.Hours, departureTime.Minutes, departureTime.Seconds);

            this.routeService.Setup(r => r.GetRouteTicketBookingInfo(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(this.GetRouteInfo());

            var controller = new RoutesController(null, routeService.Object, null, null, null);

            controller.ModelState.AddModelError(string.Empty, "Error");

            //Act
            var result = controller.BookTicket(new BookTicketFormModel());

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <BookTicketFormModel>();
        }
コード例 #9
0
        public void Get_BookTicket_ShouldRedirectToHomeWithInvalidDate()
        {
            //Arrange
            var departureTime = new TimeSpan(0, 0, 0);
            var date          = new DateTime(2017, 11, 11);

            this.routeService.Setup(r => r.RouteExists(It.IsAny <int>(), It.IsAny <TimeSpan>()))
            .Returns(true);

            var controller = new RoutesController(null, routeService.Object, null, null, null);

            this.PrepareTempData();

            this.SetControllerTempData(controller);

            //Act
            var result = controller.BookTicket(StartTownId, departureTime, date, CompanyId);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            result.As <RedirectToActionResult>().ActionName.Should().Be(nameof(HomeController.Index));
            result.As <RedirectToActionResult>().ControllerName.Should().Be(WebConstants.Controller.Home);
            this.customMessage.Should().Be(WebConstants.Message.InvalidRoute);
        }