public async Task CatchCreateMovieRentalWithNonExistentMovie() { var movieId = Guid.NewGuid(); var customerId = Guid.NewGuid(); using (var context = CreateContext()) { await context.AddAsync(new Customer() { Id = customerId }); await context.SaveChangesAsync(); var movieRentalService = new MovieRentalService(new RepositoryBase(context)); var inputModel = new Core.Application.InputModels.Movies.CreateMovieRentalInputModel() { MovieId = movieId, CustomerId = customerId, DaysInRental = 5 }; Assert.ThrowsAsync <BusinessException>(async() => await movieRentalService.CreateMovieRentalAsync(inputModel)); ClearContext(context); } }
public void CatchCreateMovieRentalWithInvalidDaysInRental(int daysInRental) { var movieRentalService = new MovieRentalService(Mock.Of <IRepository>()); var inputModel = new Core.Application.InputModels.Movies.CreateMovieRentalInputModel() { DaysInRental = daysInRental }; Assert.ThrowsAsync <ModelValidationException>(async() => await movieRentalService.CreateMovieRentalAsync(inputModel)); }
public async Task CreateMovieRentalWithSuccess() { var movieId = Guid.NewGuid(); var customerId = Guid.NewGuid(); using (var context = CreateContext()) { await context.AddAsync(new Movie() { Id = movieId }); await context.AddAsync(new Customer() { Id = customerId }); await context.SaveChangesAsync(); var movieRentalService = new MovieRentalService(new RepositoryBase(context)); var inputModel = new Core.Application.InputModels.Movies.CreateMovieRentalInputModel() { MovieId = movieId, CustomerId = customerId, DaysInRental = 5 }; var result = await movieRentalService.CreateMovieRentalAsync(inputModel); Assert.AreEqual(inputModel.MovieId, result.MovieId); Assert.AreEqual(inputModel.CustomerId, result.CustomerId); Assert.AreEqual(inputModel.DaysInRental, result.DaysInRental); Assert.IsTrue(result.ReturnedAt == null); Assert.IsTrue(result.Id != default); ClearContext(context); } }