Esempio n. 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);
            }
        }
Esempio n. 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));
        }
Esempio n. 3
0
        public async Task ReturnMovieWithSuccess(bool passedDeliveryDay)
        {
            var movieId    = Guid.NewGuid();
            var customerId = Guid.NewGuid();

            var      daysInRental = 5;
            DateTime createdAt    = DateTime.UtcNow.AddDays(-1);

            if (passedDeliveryDay)
            {
                createdAt = createdAt.AddDays(-daysInRental);
            }

            using (var context = CreateContext())
            {
                await context.AddAsync(new Movie()
                {
                    Id = movieId
                });

                await context.AddAsync(new Customer()
                {
                    Id = customerId
                });

                await context.AddAsync(new MovieRental()
                {
                    MovieId = movieId, CustomerId = customerId, DaysInRental = daysInRental, CreatedAt = createdAt
                });

                await context.SaveChangesAsync();

                var movieRentalService = new MovieRentalService(new RepositoryBase(context));

                var inputModel = new Core.Application.InputModels.Movies.ReturnMovieInputModel()
                {
                    MovieId    = movieId,
                    CustomerId = customerId,
                };

                var result = await movieRentalService.ReturnMovieAsync(inputModel);

                var expectedStatus = passedDeliveryDay ? "Alert" : "Success";

                Assert.IsTrue(result.Status.Equals(expectedStatus));

                ClearContext(context);
            }
        }
Esempio n. 4
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);
            }
        }