Exemplo n.º 1
0
        public void CanUpdateGuildAndSaveToDatabase()
        {
            DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>()
                                                           .UseInMemoryDatabase("CanUpdateGuildAndSaveToDatabase")
                                                           .Options;

            using GuildAPIDbContext context = new GuildAPIDbContext(options);
            GamesService gameService = new GamesService(context);
            GamesDTO     gamesDTO    = new GamesDTO()
            {
                Name = "Odins Game"
            };
            var          createdGame  = gameService.Create(gamesDTO);
            GuildService guildService = new GuildService(context, gameService);

            Assert.Equal(1, context.Games.CountAsync().Result);
            GuildsDTO guild = new GuildsDTO()
            {
                Name = "Odin Slayers"
            };
            var creation    = guildService.Create(guild);
            var association = gameService.AddGameGuild(createdGame.Result.Id, creation.Result.Id);

            GuildsDTO guildsDTO = new GuildsDTO()
            {
                Id   = 1,
                Name = "I am updated"
            };

            var update = guildService.Update(guildsDTO).Result;
            var actual = context.Guilds.FindAsync(update.Id).Result;

            Assert.Equal(1, context.Guilds.CountAsync().Result);
            Assert.IsType <Guilds>(actual);
            Assert.Equal(1, actual.Id);
            Assert.Equal("I am updated", actual.Name);
        }