Ejemplo n.º 1
0
        public void CanGetGuildFromDatabase()
        {
            DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>()
                                                           .UseInMemoryDatabase("CanGetGuildFromDatabase")
                                                           .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);
            var actual      = guildService.GetGuild(creation.Result.Id).Result;

            Assert.Equal(1, context.Guilds.CountAsync().Result);
            Assert.IsType <GuildsDTO>(actual);
            Assert.Equal(1, actual.Id);
            Assert.Equal("Odin Slayers", actual.Name);
        }
Ejemplo n.º 2
0
        public void CanDeleteGuildAndSaveToDatabase()
        {
            DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>()
                                                           .UseInMemoryDatabase("CanDeleteGuildAndSaveToDatabase")
                                                           .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);

            Assert.Equal(1, context.Guilds.CountAsync().Result);
            var delete = guildService.Delete(creation.Result.Id);

            Assert.Equal(0, context.Guilds.CountAsync().Result);
        }