Esempio n. 1
0
        public async Task UpdateAsync_DepartmentValidationSucceed_CreatesReservation()
        {
            // Arrange
            var reservation = new ReservationUpdateModel();
            var expected    = new Reservation();

            var clubGetService = new Mock <IClubGetService>();

            clubGetService.Setup(x => x.ValidateAsync(reservation));

            var groupGetService = new Mock <IGroupGetService>();

            groupGetService.Setup(x => x.ValidateAsync(reservation));

            var reservationDataAccess = new Mock <IReservationDataAccess>();

            reservationDataAccess.Setup(x => x.UpdateAsync(reservation)).ReturnsAsync(expected);

            var reservationGetService = new ReservationUpdateService(reservationDataAccess.Object, clubGetService.Object, groupGetService.Object);

            // Act
            var result = await reservationGetService.UpdateAsync(reservation);

            // Assert
            result.Should().Be(expected);
        }
Esempio n. 2
0
        public async Task UpdateAsync_ClubValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture     = new Fixture();
            var reservation = new ReservationUpdateModel();
            var expected    = fixture.Create <string>();

            var clubGetService = new Mock <IClubGetService>();

            clubGetService
            .Setup(x => x.ValidateAsync(reservation))
            .Throws(new InvalidOperationException(expected));

            var groupGetService = new Mock <IGroupGetService>();

            groupGetService.Setup(x => x.ValidateAsync(reservation)).Throws(new InvalidOperationException(expected));


            var reservationDataAccess = new Mock <IReservationDataAccess>();

            var reservationGetService = new ReservationUpdateService(reservationDataAccess.Object, clubGetService.Object, groupGetService.Object);

            // Act
            var action = new Func <Task>(() => reservationGetService.UpdateAsync(reservation));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            reservationDataAccess.Verify(x => x.UpdateAsync(reservation), Times.Never);
        }
        public async Task <Reservation> UpdateAsync(ReservationUpdateModel reservation)
        {
            await GroupGetService.ValidateAsync(reservation);

            await ClubGetService.ValidateAsync(reservation);

            return(await ReservationDataAccess.UpdateAsync(reservation));
        }
        public async Task <Reservation> InsertAsync(ReservationUpdateModel reservation)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Reservation>(reservation));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Reservation>(result.Entity));
        }
        public async Task <Reservation> UpdateAsync(ReservationUpdateModel reservation)
        {
            var existing = await this.Get(reservation);

            var result = this.Mapper.Map(reservation, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Reservation>(result));
        }
Esempio n. 6
0
        public IActionResult ChooseUpdateReservation(int reservationId)
        {
            var reservation = _sportEventManager.GetReservation(reservationId);

            var model = new ReservationUpdateModel
            {
                ReservationId = reservationId,
                EndTime       = reservation.TimeFinish,
                StartTime     = reservation.StartTime
            };

            return(View(model));
        }
Esempio n. 7
0
        public IHttpActionResult PutReservation(int id, ReservationUpdateModel reservationUpdateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reservationUpdateModel.Id)
            {
                return(BadRequest());
            }
            var reservation = db.Reservations.Find(reservationUpdateModel.Id);

            reservation.Screening  = db.Screenings.Find(reservationUpdateModel.ScreeningId);
            reservation.User       = db.Users.Find(reservationUpdateModel.UserId);
            reservation.ModifiedAt = DateTime.UtcNow;

            db.Entry(reservation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReservationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }