public void Parse_Success(string text, TimeSpan expected) { // arrange var parser = new DurationParser(new TokenEnumerator(new StringTokenReader(text))); // act var builder = new DurationBuilder(Reference); var result = parser.TryMake(builder); // assert Assert.True(result); Assert.Equal(expected, builder.Build()); }
public override T DeserializeImpl(IFudgeFieldContainer msg, IFudgeDeserializer deserializer) { UniqueId viewProcessId = GetUniqueId(msg, "viewProcessId"); UniqueId viewCycleId = GetUniqueId(msg, "viewCycleId"); var inputDataTimestamp = GetToDateTimeOffsetWithDefault(msg, "valuationTime"); var resultTimestamp = GetToDateTimeOffsetWithDefault(msg, "calculationTime"); TimeSpan calculationDuration = DurationBuilder.Build(msg.GetMessage("calculationDuration")).GetValueOrDefault(); //TODO strict once PLAT-1683 var configurationMap = new Dictionary <string, ViewCalculationResultModel>(); var keys = new Queue <string>(); var values = new Queue <ViewCalculationResultModel>(); foreach (var field in msg.GetMessage("results")) { switch (field.Ordinal) { case 1: string key = field.GetString(); if (!values.Any()) { keys.Enqueue(key); } else { configurationMap.Add(key, values.Dequeue()); } break; case 2: var mapAll = new Dictionary <ComputationTargetSpecification, ISet <ComputedValue> >(); foreach (var f in (IFudgeFieldContainer)field.Value) { var v = deserializer.FromField <ComputedValue>(f); ComputationTargetSpecification target = v.Specification.TargetSpecification; if (!mapAll.ContainsKey(target)) { mapAll.Add(target, new HashSet <ComputedValue>()); } mapAll[target].Add(v); } var value = new ViewCalculationResultModel(mapAll); if (!keys.Any()) { values.Enqueue(value); } else { configurationMap.Add(keys.Dequeue(), value); } break; default: throw new ArgumentException(); } } return(BuildObject(msg, deserializer, configurationMap, viewProcessId, viewCycleId, inputDataTimestamp, resultTimestamp, calculationDuration)); }