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 TestWriteReadString()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            string value = "myString";

            streamMessage.WriteString(value);
            streamMessage.Reset();

            Assert.AreEqual(value, streamMessage.ReadString(), "Value not as expected");
        }
        public void TestIllegalTypeConversionFailureDoesNotIncrementPosition2()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            String stringVal = "myString";

            streamMessage.WriteString(stringVal);
            streamMessage.Reset();

            AssertGetStreamEntryThrowsMessageFormatException <byte[]>(streamMessage);

            Assert.AreEqual(stringVal, streamMessage.ReadString(), "Expected written string");
        }
        public void TestReadBigString()
        {
            NmsStreamMessage streamMessage = factory.CreateStreamMessage();

            StringBuilder stringBuilder = new StringBuilder(1024 * 1024);

            for (int i = 0; i < 1024 * 1024; i++)
            {
                stringBuilder.Append('a' + i % 26);
            }

            string bigString = stringBuilder.ToString();

            streamMessage.WriteString(bigString);
            streamMessage.Reset();
            Assert.AreEqual(bigString, streamMessage.ReadString());
        }
        private object GetStreamEntryUsingTypeMethod(NmsStreamMessage testMessage, Type type, byte[] destination)
        {
            if (type == typeof(bool))
            {
                return(testMessage.ReadBoolean());
            }
            if (type == typeof(byte))
            {
                return(testMessage.ReadByte());
            }
            if (type == typeof(char))
            {
                return(testMessage.ReadChar());
            }
            if (type == typeof(short))
            {
                return(testMessage.ReadInt16());
            }
            if (type == typeof(int))
            {
                return(testMessage.ReadInt32());
            }
            if (type == typeof(long))
            {
                return(testMessage.ReadInt64());
            }
            if (type == typeof(float))
            {
                return(testMessage.ReadSingle());
            }
            if (type == typeof(double))
            {
                return(testMessage.ReadDouble());
            }
            if (type == typeof(string))
            {
                return(testMessage.ReadString());
            }
            if (type == typeof(byte[]))
            {
                return(testMessage.ReadBytes(destination));
            }

            throw new Exception("Unexpected entry type class");
        }
Пример #6
0
        public void TestForeignStreamMessageTransformCreateNewMessage()
        {
            ForeignNmsStreamMessage foreignMessage = new ForeignNmsStreamMessage();

            foreignMessage.WriteBoolean(true);
            foreignMessage.WriteString("test");
            foreignMessage.WriteBoolean(true);

            NmsMessage transformed = NmsMessageTransformation.TransformMessage(factory, foreignMessage);

            Assert.IsNotNull(transformed);
            Assert.AreNotSame(foreignMessage, transformed);

            Assert.IsInstanceOf <NmsStreamMessage>(transformed);

            NmsStreamMessage message = (NmsStreamMessage)transformed;

            message.Reset();
            Assert.IsTrue(message.ReadBoolean());
            Assert.AreEqual("test", message.ReadString());
            Assert.IsTrue(message.ReadBoolean());
        }
Пример #7
0
 public string ReadString()
 {
     return(message.ReadString());
 }