Esempio n. 1
0
        public async Task GivenStreamedMessages_Observable_PushesParsedMessages()
        {
            using (var stream = new MemoryStream())
            {
                var mockMessageParser = new MockMessageParser();
                int messages          = 0;
                var cancellation      = new CancellationTokenSource(TimeSpan.FromSeconds(5));
                TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();
                for (int i = 0; i < 10; i++)
                {
                    foreach (var sampleParams in SampleFixMessagesSource.GetTestTypeParentMessageBodies())
                    {
                        byte[] msg = new TestFixMessageBuilder(sampleParams[0] as string).Build();
                        await stream.WriteAsync(msg);
                    }
                }
                stream.Position = 0;

                var uut = new StreamParser <TestTypeParent>(stream, mockMessageParser, SupportedFixVersion.Fix44);

                uut.Subscribe(parsedObject => messages++, ex => taskCompletion.SetResult(false), () => taskCompletion.SetResult(true));
                var listener = Task.Run(() => uut.ListenAsync(cancellation.Token));

                Assert.True(await taskCompletion.Task);
                Assert.Equal(10 * SampleFixMessagesSource.GetTestTypeParentMessageBodies().Count(), messages);
                await listener;
            }
        }
Esempio n. 2
0
        public async Task GivenPipedMessages_Observable_PushesParsedMessages()
        {
            var pipe = new Pipe();
            var mockMessageParser = new MockMessageParser();
            int messages          = 0;
            var cancellation      = new CancellationTokenSource(TimeSpan.FromSeconds(5));
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            var uut = new PipeParser <TestTypeParent>(pipe.Reader, mockMessageParser, SupportedFixVersion.Fix44);

            uut.Subscribe(parsedObject => messages++, ex => taskCompletion.SetResult(false), () => taskCompletion.SetResult(true));
            var listener = Task.Run(() => uut.ListenAsync(cancellation.Token));

            // 10 loops to make sure we have more message then the default buffer can hold.
            for (int i = 0; i < 10; i++)
            {
                foreach (var sampleParams in SampleFixMessagesSource.GetTestTypeParentMessageBodies())
                {
                    byte[] msg = new TestFixMessageBuilder(sampleParams[0] as string).Build();
                    await pipe.Writer.WriteAsync(msg);
                }
            }
            await pipe.Writer.FlushAsync();

            pipe.Writer.Complete();

            Assert.True(await taskCompletion.Task);
            Assert.Equal(10 * SampleFixMessagesSource.GetTestTypeParentMessageBodies().Count(), messages);
            await listener;
        }
Esempio n. 3
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());
        }