public void TestClearBodyAppliesCorrectState()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            streamMessage.WriteObject(2);
            streamMessage.ClearBody();
            Assert.False(streamMessage.IsReadOnlyBody);
            streamMessage.WriteObject(2);

            Assert.Throws <MessageNotReadableException>(() => streamMessage.ReadObject());
        }
        public void TestNullStreamEntryResultsInExpectedBehaviour()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            streamMessage.WriteObject(null);
            streamMessage.Reset();

            // expect an NFE from the primitive integral, float, double, and char <type>.valueOf(null) conversions
            AssertGetStreamEntryThrowsNullReferenceException <byte>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <short>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <int>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <long>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <float>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <double>(streamMessage);
            AssertGetStreamEntryThrowsNullReferenceException <char>(streamMessage);

            // expect null
            Assert.Null(streamMessage.ReadObject());
            streamMessage.Reset(); // need to reset as read was a success
            Assert.Null(streamMessage.ReadString());
            streamMessage.Reset(); // need to reset as read was a success

            // expect completion value.
            Assert.AreEqual(-1, streamMessage.ReadBytes(new byte[1]));
            streamMessage.Reset(); // need to reset as read was a success

            // expect false
            Assert.False(streamMessage.ReadBoolean());
        }
        public void TestReadBytesWithNullSignalsCompletion()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            streamMessage.WriteObject(null);

            streamMessage.Reset();

            Assert.AreEqual(-1, streamMessage.ReadBytes(new byte[1]), "Expected immediate completion signal");
        }
        public void TestWriteReadObject()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            Object nullEntryValue   = null;
            bool   boolEntryValue   = false;
            byte   byteEntryValue   = 1;
            short  shortEntryValue  = 2;
            int    intEntryValue    = 3;
            long   longEntryValue   = 4;
            float  floatEntryValue  = 5.01f;
            double doubleEntryValue = 6.01d;
            string stringEntryValue = "string";
            char   charEntryValue   = 'c';

            byte[] bytes = { 1, 170, 65 };

            streamMessage.WriteObject(nullEntryValue);
            streamMessage.WriteObject(boolEntryValue);
            streamMessage.WriteObject(byteEntryValue);
            streamMessage.WriteObject(shortEntryValue);
            streamMessage.WriteObject(intEntryValue);
            streamMessage.WriteObject(longEntryValue);
            streamMessage.WriteObject(floatEntryValue);
            streamMessage.WriteObject(doubleEntryValue);
            streamMessage.WriteObject(stringEntryValue);
            streamMessage.WriteObject(charEntryValue);
            streamMessage.WriteObject(bytes);

            streamMessage.Reset();

            Assert.AreEqual(nullEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(boolEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(byteEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(shortEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(intEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(longEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(floatEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(doubleEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(stringEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            Assert.AreEqual(charEntryValue, streamMessage.ReadObject(), "Got unexpected value from stream");
            CollectionAssert.AreEqual(bytes, (byte[])streamMessage.ReadObject(), "Got unexpected value from stream");
        }
        public void TestWriteObjectWithIllegalTypeThrowsMFE()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            Assert.Throws <MessageFormatException>(() => streamMessage.WriteObject(1m));
        }
Пример #6
0
 public void WriteObject(object value)
 {
     message.WriteObject(value);
 }