Ejemplo n.º 1
0
        public async Task CreateMovieShouldAddMovieToRepository()
        {
            AutoMapperConfig.RegisterMappings(typeof(MovieTestModel).Assembly);

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(options.Options));

            await repository.AddAsync(new Movie { Id = 1, Name = "Movie1" });

            await repository.AddAsync(new Movie { Id = 2, Name = "Movie2" });

            await repository.SaveChangesAsync();

            var service = new MoviesService(repository, null, null, null);

            var movie = new CreateMovieServiceInputModel
            {
                Name      = "TestMovie",
                Length    = 50,
                Directors = new[] { "Test" },
                Genres    = new[] { "1" },
                Actors    = new[] { "Test" },
            };

            await service.CreaterMovieAsync(movie);

            var genresCount = service.GetAll <MovieTestModel>().Count;

            Assert.Equal(3, genresCount);
        }