public void IsSerializable()
        {
            // Arrange.
            const string ContentId = "test";
            const string ContentType = "image/png";
            var content = new byte[] { 1, 2, 3, 4 };
            var original = new EmailLinkedResource(ContentId, content, ContentType);

            // Act.
            var bytes = MobileFormatter.Serialize(original);
            var deserialized = (EmailLinkedResource)MobileFormatter.Deserialize(bytes);

            // Assert.
            Assert.IsNotNull(deserialized);
            Assert.AreEqual(ContentId, deserialized.ContentId);
            Assert.IsTrue(content.SequenceEqual(deserialized.GetBytes()));
            Assert.AreEqual(ContentType, deserialized.ContentType);
        }
Beispiel #2
0
        private static LinkedResource CreateLinkedResource(EmailLinkedResource resource)
        {
            MemoryStream stream = null;

            try
            {
                stream = new MemoryStream(resource.GetBytes());

                return new LinkedResource(stream, new ContentType(resource.ContentType)) { ContentId = resource.ContentId };
            }
            catch (Exception)
            {
                if (stream != null)
                    stream.Dispose();

                throw;
            }
        }