public void ParserByNewParser() { byte[] message = new MessageBuilder().AddRaw("35=D|53=10|44=145|55=ABC|").Build(); // Create a property mapper and map types to be parsed. SubPropertySetterFactory is responsible creating the actual property setters. var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory()); propertyMapper.Map <Order>(); // Create the composite property setter. CompositePropertySetter is the delegator of the sub property setters. var compositeSetter = new CompositePropertySetter(); // Create a validator collection to have all default validators var validators = new ValidatorCollection(IntegerToFixConverter.Instance); // Passing empty options var options = new MessageParserOptions(); // Create TypedMessageParser, passing dependencies var parser = new TypedMessageParser <Order>(propertyMapper, compositeSetter, validators, options); Order order = parser.Parse(message); Console.WriteLine($"Order {order.Symbol} - Px {order.Price}, Qty {order.Quantity}"); }
public void GivenInValidWithNoThrow_Parse_DoesNotThrow() { var uut = new TypedMessageParser <TestTypeStruct>(Mock.Of <ITagToPropertyMapper>(), Mock.Of <ITypedPropertySetter>(), new MockValidator(false), Mock.Of <MessageParserOptions>()); var ex = Record.Exception(() => uut.Parse(new TestFixMessageBuilder(SampleBody).Build())); Assert.Null(ex); }
public void GivenInValidWithThrow_Parse_ThrowsArgumentException() { var uut = new TypedMessageParser <TestTypeStruct>(Mock.Of <ITagToPropertyMapper>(), Mock.Of <ITypedPropertySetter>(), new MockValidator(false), new MessageParserOptions() { ThrowIfInvalidMessage = true }); Assert.Throws <ArgumentException>(() => uut.Parse(new TestFixMessageBuilder(SampleBody).Build())); }
public void GivenMessage_Parse_ParsesReferenceType(string input) { byte[] message = new TestFixMessageBuilder(input).Build(); var uut = new TypedMessageParser <TestTypeParent>(new TagToPropertyMapper(new SubPropertySetterFactory()), new CompositePropertySetter(), new MockValidator(), Mock.Of <MessageParserOptions>()); var result = uut.Parse(message); Assert.NotNull(result); Assert.NotNull(result.Tag55); }
public void GivenMessage_Parse_ParsesStruct() { var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory()); propertyMapper.Map <TestTypeStruct>(); var uut = new TypedMessageParser <TestTypeStruct>(propertyMapper, new CompositePropertySetter(), new MockValidator(), Mock.Of <MessageParserOptions>()); var result = uut.Parse(new TestFixMessageBuilder(SampleBody).Build()); Assert.NotNull(result.Tag100); Assert.NotEqual(0, result.Tag101); Assert.NotEqual(0, result.Tag101); }