/// <summary> /// Merges the specified event summary /// </summary> /// <param name="eventSummary">The event summary</param> /// <param name="culture">The culture</param> private void ActualMerge(MatchDTO eventSummary, CultureInfo culture) { base.Merge(eventSummary, culture, false); if (eventSummary.Season != null) { if (_season == null) { _season = new CacheItem(eventSummary.Season.Id, eventSummary.Season.Name, culture); } else { _season.Merge(eventSummary.Season, culture); } } if (eventSummary.Round != null) { if (_tournamentRound == null) { _tournamentRound = new RoundCI(eventSummary.Round, culture); } else { _tournamentRound.Merge(eventSummary.Round, culture); } } if (eventSummary.Tournament != null) { _tournamentId = eventSummary.Tournament.Id; } }
/// <summary> /// Initializes a new instance of the <see cref="MatchCI"/> class /// </summary> /// <param name="exportable">A <see cref="ExportableMatchCI" /> specifying the current instance</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain summary and fixture</param> /// <param name="semaphorePool">A <see cref="ISemaphorePool" /> instance used to obtain sync objects</param> /// <param name="defaultCulture">A <see cref="CultureInfo" /> specifying the language used when fetching info which is not translatable (e.g. Scheduled, ..)</param> /// <param name="fixtureTimestampCache">A <see cref="MemoryCache"/> used to cache the sport events fixture timestamps</param> public MatchCI(ExportableMatchCI exportable, IDataRouterManager dataRouterManager, ISemaphorePool semaphorePool, CultureInfo defaultCulture, MemoryCache fixtureTimestampCache) : base(exportable, dataRouterManager, semaphorePool, defaultCulture, fixtureTimestampCache) { _season = exportable.Season != null ? new CacheItem(exportable.Season) : null; _tournamentRound = exportable.TournamentRound != null ? new RoundCI(exportable.TournamentRound) : null; _tournamentId = exportable.TournamentId != null ? URN.Parse(exportable.TournamentId) : null; _fixture = exportable.Fixture != null ? new Fixture(exportable.Fixture) : null; _eventTimeline = exportable.EventTimeline != null ? new EventTimelineCI(exportable.EventTimeline) : null; _delayedInfo = exportable.DelayedInfo != null ? new DelayedInfoCI(exportable.DelayedInfo) : null; }
public void SportEventCacheItemMergeFixtureOnPreloadedItem() { Assert.AreEqual(0, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly 0 times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); TestDataIsCaching(); Assert.AreEqual(TestData.Cultures.Count * 3, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly {TestData.Cultures.Count * 3} times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); var item = (IMatchCI)_sportEventCache.GetEventCacheItem(TestData.EventId); Assert.IsNotNull(item); // preloaded with event summary with providers Assert.AreEqual(TestData.Cultures.Count * 3, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly {TestData.Cultures.Count * 3} times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); CacheItem info = null; Task.Run(async() => { await item.GetTournamentIdAsync(); info = await item.GetSeasonAsync(TestData.Cultures); await item.GetCompetitorsAsync(TestData.Cultures); }).GetAwaiter().GetResult(); Assert.AreEqual(TestData.Cultures.Count * 3, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly {TestData.Cultures.Count * 3} times."); //Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly {TestData.Cultures.Count} times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); Assert.IsNotNull(info); ValidateSportEventCacheItem(item, true); //merge fixture URN tourId = TestData.TournamentId; IFixture fixture = null; Task.Run(async() => { tourId = await item.GetTournamentIdAsync(); fixture = await item.GetFixtureAsync(TestData.Cultures); }).GetAwaiter().GetResult(); Assert.AreEqual(TestData.Cultures.Count * 3, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly {TestData.Cultures.Count * 3} times."); Assert.AreEqual(0, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly 0 times."); Assert.AreEqual("sr:tournament:1030", tourId.ToString()); Assert.IsNotNull(fixture); ValidateSportEventCacheItem(item, true); }
private static void ValidateSportEventCacheItem(IMatchCI item, bool ignoreDate = false) { Assert.IsNotNull(item, "Cached item not found."); Assert.AreEqual(TestData.EventId, item.Id); var date = new DateTime?(); List <URN> competitors = null; TeamCompetitorCI comp = null; RoundCI round = null; CacheItem season = null; Task.Run(async() => { date = await item.GetScheduledAsync(); competitors = (await item.GetCompetitorsAsync(TestData.Cultures)).ToList(); //comp = competitors.FirstOrDefault(); round = await item.GetTournamentRoundAsync(TestData.Cultures); season = await item.GetSeasonAsync(TestData.Cultures); }).GetAwaiter().GetResult(); Debug.Assert(date != null, "date != null"); if (!ignoreDate) { Assert.AreEqual(new DateTime(2016, 08, 10), new DateTime(date.Value.Year, date.Value.Month, date.Value.Day)); } Assert.AreEqual(2, competitors.Count); //TODO - this was removed if (comp != null) { Assert.AreEqual("sr:competitor:66390", comp.Id.ToString()); Assert.AreEqual(@"Pericos de Puebla", comp.GetName(TestData.Culture)); Assert.AreEqual("Mexico", comp.GetCountry(TestData.Culture)); Assert.AreNotEqual(comp.GetCountry(TestData.Culture), comp.GetCountry(new CultureInfo("de"))); } Assert.IsTrue(string.IsNullOrEmpty(round.GetName(TestData.Culture))); Assert.AreEqual(3, season.Name.Count); Assert.AreEqual("Mexican League 2016", season.Name[TestData.Culture]); }
public void Merge(BasicEventDTO dto, CultureInfo culture) { HomeScore = dto.HomeScore; AwayScore = dto.AwayScore; MatchTime = dto.MatchTime; Period = dto.Period; PeriodName = dto.PeriodName; Points = dto.Points; StoppageTime = dto.StoppageTime; Team = dto.Team; Type = dto.Type; Value = dto.Value; X = dto.X; Y = dto.Y; Time = dto.Time; if (dto.Assists != null && dto.Assists.Any()) { if (Assists == null || !Assists.Any()) { Assists = dto.Assists.Select(s => new EventPlayerAssistCI(s, culture)); } else { var newAssists = new List <EventPlayerAssistCI>(); foreach (var assist in dto.Assists) { var a = Assists.FirstOrDefault(f => Equals(f.Id, assist.Id)); if (a != null && a.Id.Equals(assist.Id)) { a.Merge(assist, culture); newAssists.Add(a); } else { newAssists.Add(new EventPlayerAssistCI(assist, culture)); } } Assists = newAssists; } } if (dto.GoalScorer != null) { if (GoalScorer == null) { GoalScorer = new CacheItem(dto.GoalScorer.Id, dto.GoalScorer.Name, culture); } else { GoalScorer.Merge(dto.GoalScorer, culture); } } if (dto.Player != null) { if (Player == null) { Player = new CacheItem(dto.Player.Id, dto.Player.Name, culture); } else { Player.Merge(dto.Player, culture); } } MatchStatusCode = dto.MatchStatusCode; MatchClock = dto.MatchClock; }