Exemple #1
0
        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 MessageParser, passing dependencies
            var parser = new MessageParser(propertyMapper, compositeSetter, validators, options);

            Order order = parser.Parse <Order>(message);

            Console.WriteLine($"Order {order.Symbol} - Px {order.Price}, Qty {order.Quantity}");
        }
Exemple #2
0
        public void GivenType_Map_DoesNotThrow()
        {
            var uut       = new TagToPropertyMapper(new SubPropertySetterFactory());
            var exception = Record.Exception(() => uut.Map <TestTypeParent>());

            Assert.Null(exception);
        }
        public void Setup()
        {
            var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeParent>();

            _parser = new TypedStringMessageParser <TestTypeParent>(propertyMapper, new CompositePropertySetter(), new ValidatorCollection(IntegerToFixConverter.Instance), new RapideFix.Business.Data.MessageParserOptions());
        }
Exemple #4
0
        public void Setup()
        {
            _message = new TestFixMessageBuilder("35=A|101=345|102=128.79|").Build();
            var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeStruct>();

            _parser = new TypedMessageParser <TestTypeStruct>(propertyMapper, new CompositePropertySetter(), new ValidatorCollection(IntegerToFixConverter.Instance), new RapideFix.Business.Data.MessageParserOptions());
        }
Exemple #5
0
        public void Setup()
        {
            string sampleInput = SampleFixMessagesSource.GetTestTypeParentMessageBodies().First().First() as string;

            _message = new TestFixMessageBuilder(sampleInput).Build();
            var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeParent>();

            _parser = new MessageParser(propertyMapper, new CompositePropertySetter(), new ValidatorCollection(IntegerToFixConverter.Instance), new RapideFix.Business.Data.MessageParserOptions());
        }
Exemple #6
0
        public void GivenSimpleTag_Map_ReturnsTagWithNoParents()
        {
            var uut = new TagToPropertyMapper(new SubPropertySetterFactory());

            uut.Map <TestTypeParent>();
            uut.TryGet(55.ToKnownTag(), typeof(TestTypeParent).GetHashCode(), out TagMapLeaf result);

            Assert.False(result.IsEncoded);
            Assert.False(result.IsEnumerable);
            Assert.NotNull(result.Current);
            Assert.Null(result.Parents);
        }
Exemple #7
0
        public void GivenMessage_Parse_ParsesObject()
        {
            var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeParent>();
            var compositeSetter = new CompositePropertySetter();

            var uut    = new MessageParser(propertyMapper, compositeSetter, new MockValidator(), Mock.Of <MessageParserOptions>());
            var result = uut.Parse <TestTypeParent>(TestFixMessageBuilder.CreateDefaultMessage());

            Assert.NotNull(result);
        }
Exemple #8
0
        public void GivenComplexChildType_Map_ReturnsChildsTag()
        {
            var uut = new TagToPropertyMapper(new SubPropertySetterFactory());

            uut.Map <TestTypeParent>();
            uut.TryGet(58.ToKnownTag(), typeof(TestTypeParent).GetHashCode(), out TagMapLeaf result);

            Assert.False(result.IsEncoded);
            Assert.False(result.IsEnumerable);
            Assert.NotNull(result.Current);
            Assert.Single(result.Parents);
            Assert.False(result.Parents.First().IsEnumerable);
        }
Exemple #9
0
        public void GivenSampleMessage_Parse_ParsesObject(string input)
        {
            byte[] message        = new TestFixMessageBuilder(input).Build();
            var    propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeParent>();

            var uut    = new MessageParser(propertyMapper, new CompositePropertySetter(), new MockValidator(), Mock.Of <MessageParserOptions>());
            var result = uut.Parse(message) as TestTypeParent;

            Assert.NotNull(result);
            Assert.NotNull(result.Tag55);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        public async static Task Main(string[] args)
        {
            new GettingStarted().ParserSample();
            new TypedStringMessageParserSamples().Parser();
            new MessageParserSamples().ParserByParserBuilder();
            new MessageParserSamples().ParserByNewParser();
            new MessageParserSamples().ParserMultipleMessageTypes();
            new TypedMessageParserSamples().ParserByParserBuilder();
            new TypedMessageParserSamples().ParserByNewParser();
            new TypedMessageParserSamples().ParserValueType();
            new MessageBuilderSamples().AddTag();
            new MessageBuilderSamples().AddTagRaw();
            new MessageBuilderSamples().AddFixVersion();
            new MessageBuilderSamples().BuildSpan();
            await new PipeParserSamples().ParseMultipleMessages();

            //var settings = new FixParserSettings();
            //settings.RegisterMessageTypes<Order>();

            //var parser = new FixParser(settings);
            //parser.Parse<Order>("8=FIX.4.2|9=19|35=D|55=AAPL|54=1|10=186|1=account1|44=12.5|");

            string sampleInput    = "35=A|55=TestTag55|62=35|67=56.123|";
            var    message        = new MessageBuilder().AddRaw(sampleInput).Build();
            var    propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());

            propertyMapper.Map <TestTypeParent>();

            var parser = new MessageParser(propertyMapper, new CompositePropertySetter(), new ValidatorCollection(IntegerToFixConverter.Instance), new RapideFix.Business.Data.MessageParserOptions());

            parser.Parse <TestTypeParent>(message);
            parser.Parse <TestTypeParent>(message);
            parser.Parse <TestTypeParent>(message);
            parser.Parse <TestTypeParent>(message);

            Console.WriteLine("Wait");
            Thread.Sleep(3000);
            Console.WriteLine("Start");

            for (int i = 0; i < 1000000; i++)
            {
                parser.Parse <TestTypeParent>(message);
                parser.Parse <TestTypeParent>(message);
                parser.Parse <TestTypeParent>(message);
            }
        }
Exemple #12
0
        public void GivenRepeatingSimpleType_Map_ReturnsRepeating()
        {
            var uut = new TagToPropertyMapper(new SubPropertySetterFactory());

            uut.Map <TestTypeParent>();
            uut.TryGet(56.ToKnownTag(), typeof(TestTypeParent).GetHashCode(), out TagMapLeaf repeatingTag);
            uut.TryGet(57.ToKnownTag(), typeof(TestTypeParent).GetHashCode(), out TagMapLeaf actualTag);

            Assert.False(repeatingTag.IsEncoded);
            Assert.False(repeatingTag.IsEnumerable);
            Assert.NotNull(repeatingTag.Current);
            Assert.Null(repeatingTag.Parents);
            Assert.Null(repeatingTag.TypeConverterName);

            Assert.False(actualTag.IsEncoded);
            Assert.True(actualTag.IsEnumerable);
            Assert.NotNull(actualTag.Current);
            Assert.Null(actualTag.Parents);
            Assert.NotEqual(0, actualTag.RepeatingTagNumber);
        }
 public SetSinglePropertyTestsFixture()
 {
     PropertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory());
     PropertyMapper.Map <TestTypeParent>();
     CompositeSetter = new CompositePropertySetter();
 }