public async Task <List <MatchInfo> > GetMatchHistory(string summonerName, string regionCode) { try { IsBusy = true; if (ChampionService.ChampionImageDictionary == null || ChampionService.ChampionImageDictionary.Count == 0) { await ChampionService.GetChampions(); //need champion image urls for match historys } if (ItemService.ItemImageDictionary == null || ItemService.ItemImageDictionary.Count == 0) { await ItemService.GetItems(); //need item image urls for match history } var matchHistory = await SummonerService.GetMatchHistory(summonerName, regionCode); return(matchHistory); } catch (Exception ex) { return(null); } finally { IsBusy = false; } }
private void Init() { Champion = new ChampionService(LeagueApiConfiguration); Game = new GameService(LeagueApiConfiguration); League = new LeagueService(LeagueApiConfiguration); Stats = new StatsService(LeagueApiConfiguration); Summoner = new SummonerService(LeagueApiConfiguration); Team = new TeamService(LeagueApiConfiguration); Static = new StaticService(LeagueApiConfiguration); }
public RiotAPI([NotNull] string apiKey) { INetworkClient networkClient = new NetworkClient(apiKey); IDeserializer deserializer = new JsonDeserializer(); Champions = new ChampionService(networkClient, deserializer); Summoners = new SummonerService(networkClient, deserializer); ChampionMasteries = new ChampionMasteryService(networkClient, deserializer); Leagues = new LeagueService(networkClient, deserializer); Status = new StatusService(networkClient, deserializer); Matches = new MatchService(networkClient, deserializer); }
public async Task GetFiveChampionsAsync_WithIncorrectData_ShouldntReturnFiveChampions() { var options = new DbContextOptionsBuilder <LeagueDraftDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new LeagueDraftDbContext(options); var championService = new ChampionService(context); var result = await championService.GetFiveChampionsAsync(); Assert.True(result.Count() == 0); }
public async Task GetRandomChampionAsync_WithIncorrectData_ShouldntReturnRandomChampion() { var options = new DbContextOptionsBuilder <LeagueDraftDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new LeagueDraftDbContext(options); var championService = new ChampionService(context); var getRandomChampion = await championService.GetRandomChampionAsync(); Assert.True(getRandomChampion == null); }
public async Task ThrowArgumentNullException_WhenPassedNullAccessToken() { // Arrange Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); Mock <DataContext> dataContextMock = new Mock <DataContext>(); // Act ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, dataContextMock.Object); // Assert await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await SUT.RebaseChampionsAsync(null)); }
public async Task ThrowArgumentException_WhenPassedInvalidId(string invalidId) { // Arrange Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); Mock <DataContext> dataContextMock = new Mock <DataContext>(); // Act ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, dataContextMock.Object); // Assert await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await SUT.FindAsync(invalidId)); }
public async Task FilterChampionsAsync_ShouldReturnChampions_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "FilterChampionsAsync_ShouldReturnChampions_WhenPassedValidParameters") .Options; string validSortOrder = "name_asc"; string validFilter = "testChamp"; int validPageSize = 10; int validPageNumber = 1; Champion validChampion = new Champion { Name = "testChamp", HP = 100, MP = 100 }; IEnumerable <Champion> result = new List <Champion>(); // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); await actContext.Champions.AddAsync(validChampion); await actContext.SaveChangesAsync(); ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, actContext); result = await SUT.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { var champion = result.ToArray()[0]; Assert.IsTrue(assertContext.Champions.Count().Equals(result.Count())); Assert.IsTrue(assertContext.Champions.Any(c => c.Name.Equals(champion.Name))); Assert.IsTrue(assertContext.Champions.Any(c => c.HP.Equals(champion.HP))); Assert.IsTrue(assertContext.Champions.Any(c => c.MP.Equals(champion.MP))); } }
public async Task GetChampionByIdAsync_WithCorrectData_ShouldReturnChampionById(int id) { var options = new DbContextOptionsBuilder <LeagueDraftDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new LeagueDraftDbContext(options); var championService = new ChampionService(context); SeedTestChampions(context); var champion = await championService.GetChampionByIdAsync(id); Assert.True(champion.Id == id); }
public async Task RebaseChampionsAsync_ShouldRepopulateChampionTable_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "RebaseChampionsAsync_ShouldRepopulateChampionTable_WhenPassedValidParameters") .Options; string validAccessToken = string.Empty; string validCollectionName = "champions"; int validPageSize = 100; Champion validChampion = new Champion { Id = Guid.NewGuid(), Name = "testChamp", DeletedOn = DateTime.UtcNow.AddHours(2), IsDeleted = true }; IEnumerable <Champion> validChampionList = new List <Champion>() { validChampion }; // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); pandaScoreClientMock .Setup(mock => mock.GetEntitiesParallel <Champion>(validAccessToken, validCollectionName, validPageSize)) .Returns(Task.FromResult(validChampionList)); ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, actContext); await SUT.RebaseChampionsAsync(validAccessToken); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsTrue(assertContext.Champions.Count() == 1); Assert.IsTrue(assertContext.Champions.Contains(validChampion)); } }
public async Task ThrowArgumentOutOfRangeException_WhenPassedInvalidPageSize(int invalidPageSize) { // Arrange Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); Mock <DataContext> dataContextMock = new Mock <DataContext>(); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, dataContextMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>( () => SUT.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, invalidPageSize)); }
public async Task FindAsync_ShouldReturnChampion_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "FindAsync_ShouldReturnChampion_WhenPassedValidParameters") .Options; Guid validId = Guid.NewGuid(); Champion validChampion = new Champion { Id = validId, Name = "testChamp", HP = 100, MP = 100 }; Champion result = null; // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); await actContext.Champions.AddAsync(validChampion); await actContext.SaveChangesAsync(); ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, actContext); result = await SUT.FindAsync(validId.ToString()); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsTrue(assertContext.Champions.Any(c => c.Id.Equals(result.Id))); Assert.IsTrue(assertContext.Champions.Any(c => c.Name.Equals(result.Name))); Assert.IsTrue(assertContext.Champions.Any(c => c.HP.Equals(result.HP))); Assert.IsTrue(assertContext.Champions.Any(c => c.MP.Equals(result.MP))); } }
public async Task RestoreChampionAsync_ShouldFlagChampionAsNotDelete_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "RestoreChampionAsync_ShouldFlagChampionAsNotDelete_WhenPassedValidParameters") .Options; Guid Id = Guid.NewGuid(); bool validIsDeleted = false; Champion validChampion = new Champion { Id = Id, Name = "testChamp", DeletedOn = DateTime.UtcNow.AddHours(2), IsDeleted = true }; Champion result = null; // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); await actContext.AddAsync(validChampion); await actContext.SaveChangesAsync(); ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, actContext); result = await SUT.RestoreChampionAsync(Id.ToString()); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsNotNull(result); Assert.IsNull(result.DeletedOn); Assert.IsTrue(result.IsDeleted.Equals(validIsDeleted)); } }
public async Task AddChampionAsync_ShouldAddChampion_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "AddChampionAsync_ShouldAddChampion_WhenPassedValidParameters") .Options; string validFirstName = "testChamp"; bool validIsDeleted = false; Champion validChampion = new Champion { Name = validFirstName }; Champion result = null; // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>(); ChampionService SUT = new ChampionService( pandaScoreClientMock.Object, actContext); result = await SUT.AddChampionAsync(validFirstName); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsNotNull(result); Assert.IsNotNull(result.CreatedOn); Assert.IsNull(result.DeletedOn); Assert.IsTrue(result.IsDeleted.Equals(validIsDeleted)); Assert.IsTrue(assertContext.Champions.Any(c => c.Name.Equals(result.Name))); } }
public ChampionController(ChampionService championService, ILogger <ChampionController> logger) { _championService = championService; _logger = logger; }
public async void GetMatchData(Match match, Summoner summoner) { WinningTeam = new Team(); LosingTeam = new Team(); AnalysisKills = new ObservableCollection <Participant>(Match.Participants.OrderByDescending((x => x.Stats.Kills))); AnalysisGold = new ObservableCollection <Participant>(Match.Participants.OrderByDescending((x => x.Stats.GoldEarned))); AnalysisDamage = new ObservableCollection <Participant>(Match.Participants.OrderByDescending((x => x.Stats.TotalDamageDealt))); MostKills = Match.Participants.Max(x => x.Stats.Kills); MostGold = Match.Participants.Max(x => x.Stats.GoldEarned); MostDamage = Match.Participants.Max(x => x.Stats.TotalDamageDealt); foreach (var participant in Match.Participants) { participant.Items = new ObservableCollection <string>(); participant.Items.Add(participant.Stats.Item0Icon); participant.Items.Add(participant.Stats.Item1Icon); participant.Items.Add(participant.Stats.Item2Icon); participant.Items.Add(participant.Stats.Item3Icon); participant.Items.Add(participant.Stats.Item4Icon); participant.Items.Add(participant.Stats.Item5Icon); participant.Items.Add(participant.Stats.Item6Icon); if (participant.Stats.Win) { WinningTeam.Participants.Add(participant); WinningTeam.Kills += participant.Stats.Kills; WinningTeam.Deaths += participant.Stats.Deaths; WinningTeam.Assists += participant.Stats.Assists; WinningTeam.Gold += participant.Stats.GoldEarned; WinningTeam.Damage += participant.Stats.TotalDamageDealt; } else { LosingTeam.Participants.Add(participant); LosingTeam.Kills += participant.Stats.Kills; LosingTeam.Deaths += participant.Stats.Deaths; LosingTeam.Assists += participant.Stats.Assists; LosingTeam.Gold += participant.Stats.GoldEarned; LosingTeam.Damage += participant.Stats.TotalDamageDealt; } if (participant.SummonerName == summoner.Name) { participant.IsPlayer = true; MainParticipant = participant; RuneService.GetSlots(MainParticipant); await Task.Delay(1500); if (MainParticipant.Stats.Win) { var tempWinning = Match.Teams.First(x => x.TeamId == MainParticipant.TeamId); WinningTeam.TowerKills = tempWinning.TowerKills; WinningTeam.BaronKills = tempWinning.BaronKills; WinningTeam.DragonKills = tempWinning.DragonKills; var tempLosing = Match.Teams.First(x => x.TeamId != tempWinning.TeamId); LosingTeam.TowerKills = tempLosing.TowerKills; LosingTeam.BaronKills = tempLosing.BaronKills; LosingTeam.DragonKills = tempLosing.DragonKills; } else { var tempLosing = Match.Teams.First(x => x.TeamId == MainParticipant.TeamId); LosingTeam.TowerKills = tempLosing.TowerKills; LosingTeam.BaronKills = tempLosing.BaronKills; LosingTeam.DragonKills = tempLosing.DragonKills; var tempWinning = Match.Teams.First(x => x.TeamId != tempLosing.TeamId); WinningTeam.TowerKills = tempWinning.TowerKills; WinningTeam.BaronKills = tempWinning.BaronKills; WinningTeam.DragonKills = tempWinning.DragonKills; } } participant.SummonerName = Match.ParticipantIdentities.Find(x => x.ParticipantId == participant.ParticipantId).Player.SummonerName; participant.Champion = ChampionService.GetChampion(participant.ChampionId); participant.Spell1Icon = Utils.GetSpell(participant.Spell1Id); participant.Spell2Icon = Utils.GetSpell(participant.Spell2Id); participant.Stats.TotalKillsProgress = (float)participant.Stats.Kills / (float)MostKills; participant.Stats.TotalGoldEarnedProgress = (float)participant.Stats.GoldEarned / (float)MostGold; participant.Stats.TotalDamageDealtProgress = (float)participant.Stats.TotalDamageDealt / (float)MostDamage; } }
public ChampionsController(ChampionService championService) { this.championService = championService; }