示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompetitionCI" /> class
        /// </summary>
        /// <param name="exportable">A <see cref="ExportableSportEventCI" /> representing the sport event</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 CompetitionCI(ExportableSportEventCI exportable,
                             IDataRouterManager dataRouterManager,
                             ISemaphorePool semaphorePool,
                             CultureInfo defaultCulture,
                             MemoryCache fixtureTimestampCache)
            : base(exportable, dataRouterManager, semaphorePool, defaultCulture, fixtureTimestampCache)
        {
            Guard.Argument(exportable, nameof(exportable)).NotNull();

            var exportableCompetition = exportable as ExportableCompetitionCI;

            if (exportableCompetition != null)
            {
                _bookingStatus = exportableCompetition.BookingStatus;
                _venue         = exportableCompetition.Venue != null ? new VenueCI(exportableCompetition.Venue) : null;
                _conditions    = exportableCompetition.Conditions != null
                    ? new SportEventConditionsCI(exportableCompetition.Conditions)
                    : null;
                Competitors = exportableCompetition.Competitors != null
                    ? new List <URN>(exportableCompetition.Competitors.Select(URN.Parse))
                    : null;
                _referenceId = exportableCompetition.ReferenceId != null
                    ? new ReferenceIdCI(exportableCompetition.ReferenceId)
                    : null;
                _competitorsQualifiers = exportableCompetition.CompetitorsQualifiers != null
                    ? new Dictionary <URN, string>(
                    exportableCompetition.CompetitorsQualifiers.ToDictionary(c => URN.Parse(c.Key), c => c.Value))
                    : null;
                _competitorsReferences = exportableCompetition.CompetitorsReferences != null
                    ? new Dictionary <URN, ReferenceIdCI>(
                    exportableCompetition.CompetitorsReferences.ToDictionary(c => URN.Parse(c.Key),
                                                                             c => new ReferenceIdCI(c.Value)))
                    : null;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SportEventConditions"/> class
        /// </summary>
        /// <param name="ci">A <see cref="SportEventConditionsCI"/> used to create new instance</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying the supported languages of the constructed instance</param>
        public SportEventConditions(SportEventConditionsCI ci, IEnumerable <CultureInfo> cultures)
        {
            Guard.Argument(ci, nameof(ci)).NotNull();
            Guard.Argument(cultures, nameof(cultures)).NotNull();//.NotEmpty();
            if (!cultures.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(cultures));
            }

            Attendance = ci.Attendance;
            EventMode  = ci.EventMode;
            if (ci.Referee != null)
            {
                Referee = new Referee(ci.Referee, cultures);
            }
            if (ci.WeatherInfo != null)
            {
                WeatherInfo = new WeatherInfo(ci.WeatherInfo);
            }

            if (ci.Pitchers != null)
            {
                Pitchers = ci.Pitchers.Select(s => new Pitcher(s));
            }
        }
示例#3
0
        public void SportEventConditionsTest()
        {
            var venue1 = new venue
            {
                id                = "sr:venue:1",
                capacity          = 1,
                capacitySpecified = true,
                city_name         = "my city",
                country_name      = "my country",
                map_coordinates   = "coordinates",
                name              = "venue name",
            };

            var weatherInfo1 = new weatherInfo
            {
                pitch = "my pitch",
                temperature_celsius          = 40,
                temperature_celsiusSpecified = true,
                weather_conditions           = "my weather conditions",
                wind           = "strong",
                wind_advantage = "none"
            };

            var sportEventConditionType = new sportEventConditions
            {
                attendance = "all",
                match_mode = "full mode",
                referee    = new referee
                {
                    id          = "sr:referee:1",
                    name        = "John Doe",
                    nationality = "German",
                },
                venue        = venue1,
                weather_info = weatherInfo1
            };

            var sportEventConditionsDTO = new SportEventConditionsDTO(sportEventConditionType);
            var sportEventConditionsCI  = new SportEventConditionsCI(sportEventConditionsDTO, _cultureFirst);

            Assert.IsNotNull(sportEventConditionsCI);
            Assert.AreEqual(sportEventConditionType.attendance, sportEventConditionsCI.Attendance);
            Assert.AreEqual(sportEventConditionType.match_mode, sportEventConditionsCI.EventMode);
            Assert.AreEqual(sportEventConditionType.referee.id, sportEventConditionsCI.Referee.Id.ToString());
            Assert.AreEqual(sportEventConditionType.referee.name, sportEventConditionsCI.Referee.Name);
            Assert.AreEqual(sportEventConditionType.referee.nationality, sportEventConditionsCI.Referee.GetNationality(_cultureFirst));

            //Assert.AreEqual(sportEventConditionType.venue.id, sportEventConditionsCI.); TODO: missing Venue

            Assert.AreEqual(sportEventConditionType.weather_info.pitch, sportEventConditionsCI.WeatherInfo.Pitch);
            Assert.AreEqual(sportEventConditionType.weather_info.temperature_celsius, sportEventConditionsCI.WeatherInfo.TemperatureCelsius);
            Assert.AreEqual(sportEventConditionType.weather_info.weather_conditions, sportEventConditionsCI.WeatherInfo.WeatherConditions);
            Assert.AreEqual(sportEventConditionType.weather_info.wind, sportEventConditionsCI.WeatherInfo.Wind);
            Assert.AreEqual(sportEventConditionType.weather_info.wind_advantage, sportEventConditionsCI.WeatherInfo.WindAdvantage);
        }
示例#4
0
        /// <summary>
        /// Merges the specified event summary
        /// </summary>
        /// <param name="eventSummary">The event summary</param>
        /// <param name="culture">The culture</param>
        private void ActualMerge(CompetitionDTO eventSummary, CultureInfo culture)
        {
            base.Merge(eventSummary, culture, false);

            if (eventSummary.Venue != null)
            {
                if (_venue == null)
                {
                    _venue = new VenueCI(eventSummary.Venue, culture);
                }
                else
                {
                    _venue.Merge(eventSummary.Venue, culture);
                }
            }
            if (eventSummary.Conditions != null)
            {
                if (_conditions == null)
                {
                    _conditions = new SportEventConditionsCI(eventSummary.Conditions, culture);
                }
                else
                {
                    _conditions.Merge(eventSummary.Conditions, culture);
                }
            }
            if (eventSummary.Competitors != null)
            {
                Competitors = new List <URN>(eventSummary.Competitors.Select(t => t.Id));
                GenerateMatchName(eventSummary.Competitors, culture);
                FillCompetitorsQualifiers(eventSummary.Competitors);
                FillCompetitorsReferences(eventSummary.Competitors);
                FillCompetitorsVirtual(eventSummary.Competitors);
            }
            if (eventSummary.BookingStatus != null)
            {
                _bookingStatus = eventSummary.BookingStatus;
            }
            if (!string.IsNullOrEmpty(eventSummary.LiveOdds))
            {
                _liveOdds = eventSummary.LiveOdds;
            }
            if (eventSummary.Type != null)
            {
                _sportEventType = eventSummary.Type;
            }
            if (eventSummary.StageType != null)
            {
                _stageType = eventSummary.StageType;
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="SportEventConditions" /> class
        /// </summary>
        /// <param name="ci">A <see cref="SportEventConditionsCI" /> used to create new instance</param>
        /// <param name="cultures">A <see cref="IEnumerable{T}" /> specifying the supported languages of the constructed instance</param>
        public SportEventConditions(SportEventConditionsCI ci, IEnumerable <CultureInfo> cultures)
        {
            Contract.Requires(ci != null);
            Contract.Requires(cultures != null && cultures.Any());
            Attendance = ci.Attendance;
            EventMode  = ci.EventMode;
            if (ci.Referee != null)
            {
                Referee = new Referee(ci.Referee, cultures);
            }
            if (ci.WeatherInfo != null)
            {
                WeatherInfo = new WeatherInfo(ci.WeatherInfo);
            }

            if (ci.Pitchers != null)
            {
                Pitchers = ci.Pitchers.Select(s => new Pitcher(s));
            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompetitionCI" /> class
        /// </summary>
        /// <param name="exportable">A <see cref="ExportableSportEventCI" /> representing the sport event</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="ObjectCache"/> used to cache the sport events fixture timestamps</param>
        public CompetitionCI(ExportableSportEventCI exportable,
                             IDataRouterManager dataRouterManager,
                             ISemaphorePool semaphorePool,
                             CultureInfo defaultCulture,
                             ObjectCache fixtureTimestampCache)
            : base(exportable, dataRouterManager, semaphorePool, defaultCulture, fixtureTimestampCache)
        {
            var exportableCompetition = exportable as ExportableCompetitionCI;

            if (exportableCompetition != null)
            {
                _bookingStatus = exportableCompetition.BookingStatus;
                _venue         = exportableCompetition.Venue != null ? new VenueCI(exportableCompetition.Venue) : null;
                _conditions    = exportableCompetition.Conditions != null
                    ? new SportEventConditionsCI(exportableCompetition.Conditions)
                    : null;
                Competitors = exportableCompetition.Competitors != null
                    ? new List <URN>(exportableCompetition.Competitors.Select(URN.Parse))
                    : null;
                _referenceId = exportableCompetition.ReferenceId != null
                    ? new ReferenceIdCI(exportableCompetition.ReferenceId)
                    : null;
                _competitorsQualifiers = exportableCompetition.CompetitorsQualifiers != null
                    ? new Dictionary <URN, string>(
                    exportableCompetition.CompetitorsQualifiers.ToDictionary(c => URN.Parse(c.Key), c => c.Value))
                    : null;
                _competitorsReferences = exportableCompetition.CompetitorsReferences != null
                    ? new Dictionary <URN, ReferenceIdCI>(
                    exportableCompetition.CompetitorsReferences.ToDictionary(c => URN.Parse(c.Key),
                                                                             c => new ReferenceIdCI(c.Value)))
                    : null;
                _competitorsVirtual = exportableCompetition.CompetitorsVirtual != null
                                          ? exportableCompetition.CompetitorsVirtual.Select(URN.Parse).ToList()
                                          : new List <URN>();

                _liveOdds       = string.IsNullOrEmpty(exportableCompetition.LiveOdds) ? null : exportableCompetition.LiveOdds;
                _sportEventType = exportableCompetition.SportEventType;
                _stageType      = exportableCompetition.StageType;
            }
        }
示例#7
0
        public void SportEventCacheItemMergeDetails()
        {
            var item = (IMatchCI)_sportEventCache.GetEventCacheItem(TestData.EventId);

            Assert.IsNotNull(item); // empty with providers
            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.");

            SportEventConditionsCI cons = null;

            Task.Run(async() =>
            {
                cons = await item.GetConditionsAsync(TestData.Cultures);
                cons = await item.GetConditionsAsync(TestData.Cultures);
                await item.GetCompetitorsIdsAsync(TestData.Cultures);
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(cons);
            Assert.AreEqual(0, _dataRouterManager.GetCallCount(DateSchedule), $"{DateSchedule} should be called exactly 0 times.");
            Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(SportEventSummary), $"{SportEventSummary} should be called exactly {TestData.Cultures.Count} times.");

            ValidateSportEventCacheItem(item, true);
        }