Ejemplo n.º 1
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.º 2
0
        public async Task AddGameToCollectionShouldThrowArgumentExceptionIfGivenInvalidRegionId(int regionId)
        {
            var validGameId = 2657118595;

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

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

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.AddGameToCollection(validGameId, regionId));
        }
Ejemplo n.º 3
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);
        }
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 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.º 7
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);
        }