/// <summary> /// Gets the new <see cref="IMarketWithProbabilities"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param> /// <param name="producerId">A producerId specifying message producerId</param> /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns> protected virtual IMarketWithProbabilities GetMarketWithProbabilities(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(marketOddsChange.specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers); var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers); var nameProvider = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers); var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, producerId, sportId); var marketDefinition = new MarketDefinition(marketOddsChange.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy); return(new MarketWithProbabilities(marketOddsChange.id, specifiers, additionalInfo, nameProvider, mappingProvider, MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status), marketOddsChange.outcome? .Select(outcomeOdds => new OutcomeProbabilities( outcomeOdds.id, outcomeOdds.activeSpecified ? (bool?)(outcomeOdds.active != 0) : null, outcomeOdds.probabilitiesSpecified ? (double?)outcomeOdds.probabilities : null, nameProvider, mappingProvider, cultureInfos, new OutcomeDefinition(marketOddsChange.id, outcomeOdds.id, _marketCacheProvider, specifiers, cultureInfos, _externalExceptionStrategy))), marketDefinition, cultureInfos, marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null)); }
public void SingleSpecifiersIsParsedCorrectly() { var specifiers = FeedMapperHelper.GetSpecifiers("quarternr=4"); Assert.IsNotNull(specifiers, "specifier should not be null"); Assert.AreEqual("4", specifiers["quarternr"], "the value of the 'quarternr' specifier should be '4'"); }
/// <summary> /// Gets the new <see cref="IMarket"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="market">The <see cref="market"/> instance used</param> /// <param name = "producerId" > A producerId of the<see cref="ISportEvent"/></param> /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarket"/> instance</returns> protected virtual IMarketCancel GetMarketCancel(ISportEvent sportEvent, market market, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { Contract.Requires(sportEvent != null); Contract.Requires(market != null); Contract.Ensures(Contract.Result <IMarket>() != null); var specifiers = string.IsNullOrEmpty(market.specifiers) ? null : FeedMapperHelper.GetSpecifiers(market.specifiers); var additionalInfo = string.IsNullOrEmpty(market.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(market.extended_specifiers); var producer = _producerManager.Get(producerId); var cultureInfos = cultures.ToList(); return(new MarketCancel(market.id, specifiers, additionalInfo, _nameProviderFactory.BuildNameProvider(sportEvent, market.id, specifiers), _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, market.id, specifiers, _producerManager.Get(producerId), sportId), BuildMarketDefinition(market.id, sportId, producer, specifiers, cultureInfos), market.void_reasonSpecified ? market.void_reason : (int?)null, _voidReasonCache, cultureInfos)); }
/// <summary> /// Gets the new <see cref="IMarketWithOdds"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param> /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns> protected virtual IMarketWithOdds GetMarketWithOdds(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(marketOddsChange.specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers); var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers); var marketMetadata = marketOddsChange.market_metadata == null || !marketOddsChange.market_metadata.next_betstopSpecified ? new MarketMetadata(null) : new MarketMetadata(marketOddsChange.market_metadata.next_betstop); var producer = _producerManager.Get(producerId); var nameProvider = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers); var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, _producerManager.Get(producerId), sportId); return(new MarketWithOdds( marketOddsChange.id, specifiers, additionalInfo, nameProvider, mappingProvider, MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status), marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null, marketOddsChange.favouriteSpecified && marketOddsChange.favourite == 1, marketOddsChange.outcome?.Select(o => GetOutcomeWithOdds(sportEvent, nameProvider, mappingProvider, o, cultureInfos, BuildOutcomeDefinition(marketOddsChange.id, sportId, producer, specifiers, o.id, cultureInfos))), marketMetadata, BuildMarketDefinition(marketOddsChange.id, sportId, producer, specifiers, cultureInfos), cultureInfos)); }
/// <summary> /// Validates and parses the provided market specifiers /// </summary> /// <param name="message">The <see cref="FeedMessage"/> instance containing the market whose specifiers are being validated</param> /// <param name="market">A <see cref="FeedMarket"/> instance containing the specifiers to validate</param> /// <param name="marketIndex">The index of the <code>market</code> in the <code>message</code></param> private static bool ValidateSpecifiers(FeedMessage message, FeedMarket market, int marketIndex) { Contract.Requires(message != null); Contract.Requires(market != null); Contract.Requires(marketIndex >= 0); if (string.IsNullOrEmpty(market.SpecifierString)) { return(true); } try { market.Specifiers = FeedMapperHelper.GetSpecifiers(market.SpecifierString); return(true); } catch (Exception ex) { if (ex is FormatException || ex is ArgumentException) { market.ValidationFailed = true; LogWarning(message, $"markets[{marketIndex}].specifiers", market.SpecifierString); return(false); } throw; } }
/// <summary> /// Validates and parses the provided market specifiers /// </summary> /// <param name="message">The <see cref="FeedMessage"/> instance containing the market whose specifiers are being validated</param> /// <param name="market">A <see cref="FeedMarket"/> instance containing the specifiers to validate</param> /// <param name="marketIndex">The index of the <code>market</code> in the <code>message</code></param> private static bool ValidateSpecifiers(FeedMessage message, FeedMarket market, int marketIndex) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(market, nameof(market)).NotNull(); Guard.Argument(marketIndex).NotNegative(); if (string.IsNullOrEmpty(market.SpecifierString)) { return(true); } try { market.Specifiers = FeedMapperHelper.GetSpecifiers(market.SpecifierString); return(true); } catch (Exception ex) { if (ex is FormatException || ex is ArgumentException) { market.ValidationFailed = true; LogWarning(message, $"markets[{marketIndex}].specifiers", market.SpecifierString); return(false); } throw; } }
/// <summary> /// Gets the new <see cref="IMarket"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="market">The <see cref="market"/> instance used</param> /// <param name = "producerId" > A producerId of the<see cref="ISportEvent"/></param> /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarket"/> instance</returns> protected virtual IMarketCancel GetMarketCancel(ISportEvent sportEvent, market market, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { Guard.Argument(sportEvent, nameof(sportEvent)).NotNull(); Guard.Argument(market, nameof(market)).NotNull(); var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(market.specifiers) ? null : FeedMapperHelper.GetSpecifiers(market.specifiers); var additionalInfo = string.IsNullOrEmpty(market.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(market.extended_specifiers); var marketDefinition = new MarketDefinition(market.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy); return(new MarketCancel(market.id, specifiers, additionalInfo, _nameProviderFactory.BuildNameProvider(sportEvent, market.id, specifiers), _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, market.id, specifiers, producerId, sportId), marketDefinition, market.void_reasonSpecified ? market.void_reason : (int?)null, _voidReasonCache, cultureInfos)); }
public void false_is_returned_when_any_validator_returns_false() { var validator = _factory.Build("setnr=1|gamenr=1|total~*.5"); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=2|gamenr=1|total=1.5"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=1|gamenr=2|total=1.5"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=1|gamenr=1|total=1.75"))); }
public void LeadingAndTrailingSpacesAreIgnored() { var specifiers = FeedMapperHelper.GetSpecifiers(" quarternr =1|periodnr= 2 | score = 3 "); Assert.AreEqual(3, specifiers.Count, "specifier.Count must be 3"); Assert.AreEqual("1", specifiers["quarternr"], "Value of the 'quarternr' specifier must be '1'"); Assert.AreEqual("2", specifiers["periodnr"], "Value of the 'periodnr' specifier must be '2'"); Assert.AreEqual("3", specifiers["score"], "Value of the 'score' specifier must be '3'"); }
public void MultipleSpecifiersAreParsedCorrectly() { var specifiers = FeedMapperHelper.GetSpecifiers("quarternr=4|periodnr=1"); Assert.AreEqual(2, specifiers.Count, "specifier count must be 2"); Assert.AreEqual("4", specifiers["quarternr"], "Value of the 'quarternr' specifier must be '4'"); Assert.AreEqual("1", specifiers["periodnr"], "Value of the 'periodnr' specifier must be 1"); }
public void validation_of_incorrect_values_returns_false_for_X5() { var validator = _factory.Build("total~*.5"); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=0"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=0.25"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=0.75"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=1"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=2.25"))); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=15.75"))); }
public void validation_of_correct_values_returns_true_for_X75() { var validator = _factory.Build("total~*.75"); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=0.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=1.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=2.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=3.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=5.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=17.75"))); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("total=100.75"))); }
/// <summary> /// Gets the new <see cref="IMarketWithSettlement"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="marketSettlement">The <see cref="betSettlementMarket"/> instance used</param> /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="sportId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarketWithSettlement"/> instance</returns> protected virtual IMarketWithSettlement GetMarketWithResults(ISportEvent sportEvent, betSettlementMarket marketSettlement, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { Guard.Argument(sportEvent, nameof(sportEvent)).NotNull(); Guard.Argument(marketSettlement, nameof(marketSettlement)).NotNull(); var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(marketSettlement.specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketSettlement.specifiers); var additionalInfo = string.IsNullOrEmpty(marketSettlement.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketSettlement.extended_specifiers); var nameProvider = _nameProviderFactory.BuildNameProvider(sportEvent, marketSettlement.id, specifiers); var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketSettlement.id, specifiers, producerId, sportId); var outcomes = (IEnumerable <IOutcomeSettlement>)marketSettlement.Items?.Select(outcome => new OutcomeSettlement( outcome.dead_heat_factorSpecified ? (double?)outcome.dead_heat_factor : null, outcome.id, outcome.result, MessageMapperHelper.GetVoidFactor(outcome.void_factorSpecified, outcome.void_factor), nameProvider, mappingProvider, cultureInfos, new OutcomeDefinition(marketSettlement.id, outcome.id, _marketCacheProvider, specifiers, cultureInfos, _externalExceptionStrategy))) ?? new List <IOutcomeSettlement>(); var marketDefinition = new MarketDefinition(marketSettlement.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy); return(new MarketWithSettlement(marketSettlement.id, specifiers, additionalInfo, outcomes, nameProvider, mappingProvider, marketDefinition, marketSettlement.void_reasonSpecified ? (int?)marketSettlement.void_reason : null, _namedValuesProvider.VoidReasons, cultureInfos)); }
/// <summary> /// Gets the new <see cref="IMarketWithSettlement"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="marketSettlement">The <see cref="betSettlementMarket"/> instance used</param> /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="sportId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarketWithSettlement"/> instance</returns> protected virtual IMarketWithSettlement GetMarketWithResults(ISportEvent sportEvent, betSettlementMarket marketSettlement, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { Contract.Requires(sportEvent != null, "SportEvent missing"); Contract.Requires(marketSettlement != null, "marketSettlement != null"); Contract.Ensures(Contract.Result <IMarketWithSettlement>() != null, "Contract.Result<IMarketWithSettlement>() != null"); var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(marketSettlement.specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketSettlement.specifiers); var additionalInfo = string.IsNullOrEmpty(marketSettlement.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketSettlement.extended_specifiers); var producer = _producerManager.Get(producerId); var nameProvider = _nameProviderFactory.BuildNameProvider(sportEvent, marketSettlement.id, specifiers); var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketSettlement.id, specifiers, _producerManager.Get(producerId), sportId); var outcomes = marketSettlement.Items.Select(outcome => new OutcomeSettlement( outcome.dead_heat_factorSpecified ? (double?)outcome.dead_heat_factor : null, outcome.id, outcome.result != 0, MessageMapperHelper.GetVoidFactor(outcome.void_factorSpecified, outcome.void_factor), nameProvider, mappingProvider, cultureInfos, BuildOutcomeDefinition(marketSettlement.id, sportId, producer, specifiers, outcome.id, cultureInfos))); return(new MarketWithSettlement(marketSettlement.id, specifiers, additionalInfo, outcomes, nameProvider, mappingProvider, BuildMarketDefinition(marketSettlement.id, sportId, producer, specifiers, cultureInfos), marketSettlement.void_reasonSpecified ? (int?)marketSettlement.void_reason : null, _namedValuesProvider.VoidReasons, cultureInfos)); }
/// <summary> /// Gets the new <see cref="IMarketWithOdds"/> instance /// </summary> /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param> /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param> /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param> /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param> /// <param name="cultures">The list of cultures that should be prefetched</param> /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns> protected virtual IMarketWithOdds GetMarketWithOdds(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures) { var cultureInfos = cultures.ToList(); var specifiers = string.IsNullOrEmpty(marketOddsChange.specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers); var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers) ? null : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers); var marketMetadata = new MarketMetadata(marketOddsChange.market_metadata); var nameProvider = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers); var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, producerId, sportId); var outcomes = marketOddsChange.outcome?.Select(outcome => GetOutcomeWithOdds(sportEvent, nameProvider, mappingProvider, outcome, cultureInfos, new OutcomeDefinition(marketOddsChange.id, outcome.id, _marketCacheProvider, specifiers, cultureInfos, _externalExceptionStrategy))); var marketDefinition = new MarketDefinition(marketOddsChange.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy); return(new MarketWithOdds(marketOddsChange.id, specifiers, additionalInfo, nameProvider, mappingProvider, MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status), marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null, marketOddsChange.favouriteSpecified && marketOddsChange.favourite == 1, outcomes, marketMetadata, marketDefinition, cultureInfos)); }
public void EmptySpecifierNameThrowsAnException() { FeedMapperHelper.GetSpecifiers("=4"); }
public void specifier_with_non_decimal_value_causes_exception() { var validator = _factory.Build("setnr=1|total~*.75"); validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=1|total=zero")); }
public void missing_specifier_causes_exception() { var validator = _factory.Build("setnr=1|total~*.75"); validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=1")); }
public void SpecifierNameMustNotHaveSpacesOnly() { FeedMapperHelper.GetSpecifiers(" =4"); }
public void true_is_returned_when_all_validators_return_true() { var validator = _factory.Build("setnr=1|gamenr=1|total~*.5"); Assert.IsTrue(validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=1|gamenr=1|total=1.5"))); }
public void validation_of_correct_value_returns_false() { var validator = _factory.Build("setnr=1"); Assert.IsFalse(validator.Validate(FeedMapperHelper.GetValidForAttributes("setnr=2"))); }
public void DuplicatedSpecifiersAreNotAllowed() { var specifiers = FeedMapperHelper.GetSpecifiers("score=1| score =1"); Assert.IsNotNull(specifiers); }
public void EmptySpecifierValueThrowsAnException() { FeedMapperHelper.GetSpecifiers("periodnr="); }
public void SpecifierValueMustNotHaveSpacesOnly() { FeedMapperHelper.GetSpecifiers("periodnr= "); }