public void NewGuestHostReservation_Fail()
        {
            Guest newGuest = new Guest();

            newGuest.Id = _guestsRepo.GetNumberOfGuests() + 1;
            ActionResult <Guest> guestActionResult = _guestsController.CreateGuest(newGuest);

            Assert.IsTrue(guestActionResult.Result is CreatedAtRouteResult);

            HostCreateDto newHost = new HostCreateDto();

            newHost.Apartment                 = new ApartmentCreateDto();
            newHost.Apartment.Address         = new Address();
            newHost.Apartment.Address.Country = "Israel";
            newHost.Apartment.Address.City    = "Netanya";
            newHost.Apartment.Address.Street  = "Beeri";
            ActionResult <HostReadDto> hostActionResult = _hostsController.CreateHost(newHost);

            Assert.IsTrue(hostActionResult.Result is CreatedAtRouteResult);
            CreatedAtRouteResult hostReadDto = hostActionResult.Result as CreatedAtRouteResult;

            ReservationCreateDto newReservations = new ReservationCreateDto();

            newReservations.ArrivingDate       = new DateTime(2018, 08, 01);
            newReservations.LeavingDate        = new DateTime(2018, 07, 09);
            newReservations.ReservationGuestId = newGuest.Id;
            newReservations.ReservationHostId  = ((HostReadDto)hostReadDto.Value).Id;
            ActionResult <ReservationReadDto> reservationSctionResult = _reservationsController.CreateReservation(newReservations);

            Assert.IsTrue(reservationSctionResult.Result is NotFoundObjectResult);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateReservationAsync(ReservationCreateDto reservationCreateDto)
        {
            if (await reservationService.ReservationCanBeCreatedAsync(reservationCreateDto))
            {
                var reservation = await reservationService.CreateReservationAsync(reservationCreateDto);

                return(Ok(reservation));
            }
            return(BadRequest());
        }
Ejemplo n.º 3
0
        public void CreateReservations_ShouldFail()
        {
            ReservationCreateDto newReservations = new ReservationCreateDto();

            newReservations.ArrivingDate       = new DateTime(2019, 08, 02);
            newReservations.LeavingDate        = new DateTime(2019, 08, 04);
            newReservations.ReservationGuestId = 1;
            newReservations.ReservationHostId  = 2;
            ActionResult <ReservationReadDto> actionResult = _controller.CreateReservation(newReservations);

            Assert.IsTrue(actionResult.Result is NotFoundObjectResult);
        }
Ejemplo n.º 4
0
        public void CreateReservations_ShouldCreateReservations()
        {
            ReservationCreateDto newReservations = new ReservationCreateDto();

            newReservations.ArrivingDate       = new DateTime(2018, 08, 01);
            newReservations.LeavingDate        = new DateTime(2018, 08, 09);
            newReservations.ReservationGuestId = 1;
            newReservations.ReservationHostId  = 2;
            ActionResult <ReservationReadDto> actionResult = _controller.CreateReservation(newReservations);

            Assert.IsTrue(actionResult.Result is CreatedAtRouteResult);
        }
Ejemplo n.º 5
0
        public ActionResult <ReservationCreateDto> CreateReservation(ReservationCreateDto reservationCreateDto)
        {
            var reservationModel = _mapper.Map <Reservation>(reservationCreateDto);

            _repository.CreateReservation(reservationModel);
            _repository.SaveChanges();

            var ReservationReadDto = _mapper.Map <ReservationReadDto>(reservationModel);

            return(CreatedAtRoute(nameof(GetReservationById), new { id = ReservationReadDto.Id }, ReservationReadDto));
            //return Ok(CommandReadDto);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Check if reservation can be created. Method is being executed before CreateReservationAsync() method.
        /// It checks how many reservations are in the database for given term and car.
        /// If 0 then new reservation doesn't collide with other reservations.
        /// </summary>
        /// <param name="reservationDto"></param>
        /// <returns>Returns true if new reservation can be created and false if can't.</returns>
        public async Task <bool> ReservationCanBeCreatedAsync(ReservationCreateDto reservationDto)
        {
            var reservation = new Reservation()
            {
                RentalDate = reservationDto.RentalDate,
                ReturnDate = reservationDto.ReturnDate,
                CarId      = reservationDto.CarId
            };
            List <Reservation> reservations = await reservationRepository.FilterReservationsAsync(reservation);

            return(reservations.Count == 0 ? true : false);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create(ReservationCreateDto reservationCreateDto)
        {
            Reservation reservation = mapper.Map <Reservation>(reservationCreateDto);

            reservation.Status = reservationCreateDto.Paid ? ReservationStatus.Paid : ReservationStatus.Pending;
            reservation.Car    = await carService.GetById(reservation.CarId);

            reservation.UserId = long.Parse(User.FindFirst("Id").Value);

            await reservationService.Create(reservation);

            return(NoContent());
        }
        public virtual async Task <ReservationDto> CreateAsync(ReservationCreateDto input)
        {
            var newReservation = ObjectMapper.Map <ReservationCreateDto, Reservation>(input);


            newReservation.TenantId = CurrentTenant.Id;


            var reservation = await _reservationRepository.InsertAsync(newReservation);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <Reservation, ReservationDto>(reservation));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <ReservationReadDto> > CreateReservation(ReservationCreateDto reservationCreateDto)
        {
            var reservationModel = _mapper.Map <ReservationModel>(reservationCreateDto);
            var x = await _repository.CreateReservation(reservationModel);

            var reservationReadDto = _mapper.Map <ReservationReadDto>(x);

            if (x != null)
            {
                return(CreatedAtRoute(nameof(GetAllReservations), new { Id = x.Id }, reservationReadDto));
            }
            else
            {
                return(NoContent());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Insert new reservation into database.
        /// </summary>
        /// <param name="reservationCreateDto"></param>
        /// <returns>Returns new reservations object mapped to reservationDto.</returns>
        public async Task <ReservationDto> CreateReservationAsync(ReservationCreateDto reservationCreateDto)
        {
            var reservation = new Reservation()
            {
                UserId      = reservationCreateDto.UserId,
                CarId       = reservationCreateDto.CarId,
                RentalDate  = reservationCreateDto.RentalDate,
                ReturnDate  = reservationCreateDto.ReturnDate,
                IsFinished  = false,
                DateCreated = DateTime.Now
            };

            reservationRepository.Create(reservation);
            await reservationRepository.SaveChangesAsync();

            reservation = await reservationRepository.FindByIdAsync(reservation.ReservationId);

            return(mapper.Map <ReservationDto>(reservation));
        }
Ejemplo n.º 11
0
        public async Task ReservationCanBeCreatedAsync_CarIsAvailable_ReturnsTrue()
        {
            //Arrange
            var reservationDto = new ReservationCreateDto()
            {
            };

            mockReservationRepository
            .Setup(p => p.FilterReservationsAsync(It.IsAny <Reservation>()))
            .ReturnsAsync(new List <Reservation>()
            {
            });
            var service = new ReservationService(mockReservationRepository.Object, mapper);
            //Act
            var result = await service.ReservationCanBeCreatedAsync(reservationDto);

            //Assert
            Assert.True(result);
        }
        public ActionResult <ReservationReadDto> CreateReservation([FromQueryAttribute] ReservationCreateDto reservationCreateDto)
        {
            Reservation reservationModel = _mapper.Map <Reservation>(reservationCreateDto);

            try
            {
                IsValidReservation(reservationModel.ReservationGuestId, reservationModel.ReservationHostId, reservationModel.ArrivingDate, reservationModel.LeavingDate);
            }
            catch (ArgumentException exp)
            {
                return(NotFound(exp.Message));
            }

            _reservationRepo.CreateReservation(reservationModel);
            _reservationRepo.SaveChanges();
            ReservationReadDto reservationReadDto = _mapper.Map <ReservationReadDto>(reservationModel);

            return(CreatedAtRoute(nameof(GetReservationById), new { id = reservationModel.Id }, reservationReadDto));
        }
Ejemplo n.º 13
0
        public async Task CreateReservationAsync_ValidObjectPassed_CreatedObject()
        {
            Reservation reservation = new Reservation()
            {
                ReservationId = 1
            };
            ReservationCreateDto reservationDto = new ReservationCreateDto();

            mockReservationRepository
            .Setup(p => p.FindByIdAsync(0))
            .ReturnsAsync(reservation);
            mockReservationRepository
            .Setup(s => s.SaveChangesAsync())
            .Verifiable();
            var service = new ReservationService(mockReservationRepository.Object, mapper);
            //Act
            var result = await service.CreateReservationAsync(reservationDto);

            //Assert
            Assert.Equal(result.ReservationId, reservation.ReservationId);
            Assert.IsType <ReservationDto>(result);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> CreateReservationAsync([FromBody] ReservationCreateDto createDto)
        {
            var reservation = await _reservationDao.CreateReservation(createDto.CustomerId, new DateRange(createDto.CheckIn, createDto.CheckOut));

            return(Ok(new SuccessResponse <Reservation>(reservation)));
        }