示例#1
0
        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);
            }
        }
示例#2
0
        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));
        }
示例#3
0
        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);
            }
        }