private static bool CompareMarketOutcomeSettlement(IReadOnlyList <IOutcomeSettlement> marketOutcomeSettlement, betSettlementMarketOutcome[] betOutcomes, AssertHelper assertHelper) { var mos = marketOutcomeSettlement.ToList(); if (mos.Count == 0 && betOutcomes.Length == 0) { return(true); } foreach (var b in betOutcomes) { foreach (var m in mos) { if (b.id == m.Id) { assertHelper.AreEqual(() => m.Id, b.id); assertHelper.AreEqual(() => m.DeadHeatFactor, b.dead_heat_factorSpecified ? (double?)b.dead_heat_factor : null); assertHelper.AreEqual(() => m.Result, b.result == 1); var voidFactor = (VoidFactor?)MessageMapperHelper.GetVoidFactor(b.void_factorSpecified, b.void_factor); assertHelper.AreEqual(() => m.VoidFactor, voidFactor); break; } } } return(true); }
/// <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)); }
public void VoidFactorsAreConverted() { var voidFactor = MessageMapperHelper.GetVoidFactor(true, 0); Assert.AreEqual(voidFactor, VoidFactor.Zero, "The value of voidFactor must be VoidFactor.ZERO"); voidFactor = MessageMapperHelper.GetVoidFactor(true, 0.5); Assert.AreEqual(voidFactor, VoidFactor.Half, "The value of voidFactor must be VoidFactor.Half"); voidFactor = MessageMapperHelper.GetVoidFactor(true, 1); Assert.AreEqual(voidFactor, VoidFactor.One, "The value of voidFactor must be VoidFactor.ONE"); voidFactor = MessageMapperHelper.GetVoidFactor(false, 0); Assert.AreEqual(voidFactor, VoidFactor.Zero, "The value of voidFactor must be VoidFactor.ZERO"); voidFactor = MessageMapperHelper.GetVoidFactor(false, 0.5); Assert.AreEqual(voidFactor, VoidFactor.Zero, "The value of voidFactor must be VoidFactor.ZERO"); voidFactor = MessageMapperHelper.GetVoidFactor(false, 1); Assert.AreEqual(voidFactor, VoidFactor.Zero, "The value of voidFactor must be VoidFactor.ZERO"); }
public void IncorrectVoidFactorsDoNotThrowWhenNotSpecified() { var voidFactor = MessageMapperHelper.GetVoidFactor(false, 0.7); Assert.AreEqual(voidFactor, VoidFactor.Zero, "The value of voidFactor must be VoidFactor.ZERO"); }
public void IncorrectVoidFactorsThrow() { MessageMapperHelper.GetVoidFactor(true, 0.7); }
/// <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)); }