public async Task GetChampionDtoShouldThrowArgumentNullExceptionIfGivenInvalidRiotId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("championTest");
            var db = new ApplicationDbContext(options.Options);

            int invalidChampionRiotId = -100;

            var service = new ChampionsService(db);

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await service.GetChampionDto(invalidChampionRiotId));
        }
Ejemplo n.º 2
0
        public async Task GetCollectionGamesShouldReturnCollectionPageGameViewModel()
        {
            var validGameId = 2660892488;
            int regionId    = 1;

            var user = new ApplicationUser()
            {
                Email = "[email protected]",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolAddGameToUser");
            var db = new ApplicationDbContext(options.Options);

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            int expectedGameCount = 1;
            var userId            = user.Id;

            var service = new GamesService(db, this.playersService, this.teamsService.Object);

            await service.AddGameToCollection(validGameId, regionId);

            var expectedGame = await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId);

            await service.AddGameToUser(userId, validGameId);

            var result          = (await service.GetCollectionGames(userId)).ToList();
            var resultFirstGame = result.FirstOrDefault();

            Assert.NotNull(result);
            Assert.NotNull(resultFirstGame);
            Assert.IsType <List <CollectionPageGameViewModel> >(result);
            Assert.IsType <CollectionPageGameViewModel>(resultFirstGame);
            Assert.Equal(expectedGameCount, result.Count());
            Assert.Equal(expectedGame.RiotGameId, resultFirstGame.GameId);
            Assert.Equal(expectedGame.Teams.First().State, resultFirstGame.BlueTeam.State);
            Assert.Equal(expectedGame.Teams.Last().State, resultFirstGame.RedTeam.State);
            Assert.Equal(expectedGame.Teams[0].Players.First().Username, resultFirstGame.BlueTeam.Players.First().Username);
            Assert.Equal(expectedGame.Teams[1].Players.Last().Username, resultFirstGame.RedTeam.Players.Last().Username);
        }
        public async Task GetChampionDtoShouldReturnChampionDtoWithTheGivenId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("championDtoTest");
            var db = new ApplicationDbContext(options.Options);

            int    championRiotId       = 41;
            string expectedChampionName = "Gangplank";

            var service = new ChampionsService(db);

            var result = await service.GetChampionDto(championRiotId);

            Assert.NotNull(result);
            Assert.Equal(expectedChampionName, result.ChampionName);
            Assert.IsType <ChampionDTO>(result);
        }
Ejemplo n.º 4
0
        public async Task AddGameToCollectionShouldAddGameToDatabase()
        {
            var validGameId = 2657118595;
            int regionId    = 1;

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolAddGameToCollection");
            var db = new ApplicationDbContext(options.Options);

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            var expectedGame = await this.api.Match.GetMatchAsync(Region.Eune, validGameId);

            var expectedCollectionGameCount = 1;

            var service = new GamesService(db, this.playersService, this.teamsService.Object);

            await service.AddGameToCollection(validGameId, regionId);

            var resultGame = await db.Games.FirstOrDefaultAsync();

            var firstPlayer         = resultGame.Teams.First().Players.First();
            var lastPlayer          = resultGame.Teams.Last().Players.Last();
            var firstPlayerChampion = await db.ChampionsStatic.FirstOrDefaultAsync(c => c.ChampionId == firstPlayer.PlayerChampions.First().ChampionId);

            var lastPlayerChampion = await db.ChampionsStatic.FirstOrDefaultAsync(c => c.ChampionId == lastPlayer.PlayerChampions.First().ChampionId);

            Assert.NotNull(resultGame);
            Assert.NotNull(resultGame.Teams);
            Assert.NotNull(resultGame.Teams[0].Players);
            Assert.NotNull(resultGame.Teams[1].Players);
            Assert.NotNull(resultGame.Teams[0]);
            Assert.NotNull(resultGame.Teams[1]);
            Assert.Equal(expectedCollectionGameCount, await db.Games.CountAsync());
            Assert.Equal(expectedGame.GameId, resultGame.RiotGameId);
            Assert.Equal(expectedGame.Teams.First().Win, resultGame.Teams.First().State);
            Assert.Equal(expectedGame.Teams.Last().Win, resultGame.Teams.Last().State);
            Assert.Equal(expectedGame.ParticipantIdentities.First().Player.SummonerName, firstPlayer.Username);
            Assert.Equal(expectedGame.ParticipantIdentities.Last().Player.SummonerName, lastPlayer.Username);
            Assert.Equal(expectedGame.Participants.First().ChampionId, int.Parse(firstPlayerChampion.ChampionRiotId));
            Assert.Equal(expectedGame.Participants.Last().ChampionId, int.Parse(lastPlayerChampion.ChampionRiotId));
        }
Ejemplo n.º 5
0
        public async Task AddGameToUserShouldThrowArgumentExceptionIfGivenInvalidUserId(string userId)
        {
            var validGameId = 2657118595;
            int regionId    = 1;

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolAddGameToUser");
            var db = new ApplicationDbContext(options.Options);

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            var service = new GamesService(db, this.playersService, this.teamsService.Object);
            await service.AddGameToCollection(validGameId, regionId);

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.AddGameToUser(userId, validGameId));
        }
