예제 #1
0
        public async Task EditGenreMustRenameGenreByGiveId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <Genre>(new ApplicationDbContext(options.Options));

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

            await repository.SaveChangesAsync();

            var service = new GenresService(repository, null);

            AutoMapperConfig.RegisterMappings(typeof(GenreTestModel).Assembly);

            var genre = await service.EditGenreAsync(1, "Drama");

            var expectedGenre = service.GetById <GenreTestModel>(1);

            Assert.Equal(1, genre);
            Assert.Equal("Drama", expectedGenre.Name);
        }
예제 #2
0
        public async Task GetGenreByIdAndReturnIdAndNameIfItExists()
        {
            AutoMapperConfig.RegisterMappings(typeof(GenreTestModel).Assembly);
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <Genre>(new ApplicationDbContext(options.Options));

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

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

            await repository.AddAsync(new Genre { Id = 3, Name = "Drama" });

            await repository.SaveChangesAsync();

            var service = new GenresService(repository, null);

            var genre = service.GetById <GenreTestModel>(1);

            Assert.Equal(1, genre.Id);
            Assert.Equal("Action", genre.Name);
        }