Exemplo n.º 1
0
        public async Task EditGenreShouldWorkCorrectly(string name, string description)
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);
            await db.Genres.AddAsync(
                new Genre
            {
                Name        = "test",
                Description = "description",
            });

            await db.SaveChangesAsync();

            var genresService = new GenresService(db);

            await genresService.EditGenreAsync(1, name, description);

            var result = await db.Genres.FirstOrDefaultAsync();

            Assert.Equal(name, result.Name);
            Assert.Equal(description, result.Description);
            Assert.NotNull(result.ModifiedOn);
        }
Exemplo n.º 2
0
        public async Task EditGenreMustReturnFalseWithIncorrectNames(string name)
        {
            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.SaveChangesAsync();

            var service = new GenresService(repository, null);

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => service.EditGenreAsync(1, name));
        }
Exemplo n.º 3
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);
        }