Пример #1
0
            protected int TestReadAndWrite(MessageSample sample, Action <TMessage> handler = null, Request request = null, bool suppressModification = false)
            {
                // argument checks
                Debug.Assert(sample != null);
                sample.CompleteArranging();
                // handler can be null
                // request can be null

                // state checks
                IAdapter adapter = this.Adapter;

                Debug.Assert(adapter != null);

                // create a Message and call Read and Write
                int messageCount = 0;

                using (TMessage message = adapter.Create(sample)) {
                    Assert.Equal(MessageReadingState.None, message.ReadingState);

                    // Read
                    while (adapter.Read(message, request))
                    {
                        Assert.Equal(MessageReadingState.Body, message.ReadingState);
                        ++messageCount;

                        // handle the message
                        handler?.Invoke(message);

                        // Write
                        adapter.Write(message, suppressModification);
                    }
                }

                return(messageCount);
            }
Пример #2
0
            public void ReadHeader_Empty()
            {
                using (Stream input = new MemoryStream()) {
                    MessageIO io      = new MessageIO(input, output: null);
                    IAdapter  adapter = this.Adapter;
                    using (TMessage message = adapter.Create(io)) {
                        // ACT
                        Debug.Assert(input.Length == 0);
                        bool actual = adapter.ReadHeader(message, null);

                        // ASSERT
                        Assert.Equal(false, actual);
                        Assert.Equal(MessageReadingState.None, message.ReadingState);
                    }
                }
            }
Пример #3
0
            protected int TestReadHeaderAndSkipBody(MessageSample sample, Action <TMessage> handler = null, Request request = null)
            {
                // argument checks
                Debug.Assert(sample != null);
                sample.CompleteArranging();
                // handler can be null
                // request can be null

                // state checks
                IAdapter adapter = this.Adapter;

                Debug.Assert(adapter != null);

                // create a Message and call ReadHeader and SkipBody
                int messageCount = 0;

                using (TMessage message = adapter.Create(sample)) {
                    Assert.Equal(MessageReadingState.None, message.ReadingState);

                    // ReadHeader
                    while (adapter.ReadHeader(message, request))
                    {
                        Assert.Equal(MessageReadingState.Header, message.ReadingState);
                        ++messageCount;

                        // handle the message
                        handler?.Invoke(message);

                        // SkipBody
                        adapter.SkipBody(message);
                        Assert.Equal(MessageReadingState.BodyRedirected, message.ReadingState);
                    }
                }

                return(messageCount);
            }