Exemplo n.º 1
0
 public string GetDamageCauserName(string damageCauserKey)
 {
     try
     {
         var damageCausersDict = _memoryCache.Get <Dictionary <string, string> >(_damageCausersCacheKey);
         if (damageCausersDict == null)
         {
             var damageCausersJson = EmbeddedResourcesUtility.ReadEmbeddedResource(_damageCausersResourcePath);
             damageCausersDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(damageCausersJson);
             _memoryCache.Set(_damageCausersCacheKey, damageCausersDict, new MemoryCacheEntryOptions
             {
                 AbsoluteExpiration = DateTimeOffset.UtcNow.Add(_damageCausersCacheExpiration)
             });
         }
         return(damageCausersDict[damageCauserKey]);
     }
     catch (FileNotFoundException)
     {
         _logger.LogError($"Resource path: {_damageCausersResourcePath} not found");
     }
     catch (JsonReaderException)
     {
         _logger.LogError($"Failed to deserialize Damage Causers json into a dictionary.");
     }
     catch (KeyNotFoundException)
     {
         _logger.LogError($"Key {damageCauserKey} not found in the damage causers dictionary.");
     }
     return(string.Empty);
 }
Exemplo n.º 2
0
        public IEnumerable <Competition> GetCompetitionSchedule()
        {
            var schedule = _memoryCache.Get <IEnumerable <Competition> >(_eventScheduleCacheKey);

            if (schedule != null)
            {
                return(schedule);
            }
            try
            {
                var scheduleJson = EmbeddedResourcesUtility.ReadEmbeddedResource(_eventScheduleResourcePath);
                var res          = JsonConvert.DeserializeObject <IEnumerable <Competition> >(scheduleJson);
                _memoryCache.Set(_eventScheduleCacheKey, res, new MemoryCacheEntryOptions
                {
                    AbsoluteExpiration = DateTimeOffset.UtcNow.Add(_eventScheduleCacheExpiration)
                });
                return(res);
            }
            catch (FileNotFoundException)
            {
                _logger.LogError($"Resource path: {_eventScheduleResourcePath} not found");
            }
            catch (JsonReaderException)
            {
                _logger.LogError($"Failed to deserialize Event Schedule json into a dictionary.");
            }
            return(null);
        }
Exemplo n.º 3
0
        public async Task GetTeamRankings_WhenProvidingMockInputs_ShouldProduceExpectedOutput()
        {
            // arrange
            var mockKillListStr        = EmbeddedResourcesUtility.ReadEmbeddedResource("Fanview.Test.Mocks.killList.json");
            var mockLiveMatchStatusStr = EmbeddedResourcesUtility.ReadEmbeddedResource("Fanview.Test.Mocks.liveMatchStatus.json");
            var mockResStr             = EmbeddedResourcesUtility.ReadEmbeddedResource("Fanview.Test.Mocks.teamRankingResult.json");
            var mockKillList           = JsonConvert.DeserializeObject <KillLeader>(mockKillListStr);
            var mockLiveMatchStatus    = JsonConvert.DeserializeObject <IEnumerable <LiveMatchStatus> >(mockLiveMatchStatusStr);
            var mockRes = JsonConvert.DeserializeObject <IEnumerable <LiveTeamRanking> >(mockResStr);

            // act
            var res = await _sut.GetTeamRankings(mockKillList, mockLiveMatchStatus);

            // assert
            foreach (var team in res)
            {
                var mockTeam = mockRes.FirstOrDefault(t => t.TeamId == team.TeamId);
                Assert.AreEqual(mockTeam.RankPoints, team.RankPoints, team.TeamName + " - Rank points");
                Assert.AreEqual(mockTeam.KillPoints, team.KillPoints, team.TeamName + " - Kill points");
                Assert.AreEqual(mockTeam.TotalPoints, team.TotalPoints, team.TeamName + " - Total points");
                Assert.AreEqual(mockTeam.TeamRank, team.TeamRank, team.TeamName + " - Rank");
            }
        }