Ejemplo n.º 6
0
        public async Task GetGameCountShouldReturnCorrectNumberOfGamesInUsersCollection()
        {
            var validGameId  = 2657118595;
            var secondGameId = 2652692459;
            int regionId     = 1;

            var user = new ApplicationUser()
            {
                Email = "[email protected]",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolGameCount");
            var db = new ApplicationDbContext(options.Options);

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            var userId            = user.Id;
            int expectedGameCount = 2;

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            var service = new GamesService(db, this.playersService, this.teamsService.Object);
            await service.AddGameToCollection(validGameId, regionId);

            await service.AddGameToUser(userId, validGameId);

            await service.AddGameToCollection(secondGameId, regionId);

            await service.AddGameToUser(userId, secondGameId);

            var result = service.GetGameCount(userId);

            Assert.Equal(expectedGameCount, result);
        }
Ejemplo n.º 7
0
        public async Task RemoveGameFromCollectionShouldRemoveTheGameFromUsersCollection()
        {
            var validGameId = 2660892488;
            int regionId    = 1;

            var user = new ApplicationUser()
            {
                Email = "[email protected]",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolRemoveGameToUser");
            var db = new ApplicationDbContext(options.Options);

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            int expectedGameCount = 0;
            var userId            = user.Id;

            var service = new GamesService(db, this.playersService, this.teamsService.Object);
            await service.AddGameToCollection(validGameId, regionId);

            await service.AddGameToUser(userId, validGameId);

            await service.RemoveGameFromCollection(userId, validGameId);

            var tryGetGame = await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId);

            Assert.Null(tryGetGame);
            Assert.Equal(expectedGameCount, db.Games.Count());
            Assert.Equal(expectedGameCount, db.UserGames.Count());
        }
Ejemplo n.º 8
0
        public async Task AddGameToUserShouldAddTheGameToGivenUserById()
        {
            var validGameId = 2657118595;
            int regionId    = 1;

            var user = new ApplicationUser()
            {
                Email = "[email protected]",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("lolAddGameToUserLol");
            var db = new ApplicationDbContext(options.Options);

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            RegionsService regionsService = new RegionsService(db);
            await regionsService.UpdateRegions();

            ChampionsService championsService = new ChampionsService(db);
            await championsService.UploadChamionsToDBAsync();

            var userId = user.Id;

            var service = new GamesService(db, this.playersService, this.teamsService.Object);

            await service.AddGameToCollection(validGameId, regionId);

            var gameId = (await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId)).GameId;

            await service.AddGameToUser(userId, validGameId);

            var userGames = await db.UserGames.FirstOrDefaultAsync();

            Assert.NotNull(userGames);
            Assert.Equal(userId, userGames.UserId);
            Assert.Equal(gameId, userGames.GameId);
        }
Ejemplo n.º 9
0
        public Session()
        {
            AccountService        = new Riot.Services.AccountService(this);
            ChampionTradeService  = new Riot.Services.ChampionTradeService(this);
            ClientFacadeService   = new Riot.Services.ClientFacadeService(this);
            GameInvitationService = new Riot.Services.GameInvitationService(this);
            GameService           = new Riot.Services.GameService(this);
            InventoryService      = new Riot.Services.InventoryService(this);
            LcdsProxyService      = new Riot.Services.LcdsProxyService(this);
            LeaguesService        = new Riot.Services.LeaguesService(this);
            LoginService          = new Riot.Services.LoginService(this);
            MasteryBookService    = new Riot.Services.MasteryBookService(this);
            MatchmakingService    = new Riot.Services.MatchmakingService(this);
            PlayerStatsService    = new Riot.Services.PlayerStatsService(this);
            RerollService         = new Riot.Services.RerollService(this);
            SpellBookService      = new Riot.Services.SpellBookService(this);
            SummonerIconService   = new Riot.Services.SummonerIconService(this);
            SummonerRuneService   = new Riot.Services.SummonerRuneService(this);
            SummonerService       = new Riot.Services.SummonerService(this);
            SummonerTeamService   = new Riot.Services.SummonerTeamService(this);

            LootService             = new LootService(this, LcdsProxyService);
            ChampionMasteryService  = new ChampionMasteryService(this, LcdsProxyService);
            TeambuilderDraftService = new TeambuilderDraftService(this, LcdsProxyService);

            PlayerPreferencesService = new PlayerPreferencesService(this);
            MatchHistoryService      = new MatchHistoryService(this);

            var patcher = new PatcherService(this);

            this.chat = new ChatService(this);

            this.Maestro = new Maestro(chat, patcher);

            var settings = new SettingsService(this);

            var hextech   = new HextechService(this);
            var champions = new ChampionsService(this);
            var masteries = new MasteriesService(this);
            var runes     = new RunesService(this);

            var matches = new Server.Profile.MatchHistoryService(this);

            this.summoner = new SummonerService(this);
            this.Assets   = new AssetsService(patcher);

            var rooms = new ChatRoomService(this, chat);
            var login = new AuthService(this);

            var game   = new PlayLoopService(this, rooms);
            var invite = new InviteService(this, game);

            var meta  = new MetaService(this);
            var debug = new DebugService(this);

            var replay = new ReplayService(this);

            patcher.FinishWAD();

            var info = new InfoService(this, patcher);
        }