public void TestClearBodyOnNewMessageRemovesExistingValues() { NmsStreamMessage streamMessage = factory.CreateStreamMessage(); streamMessage.WriteBoolean(true); streamMessage.ClearBody(); streamMessage.WriteBoolean(false); streamMessage.Reset(); // check we get only the value added after the clear Assert.False(streamMessage.ReadBoolean(), "expected value added after the clear"); Assert.Throws <MessageEOFException>(() => streamMessage.ReadBoolean(), "Expected exception to be thrown"); }
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 TestReadWithEmptyStreamThrowsMEOFE() { NmsStreamMessage streamMessage = factory.CreateStreamMessage(); streamMessage.Reset(); Assert.Throws <MessageEOFException>(() => streamMessage.ReadBoolean(), "Expected exception to be thrown as message has no content"); }
public void TestWriteReadBoolean() { NmsStreamMessage streamMessage = factory.CreateStreamMessage(); bool value = true; streamMessage.WriteBoolean(value); streamMessage.Reset(); Assert.AreEqual(value, streamMessage.ReadBoolean(), "Value not as expected"); }
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()); }
public void TestEmptyForeignStreamMessageTransformCreateNewMessage() { ForeignNmsStreamMessage foreignMessage = new ForeignNmsStreamMessage(); NmsMessage transformed = NmsMessageTransformation.TransformMessage(factory, foreignMessage); Assert.IsNotNull(transformed); Assert.AreNotSame(foreignMessage, transformed); Assert.IsInstanceOf <NmsStreamMessage>(transformed); NmsStreamMessage message = (NmsStreamMessage)transformed; message.Reset(); Assert.Catch <MessageEOFException>(() => message.ReadBoolean()); }
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"); }
public void TestNewMessageIsWriteOnlyThrowsMNRE() { NmsStreamMessage streamMessage = factory.CreateStreamMessage(); Assert.Throws <MessageNotReadableException>(() => streamMessage.ReadBoolean(), "Expected exception to be thrown"); }
public bool ReadBoolean() { return(message.ReadBoolean()); }