public void SportDataCacheCorrectlyHandlesFetchMiss() { var nonExistingTournamentUrn = URN.Parse($"{TestData.SimpleTournamentId}9"); Assert.AreEqual(0, _sportDataCache.Sports.Count); Assert.AreEqual(0, _sportDataCache.Categories.Count); Assert.AreEqual(0, _sportEventCache.Cache.Count()); Assert.AreEqual(0, _dataRouterManager.GetCallCount(AllTournaments), $"{AllTournaments} should be called exactly 0 times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(AllSports), $"{AllSports} should be called exactly 0 times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); var sports = _sportDataCache.GetSportsAsync(TestData.Cultures).Result; // initial load Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllTournaments), $"{AllTournaments} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllSports), $"{AllSports} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); Assert.AreEqual(TestData.CacheSportCount, _sportDataCache.Sports.Count); Assert.AreEqual(TestData.CacheCategoryCountPlus, _sportDataCache.Categories.Count); Assert.AreEqual(TestData.CacheTournamentCount, _sportEventCache.Cache.Count(c => c.Key.Contains("tournament") || c.Key.Contains("season"))); Assert.AreEqual(0, _sportEventCache.SpecialTournaments.Count()); var data01 = _sportDataCache.GetSportForTournamentAsync(nonExistingTournamentUrn, TestData.Cultures).Result; Assert.IsNull(data01); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllTournaments), $"{AllTournaments} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllSports), $"{AllSports} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.CacheSportCount, _sportDataCache.Sports.Count); Assert.AreEqual(TestData.CacheCategoryCountPlus, _sportDataCache.Categories.Count); Assert.AreEqual(TestData.CacheTournamentCount + 1, _sportEventCache.Cache.Count(c => c.Key.Contains("tournament") || c.Key.Contains("season"))); Assert.AreEqual(1, _sportEventCache.SpecialTournaments.Count()); data01 = _sportDataCache.GetSportForTournamentAsync(nonExistingTournamentUrn, TestData.Cultures).Result; Assert.IsNull(data01); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllTournaments), $"{AllTournaments} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(AllSports), $"{AllSports} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(TestData.CacheSportCount, _sportDataCache.Sports.Count); Assert.AreEqual(TestData.CacheCategoryCountPlus, _sportDataCache.Categories.Count); Assert.AreEqual(TestData.CacheTournamentCount + 1, _sportEventCache.Cache.Count(c => c.Key.Contains("tournament") || c.Key.Contains("season"))); Assert.AreEqual(1, _sportEventCache.SpecialTournaments.Count()); Assert.IsNotNull(sports); Assert.IsNull(data01); }
public void SportDataCacheStatusTest() { var status = _sportDataCache.CacheStatus(); Assert.AreEqual(0, status["SportCI"]); Assert.AreEqual(0, status["CategoryCI"]); var sports = _sportDataCache.GetSportsAsync(TestData.Cultures).Result; // initial load Assert.IsNotNull(sports); status = _sportDataCache.CacheStatus(); Assert.AreEqual(TestData.CacheSportCount, status["SportCI"]); Assert.AreEqual(TestData.CacheCategoryCountPlus, status["CategoryCI"]); }
public void TestDataIsCachingTest() { const string callType = "GetAllSportsAsync"; _timer.FireOnce(TimeSpan.Zero); Thread.Sleep(500); var sports = _sportDataCache.GetSportsAsync(TestData.Cultures).Result; Assert.IsNotNull(sports, "Retrieved sports cannot be null"); Assert.IsTrue(sports.Any(), "sports.Count() > 0"); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly {TestData.Cultures.Count} times."); }