public void serializer_defined_for_message_with_MessageTypeId_65535_Serialize_returns_serialized_object() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(CustomMessage.TypeId, new TestMessageSerializer()); Assert.AreEqual(Encoding.UTF8.GetBytes("abc"), messageSerialization.Serialize(new CustomMessage { Text = "abc" })); }
public void serializer_defined_but_not_for_test_message_Serialize_throws_MissingMessageSerializerException() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(0, new TestMessageSerializer()); Assert.Throws<MissingMessageSerializerException>(() => messageSerialization.Serialize(new TestMessage())); }
public void serializer_defined_but_not_for_test_message_Serialize_throws_MissingMessageSerializerException() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(0, new TestMessageSerializer()); Assert.Throws <MissingMessageSerializerException>(() => messageSerialization.Serialize(new TestMessage())); }
public void serializer_defined_for_message_with_MessageTypeId_65535_Serialize_returns_serialized_object() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(CustomMessage.TypeId, new TestMessageSerializer()); Assert.AreEqual(Encoding.UTF8.GetBytes("abc"), messageSerialization.Serialize(new CustomMessage { Text = "abc" })); }
public void MessageSerializationException_should_be_thrown_on_exception_while_serializing_message() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(ExceptionTestMessage.TypeId, new ExceptionTestMessageSerializer()); var messageThatCausesExceptionOnSerialization = new ExceptionTestMessage(true, false); var exception = Assert.Throws <MessageSerializationException>(() => messageSerialization.Serialize(messageThatCausesExceptionOnSerialization)); Assert.IsInstanceOf <TestException>(exception.InnerException); }
public void MessageDeserializationException_should_be_thrown_on_exception_while_deserializing_message() { var messageSerialization = new MessageSerialization(); messageSerialization.RegisterSerializer(ExceptionTestMessage.TypeId, new ExceptionTestMessageSerializer()); messageSerialization.RegisterDeserializer(ExceptionTestMessage.TypeId, new ExceptionTestMessageDeserializer()); var messageThatCausesExceptionOnDeserialization = new ExceptionTestMessage(false, true); var message = messageSerialization.Serialize(messageThatCausesExceptionOnDeserialization); var exception = Assert.Throws<MessageDeserializationException>(() => messageSerialization.Deserialize(ExceptionTestMessage.TypeId, message)); Assert.IsInstanceOf<TestException>(exception.InnerException); }