private static void ValidateMapping(mappingsMapping msg, MarketMappingCacheItem ci) { var ciMarketId = ci.MarketSubTypeId == null?ci.MarketTypeId.ToString() : $"{ci.MarketTypeId}:{ci.MarketSubTypeId}"; Assert.AreEqual(msg.market_id, ciMarketId); if (!string.IsNullOrEmpty(msg.product_ids)) { var ids = msg.product_ids.Split(new[] { SdkInfo.MarketMappingProductsDelimiter }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList(); Assert.AreEqual(ids.Count, ci.ProducerIds.Count()); foreach (var id in ids) { Assert.IsTrue(ci.ProducerIds.Contains(id), $"Missing producerId:{id}."); } } else { Assert.AreEqual(1, ci.ProducerIds.Count()); Assert.AreEqual(msg.product_id, ci.ProducerIds.First()); } Assert.AreEqual(msg.sport_id, ci.SportId.ToString()); Assert.AreEqual(msg.sov_template, ci.SovTemplate); Assert.AreEqual(msg.valid_for, ci.Validator.ToString()); if (msg.mapping_outcome != null) { Assert.AreEqual(msg.mapping_outcome.Length, ci.OutcomeMappings.Count()); for (var i = 0; i < msg.mapping_outcome.Length; i++) { ValidateMappingOutcome(msg.mapping_outcome[i], ci.OutcomeMappings.ToArray()[i]); } } }
internal MarketMappingDTO(mappingsMapping mapping) { Guard.Argument(mapping, nameof(mapping)).NotNull(); Guard.Argument(mapping.product_id, nameof(mapping.product_id)).Positive(); Guard.Argument(mapping.sport_id, nameof(mapping.sport_id)).NotNull().NotEmpty(); Guard.Argument(mapping.market_id, nameof(mapping.market_id)).NotNull().NotEmpty(); ProducerIds = string.IsNullOrEmpty(mapping.product_ids) ? new[] { mapping.product_id } : mapping.product_ids.Split(new[] { SdkInfo.MarketMappingProductsDelimiter }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse); SportId = mapping.sport_id == "all" ? null : URN.Parse(mapping.sport_id); OrgMarketId = null; var marketId = mapping.market_id.Split(':'); // legacy int typeId; int.TryParse(marketId[0], out typeId); MarketTypeId = typeId; if (marketId.Length == 2) { int subTypeId; MarketSubTypeId = int.TryParse(marketId[1], out subTypeId) ? subTypeId : (int?)null; } SovTemplate = mapping.sov_template; ValidFor = mapping.valid_for; OutcomeMappings = new List <OutcomeMappingDTO>(); if (mapping.mapping_outcome != null) { OutcomeMappings = mapping.mapping_outcome.Select(o => new OutcomeMappingDTO(o, mapping.market_id)); } }
internal MarketMappingDTO(mappingsMapping mapping) { Contract.Requires(mapping != null); Contract.Requires(mapping.product_id > 0); Contract.Requires(!string.IsNullOrEmpty(mapping.sport_id)); Contract.Requires(!string.IsNullOrEmpty(mapping.market_id)); ProducerId = mapping.product_id; ProducerIds = string.IsNullOrEmpty(mapping.product_ids) ? new[] { mapping.product_id } : mapping.product_ids .Split(new[] { SdkInfo.MarketMappingProductsDelimiter }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse); SportId = mapping.sport_id == "all" ? null : URN.Parse(mapping.sport_id); OrgMarketId = null; var marketId = mapping.market_id.Split(':'); // legacy int typeId; int.TryParse(marketId[0], out typeId); MarketTypeId = typeId; if (marketId.Length == 2) { int subTypeId; MarketSubTypeId = int.TryParse(marketId[1], out subTypeId) ? subTypeId : (int?)null; } SovTemplate = mapping.sov_template; ValidFor = mapping.valid_for; if (mapping.mapping_outcome != null) { OutcomeMappings = mapping.mapping_outcome.Select(o => new OutcomeMappingDTO(o, mapping.market_id)); } }
private static void ValidateMapping(mappingsMapping msg, MarketMappingDTO dto) { var dtoMarketId = dto.MarketSubTypeId == null?dto.MarketTypeId.ToString() : $"{dto.MarketTypeId}:{dto.MarketSubTypeId}"; Assert.AreEqual(msg.market_id, dtoMarketId); Assert.AreEqual(msg.sport_id, dto.SportId.ToString()); Assert.AreEqual(msg.sov_template, dto.SovTemplate); Assert.AreEqual(msg.valid_for, dto.ValidFor); if (msg.mapping_outcome != null) { Assert.AreEqual(msg.mapping_outcome.Length, dto.OutcomeMappings.Count()); for (var i = 0; i < msg.mapping_outcome.Length; i++) { ValidateMappingOutcome(msg.mapping_outcome[i], dto.OutcomeMappings.ToArray()[i]); } } }
internal MarketMappingDTO(mappingsMapping mapping) { Guard.Argument(mapping, nameof(mapping)).NotNull(); Guard.Argument(mapping.product_id, nameof(mapping.product_id)).Positive(); Guard.Argument(mapping.sport_id, nameof(mapping.sport_id)).NotNull().NotEmpty(); Guard.Argument(mapping.market_id, nameof(mapping.market_id)).NotNull().NotEmpty(); ProductId = mapping.product_id; SportId = mapping.sport_id == "all" ? null : URN.Parse(mapping.sport_id); var marketId = mapping.market_id.Split(':'); int.TryParse(marketId[0], out _typeId); if (marketId.Length == 2) { int.TryParse(marketId[1], out _subTypeId); } SovTemplate = mapping.sov_template; ValidFor = mapping.valid_for; if (mapping.mapping_outcome != null) { OutcomeMappings = mapping.mapping_outcome.Select(o => new OutcomeMappingDTO(o)); } }