예제 #1
0
        public async Task GetGamesAsyncShouldThrowArgumentExceptionIfGivenInvalidCount(int count)
        {
            GetGamesInputModel input = new GetGamesInputModel()
            {
                Username = "******",
                Count    = count,
                RegionId = 1, // Eune
            };

            GetGamesInputModel secondInput = new GetGamesInputModel()
            {
                Username = "******",
                Count    = count,
                RegionId = 1, // Eune
            };

            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.GetGamesAsync(input));

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetGamesAsync(secondInput));
        }
예제 #2
0
        public async Task GetGamesAsyncShouldThrowArgumentNullExceptionIfGivenNonExistentUsername(string username)
        {
            GetGamesInputModel input = new GetGamesInputModel()
            {
                Username = username,
                Count    = 1,
                RegionId = 1, // Eune
            };

            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 <ArgumentNullException>(async() => await service.GetGamesAsync(input));
        }
예제 #3
0
        public async Task GetGamesAsyncShouldReturnCollectionoFMatchByInput()
        {
            var summonerName = "Nikolcho";
            var count        = 2;
            var region       = Region.Eune;

            var summoner = await this.api.Summoner.GetSummonerByNameAsync(region, summonerName);

            var matchList = await this.api.Match.GetMatchListAsync(region, summoner.AccountId);

            var expectedGames = new List <RiotSharp.Endpoints.MatchEndpoint.Match>();

            for (int i = 0; i < count; i++)
            {
                var game = await this.api.Match.GetMatchAsync(region, matchList.Matches[i].GameId);

                expectedGames.Add(game);
            }

            GetGamesInputModel input = new GetGamesInputModel()
            {
                Username = summonerName,
                Count    = count,
                RegionId = 1, // Eune
            };

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

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

            var games = (await service.GetGamesAsync(input)).ToList();

            Assert.NotNull(games);
            Assert.IsType <List <RiotSharp.Endpoints.MatchEndpoint.Match> >(games);
            Assert.Equal(expectedGames[0].GameId, games[0].GameId);
            Assert.Equal(expectedGames[0].GameCreation, games[0].GameCreation);
            Assert.Equal(expectedGames[0].QueueId, games[0].QueueId);
            Assert.Equal(expectedGames[0].SeasonId, games[0].SeasonId);
            Assert.Equal(expectedGames[1].GameId, games[1].GameId);
            Assert.Equal(expectedGames[1].GameCreation, games[1].GameCreation);
            Assert.Equal(expectedGames[1].QueueId, games[1].QueueId);
            Assert.Equal(expectedGames[1].SeasonId, games[1].SeasonId);
        }
        public async Task <ICollection <Match> > GetGamesAsync(GetGamesInputModel input)
        {
            if (input.Count < 0 || input.Count > 10)
            {
                throw new ArgumentException("Count must be between 0 and 10!");
            }

            if (input.RegionId < 0 || input.RegionId > 10)
            {
                throw new ArgumentException("Region Id must be between 0 and 10!");
            }

            if (input.Username.Length <= 0 || input.Username.Length > 16) // Leagues max name length is 16!
            {
                throw new ArgumentException("Username must be between 1 and 16 characters long!");
            }

            RiotSharp.Misc.Region region = (RiotSharp.Misc.Region)input.RegionId;

            var summoner = await this.GetBasicSummonerDataAsync(input.Username, region);

            if (summoner == null)
            {
                throw new ArgumentNullException("summonerName", "Wrong summoner name!");
            }

            var matches = await this.Api.Match.GetMatchListAsync(region, summoner.AccountId);

            var games = new List <Match>();

            for (int i = 0; i < input.Count; i++)
            {
                var game = await this.GetGameAsync(matches.Matches[i].GameId, region);

                games.Add(game);
            }

            return(games);
        }
예제 #5
0
        public async Task <IActionResult> GetGames(GetGamesInputModel input)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                return(this.Redirect("/Identity/Account/Login"));
            }

            IEnumerable <HomePageGameViewModel> viewModel = new List <HomePageGameViewModel>();

            try
            {
                var games = await this.gamesService.GetGamesAsync(input);

                viewModel = await this.gamesService.GetModelByMatches(games, input.RegionId);
            }
            catch (System.Exception e)
            {
                if (e.Message == "404, Resource not found")
                {
                    this.ModelState.AddModelError("lol", "There are no results recorded for the given Username.");
                }
                else
                {
                    this.ModelState.AddModelError("lol", e.Message);
                }
            }

            if (!this.ModelState.IsValid)
            {
                var regions = await this.regionsService.GetRegions();

                this.ViewBag.Regions = regions;
                return(this.View("lolapp"));
            }

            return(this.View("games", viewModel));
        }
        public async Task <ICollection <Match> > GetGamesAsync(GetGamesInputModel input)
        {
            RiotSharp.Misc.Region region = (RiotSharp.Misc.Region)input.RegionId;

            var summoner = await this.GetBasicSummonerDataAsync(input.Username, region);

            if (summoner == null)
            {
                throw new ArgumentException("Wrong summoner name!");
            }

            var matches = await this.Api.Match.GetMatchListAsync(region, summoner.AccountId);

            var games = new List <Match>();

            for (int i = 0; i < input.Count; i++)
            {
                var game = await this.GetGameAsync(matches.Matches[i].GameId, region);

                games.Add(game);
            }

            return(games);
        }