public async Task ConvertAsync_Throws_WithSerializedObject()
        {
            BrokeredMessage message = new BrokeredMessage(new TestObject {
                Text = TestString
            });

            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();
            var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => converter.ConvertAsync(message, CancellationToken.None));

            Assert.IsType <SerializationException>(exception.InnerException);
            Assert.StartsWith("The BrokeredMessage with ContentType 'null' failed to deserialize to a byte[] with the message: ", exception.Message);
        }
        public async Task ConvertAsync_ReturnsExpectedResult_WithSerializedByteArray_UnknownContentType(string contentType)
        {
            byte[]          bytes   = Encoding.UTF8.GetBytes(TestString);
            BrokeredMessage message = new BrokeredMessage(bytes);

            message.ContentType = contentType;
            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();

            byte[] result = await converter.ConvertAsync(message, CancellationToken.None);

            // we expect to read back the DataContract-serialized string, since the ContentType tells us to read it back as-is.
            string decoded = Encoding.UTF8.GetString(result);

            Assert.Equal(TestString, decoded);
        }
        public async Task ConvertAsync_ReturnsExpectedResult_WithSerializedByteArray_KnownContentType(string contentType)
        {
            byte[]          bytes   = Encoding.UTF8.GetBytes(TestString);
            BrokeredMessage message = new BrokeredMessage(bytes);

            message.ContentType = contentType;
            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();

            byte[] result = await converter.ConvertAsync(message, CancellationToken.None);

            // we expect to read back the DataContract-serialized string, since the ContentType tells us to read it back as-is.
            string decoded = Encoding.UTF8.GetString(result);

            Assert.Equal("@base64Binary3http://schemas.microsoft.com/2003/10/Serialization/�This is a test!", decoded);
        }
        public async Task ConvertAsync_ReturnsExpectedResult(string contentType)
        {
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);
            sw.Write(TestString);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            BrokeredMessage message = new BrokeredMessage(ms);
            message.ContentType = contentType;
            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();

            byte[] result = await converter.ConvertAsync(message, CancellationToken.None);
            string decoded = Encoding.UTF8.GetString(result);
            Assert.Equal(TestString, decoded);
        }
示例#5
0
        public async Task ConvertAsync_ReturnsExpectedResult(string contentType)
        {
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            sw.Write(TestString);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            BrokeredMessage message = new BrokeredMessage(ms);

            message.ContentType = contentType;
            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();

            byte[] result = await converter.ConvertAsync(message, CancellationToken.None);

            string decoded = Encoding.UTF8.GetString(result);

            Assert.Equal(TestString, decoded);
        }
        public async Task ConvertAsync_Throws_WithStream_UnknownContentType(string contentType)
        {
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            sw.Write(TestString);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            BrokeredMessage message = new BrokeredMessage(ms);

            message.ContentType = contentType;
            BrokeredMessageToByteArrayConverter converter = new BrokeredMessageToByteArrayConverter();

            var ex = await Assert.ThrowsAnyAsync <InvalidOperationException>(() => converter.ConvertAsync(message, CancellationToken.None));

            Assert.IsType <SerializationException>(ex.InnerException);
            string expectedType = contentType ?? "null";

            Assert.StartsWith(string.Format("The BrokeredMessage with ContentType '{0}' failed to deserialize to a byte[] with the message: ", expectedType), ex.Message);
        }