Ejemplo n.º 1
0
        public void VariantMarketDescriptionCacheIsCachingTest()
        {
            const string callType = "GetVariantMarketDescriptionAsync";

            Assert.AreEqual(0, _variantMemoryCache.Count());
            Assert.AreEqual(0, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly 0 times.");

            var market = _variantMdCache.GetMarketDescriptionAsync(10030, "lcoo:markettext:33421", TestData.Cultures).Result;

            Assert.IsNotNull(market);
            Assert.AreEqual(1, _variantMemoryCache.Count());
            Assert.AreEqual(3, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly 3 times.");

            market = _variantMdCache.GetMarketDescriptionAsync(10030, "lcoo:markettext:33421", TestData.Cultures).Result;
            Assert.IsNotNull(market);
            Assert.AreEqual(1, _variantMemoryCache.Count());
            Assert.AreEqual(3, _dataRouterManager.GetCallCount(callType), $"{callType} - no new call should be made.");
        }
Ejemplo n.º 2
0
        public void fixture_provider_is_called_only_once_for_each_locale()
        {
            var cacheItem = (IMatchCI)_sportEventCache.GetEventCacheItem(TestData.EventId);

            var task = Task.Run(async() =>
            {
                await cacheItem.GetBookingStatusAsync();
                await cacheItem.GetScheduledAsync();
                await cacheItem.GetScheduledEndAsync();
                await cacheItem.GetCompetitorsAsync(TestData.Cultures);
                await cacheItem.GetTournamentRoundAsync(TestData.Cultures);
                await cacheItem.GetSeasonAsync(TestData.Cultures);
                await cacheItem.GetTournamentIdAsync();
                await cacheItem.GetVenueAsync(TestData.Cultures);
                await cacheItem.GetFixtureAsync(TestData.Cultures);
                await cacheItem.GetReferenceIdsAsync();
            });

            Task.WaitAll(task);

            Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly {TestData.Cultures.Count} times.");
            Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventFixture), $"{SportEventFixture} should be called exactly {TestData.Cultures.Count} times.");
        }
Ejemplo n.º 3
0
        public void TestDataRouterManagerTest()
        {
            const string callType = "GetSportEventSummaryAsync";

            Assert.AreEqual(0, _dataRouterManager.GetCallCount(callType));
            _dataRouterManager.GetSportEventSummaryAsync(TournamentIdExtra, _cultureEn, null).ConfigureAwait(false);
            Assert.AreEqual(1, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly 1 time.");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void TestDataIsCaching()
        {
            // even if called several times, loads only once for all specified languages
            _timer.FireOnce(TimeSpan.Zero);
            _timer.FireOnce(TimeSpan.Zero);
            _timer.FireOnce(TimeSpan.Zero);

            var i = 0;

            while (_dataRouterManager.GetCallCount(DateSchedule) != (TestData.Cultures.Count * 3) && i < 100)
            {
                System.Threading.Thread.Sleep(100);
                i++;
            }
            Assert.IsTrue(_memoryCache.GetCount() > 0, "Nothing was cached.");
            Assert.AreEqual(ScheduleEventCount, _sportEventCache.Cache.Count(c => c.Key.Contains("match")), "cache item count is wrong");
            Assert.AreEqual(TestData.Cultures.Count * 3, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly {TestData.Cultures.Count * 3} times.");
        }
        public async Task SportDataCacheFullExportTest()
        {
            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.IsNotNull(sports);

            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.");


            var export = (await _sportDataCache.ExportAsync()).ToList();

            Assert.AreEqual(TestData.CacheSportCount + TestData.CacheCategoryCountPlus, export.Count);

            _sportDataCache.Sports.Clear();
            _sportDataCache.Categories.Clear();
            _sportDataCache.FetchedCultures.Clear();

            await _sportDataCache.ImportAsync(export);

            Assert.AreEqual(TestData.CacheSportCount, _sportDataCache.Sports.Count);
            Assert.AreEqual(TestData.CacheCategoryCountPlus, _sportDataCache.Categories.Count);

            // No calls to the data router manager
            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.");

            var exportString       = SerializeExportables(export);
            var secondExportString = SerializeExportables(await _sportDataCache.ExportAsync());

            Assert.AreEqual(exportString, secondExportString, "The first and the second export json are not equal");
        }
Ejemplo n.º 7
0
        public void player_profile_is_called_only_once()
        {
            const string callType = "GetPlayerProfileAsync";

            Assert.AreEqual(0, _memoryCache.Count());
            Assert.AreEqual(0, _dataRouterManager.GetCallCount(callType), $"{callType} should be called 0 time.");
            var name = _nameProvider.GetOutcomeNameAsync("sr:player:2", TestData.Cultures.First()).Result;

            Assert.AreEqual("Cole, Ashley", name, "The generated name is not correct");
            Assert.AreEqual(1, _memoryCache.Count());
            Assert.AreEqual(1, _dataRouterManager.GetCallCount(callType), $"{callType} should be called 1 time.");
        }
Ejemplo n.º 8
0
        public void player_profile_gets_cached()
        {
            const string callType = "GetPlayerProfileAsync";

            Assert.AreEqual(0, _dataRouterManager.GetCallCount(callType), "Should be called exactly 0 times.");
            Assert.IsTrue(!_memoryCache.Any());
            var player = _profileCache.GetPlayerProfileAsync(CreatePlayerUrn(1), TestData.Cultures).Result;

            Assert.IsNotNull(player);
            Assert.AreEqual(1, _memoryCache.Count());

            Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly {TestData.Cultures.Count} times.");

            //if we call again, should not fetch again
            player = _profileCache.GetPlayerProfileAsync(CreatePlayerUrn(1), TestData.Cultures).Result;
            Assert.IsNotNull(player);
            Assert.AreEqual(1, _memoryCache.Count());

            Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly {TestData.Cultures.Count} times.");
        }