Пример #1
0
        public void TestStreamingDecoderFailures()
        {
            foreach (var entry in _negativeEncodedTestCases)
            {
                var decoder = new EventStreamDecoder();
                decoder.MessageReceived += DecoderDidNotFail;

                try
                {
                    decoder.ProcessData(entry.Value, 0, entry.Value.Length);
                    Assert.Fail("The decoder should have failed on write of invalid data.");
                }
                catch (Exception)
                {
                    try
                    {
                        decoder.ProcessData(entry.Value, 0, entry.Value.Length);
                        Assert.Fail("Calling decode on a decoder that has failed, should throw and exception");
                    }
                    catch (EventStreamDecoderIllegalStateException ex)
                    {
                    }
                }
            }
        }
Пример #2
0
        public void TestStreamingDecoder()
        {
            using (var memoryStream = new MemoryStream())
            {
                foreach (var entry in _positiveEncodedTestCases)
                {
                    memoryStream.Write(entry.Value, 0, entry.Value.Length);
                }

                memoryStream.Position = 0;

                var decoder = new EventStreamDecoder();
                decoder.MessageReceived += Decoder_MessageReceived;

                var buffer = new byte[128];
                var read   = 0;
                while ((read = memoryStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    decoder.ProcessData(buffer, 0, read);
                }
            }

            Assert.AreEqual(_positiveEncodedTestCases.Count, _decoderMessages.Count);
            var index = 0;

            foreach (var messageBuffer in _positiveEncodedTestCases.Values)
            {
                CollectionAssert.AreEqual(messageBuffer, _decoderMessages[index++].ToByteArray());
            }
        }