Example #1
0
        public async Task CreateAsync_ShouldSuccessfullyAddToDatabase()
        {
            // Arrange
            var context       = ApplicationDbContextInMemoryFactory.InitializeContext();
            var busRepository = new EfDeletableEntityRepository <Bus>(context);

            var service    = new BusesService(busRepository);
            var inputModel = new BusInputModel();

            inputModel.BusNumber         = "BusNumber";
            inputModel.AvailableSeats    = 20;
            inputModel.PricePerPerson    = 50;
            inputModel.ReservationType   = ReservationType.Bus;
            inputModel.StartPointId      = 1;
            inputModel.StartPointStation = "StartStation";
            inputModel.EndPointId        = 2;
            inputModel.EndPointStation   = "EndStation";
            inputModel.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            inputModel.TravellingTime    = new TimeSpan(30, 30, 00);

            var expectedResult = 1;

            // Act
            await service.CreateAsync(inputModel);

            var actualResult = busRepository.All().Count();

            // Assert
            Assert.True(expectedResult == actualResult);
        }
Example #2
0
        public IActionResult Create()
        {
            this.ViewData["EndPointId"]   = new SelectList(this.destinationsService.GetAll(), "Id", "Town");
            this.ViewData["StartPointId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town");

            var inputModel = new BusInputModel();

            return(this.View(inputModel));
        }
Example #3
0
        public async Task <IActionResult> Create(BusInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["EndPointId"]   = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.EndPointId);
                this.ViewData["StartPointId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.StartPointId);
                return(this.View(inputModel));
            }

            await this.busesService.CreateAsync(inputModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Example #4
0
        public async Task CreateAsync(BusInputModel inputModel)
        {
            var bus = new Bus
            {
                BusNumber         = inputModel.BusNumber,
                PricePerPerson    = inputModel.PricePerPerson,
                DepartureDateTime = inputModel.DepartureDateTime,
                TravellingTime    = inputModel.TravellingTime,
                AvailableSeats    = inputModel.AvailableSeats,
                StartPointId      = inputModel.StartPointId,
                StartPointStation = inputModel.StartPointStation,
                EndPointId        = inputModel.EndPointId,
                EndPointStation   = inputModel.EndPointStation,
                ReservationType   = inputModel.ReservationType,
            };

            await this.busesRepository.AddAsync(bus);

            await this.busesRepository.SaveChangesAsync();
        }