public void JsonMessageDeserializer_WhenGivenNullTextWriter_ThrowsArgumentNullException() {
            // given
            IMessageTypeResolver resolver = new UnitTestMessageTypeResolver();
            TextReader textReader = null;

            // when
            ArgumentNullException exception =
                Assert.Throws<ArgumentNullException>(
                    () => new JsonMessageDeserializer(resolver, textReader));

            // then
            Assert.That(() => exception.ParamName, Is.EqualTo("textReader"));
        }
        public void JsonMessageSerializer_WhenGivenNullMessage_ThrowsArgumentNullException() {
            // given
            IMessageTypeResolver resolver = new UnitTestMessageTypeResolver();
            TextWriter textWriter = new StringWriter();

            // when
            ArgumentNullException exception =
                Assert.Throws<ArgumentNullException>(
                    () => new JsonMessageSerializer(resolver, textWriter).SerializeMessage(null));

            // then
            Assert.That(() => exception.ParamName, Is.EqualTo("message"));
        }
        public void JsonMessageSerializer_WhenUnderlyingMediumFails_ThrowsMessageException() {
            // given
            IMessageTypeResolver resolver = new UnitTestMessageTypeResolver();
            TextWriter textWriter = new StringWriter();
            textWriter.Dispose(); // so stringwriter will throw ObjectDisposedException

            // when / then
            MessageTransferException exception =
                Assert.Throws<MessageTransferException>(
                    () => new JsonMessageSerializer(resolver, textWriter).SerializeMessage(new FakeMessage()));

            // then
            Assert.That(() => exception.InnerException, Is.InstanceOf<ObjectDisposedException>());
        }