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 IActionResult <GameDetailsViewModel> Game(HttpSession session, HttpResponse response,
                                                         BuyGameBindingModel model)
        {
            if (!AuthenticationManager.IsAuthenticated(session.Id))
            {
                Redirect(response, $"/authentication/login");
                return(null);
            }
            User user = AuthenticationManager.GetAuthenticatedUser(session.Id);

            service.AddGameToUser(model, user);
            Redirect(response, "/user/games");
            return(null);
        }
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 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.º 5
0
        public async Task AddGameToUserShouldThrowArgumentExceptionIfGivenInvalidGameId(int gameId)
        {
            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();

            var userId = user.Id;

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

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.AddGameToUser(userId, gameId));
        }
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);
        }