示例#1
0
 public void Repeated_images_use_the_same_LinkedResource()
 {
     var embedder = new ImageEmbedder(StubLinkedResource);
     var r1 = embedder.ReferenceImage("test-a.png");
     var r2 = embedder.ReferenceImage("test-a.png");
     Assert.Same(r1, r2);
 }
        public void Repeated_images_use_the_same_LinkedResource()
        {
            var embedder = new ImageEmbedder(StubLinkedResource);
            var r1       = embedder.ReferenceImage("test-a.png");
            var r2       = embedder.ReferenceImage("test-a.png");

            Assert.Same(r1, r2);
        }
示例#3
0
        public void Determine_content_type_from_JPG_file_extension()
        {
            var embedder = new ImageEmbedder(StubLinkedResource);
            var resource = embedder.ReferenceImage("test.jpg");

            resource.ContentType.ShouldEqual(new ContentType("image/jpeg"));
        }
        public void ReferenceImage_returns_LinkedResource()
        {
            var embedder = new ImageEmbedder(StubLinkedResource);
            var resource = embedder.ReferenceImage("test.png");

            resource.ShouldNotBeNull();
        }
        public void Determine_content_type_from_GIF_file_extension()
        {
            var embedder = new ImageEmbedder(StubLinkedResource);
            var resource = embedder.ReferenceImage("test.gif");

            resource.ContentType.ShouldBe(new ContentType("image/gif"));
        }
        public void Determine_content_type_from_PNG_http_file_extension()
        {
            var embedder = new ImageEmbedder(StubLinkedResource);
            var resource = embedder.ReferenceImage("http://test.com/test.png");

            resource.ContentType.ShouldBe(new ContentType("image/png"));
        }
示例#7
0
 public void Can_read_image_from_http_url()
 {
     var embedder = new ImageEmbedder();
     using (var resource = embedder.ReferenceImage("http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"))
     {
         resource.ContentStream.Length.ShouldNotEqual(0);
     }
 }
        public void Can_read_image_from_http_url()
        {
            var embedder = new ImageEmbedder();

            using (var resource = embedder.ReferenceImage("http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"))
            {
                resource.ContentStream.Length.ShouldNotBe(0);
            }
        }
示例#9
0
        public void AddImagesToView_adds_linked_resources()
        {
            var embedder = new ImageEmbedder(s => new LinkedResource(new MemoryStream()));
            var cid = embedder.ReferenceImage("test.png");
            using (var view = AlternateView.CreateAlternateViewFromString("<img src=\"cid:" + cid.ContentId + "\" />", new ContentType("text/html")))
            {
                embedder.AddImagesToView(view);

                view.LinkedResources.Count.ShouldEqual(1);
                view.LinkedResources[0].ShouldBeSameAs(cid);
            }
        }
        public void AddImagesToView_adds_linked_resources()
        {
            var embedder = new ImageEmbedder(s => new LinkedResource(new MemoryStream()));
            var cid      = embedder.ReferenceImage("test.png");

            using (var view = AlternateView.CreateAlternateViewFromString("<img src=\"cid:" + cid.ContentId + "\" />", new ContentType("text/html")))
            {
                embedder.AddImagesToView(view);

                view.LinkedResources.Count.ShouldBe(1);
                view.LinkedResources[0].ShouldBeSameAs(cid);
            }
        }
示例#11
0
        public void ReplaceLinkedImagesWithEmbeddedImages_replaces_cid_reference()
        {
            var embedder = new ImageEmbedder();
            var resource = embedder.ReferenceImage("postal.png");

            string body = "<img src=\"cid:" + resource.ContentId + @"""/>";
            var    view = AlternateView.CreateAlternateViewFromString(body);

            embedder.AddImagesToView(view);

            string replaced = TemplateViewResult.ReplaceLinkedImagesWithEmbeddedImages(view, body);

            Assert.DoesNotContain("cid:", replaced);
        }
示例#12
0
        public void ReplaceLinkedImagesWithEmbeddedImages_replaces_cid_reference_with_correct_mime()
        {
            var embedder = new ImageEmbedder();
            var resource = embedder.ReferenceImage("postal.png");

            string body = "<img src=\"cid:" + resource.ContentId + @"""/>";
            var    view = AlternateView.CreateAlternateViewFromString(body);

            embedder.AddImagesToView(view);

            string replaced = EmailViewResult.ReplaceLinkedImagesWithEmbeddedImages(view, body);

            Assert.Contains("data:image/png;base64,", replaced);
        }
示例#13
0
 public void Can_read_image_from_file_system()
 {
     var embedder = new ImageEmbedder();
     var filename = Path.GetTempFileName();
     try
     {
         File.WriteAllBytes(filename, new byte[] { 42 });
         using (var resource = embedder.ReferenceImage(filename))
         {
             resource.ContentStream.Length.ShouldEqual(1);
         }
     }
     finally
     {
         File.Delete(filename);
     }
 }
        public void Can_read_image_from_file_system()
        {
            var embedder = new ImageEmbedder();
            var filename = Path.GetTempFileName();

            try
            {
                File.WriteAllBytes(filename, new byte[] { 42 });
                using (var resource = embedder.ReferenceImage(filename))
                {
                    resource.ContentStream.Length.ShouldBe(1);
                }
            }
            finally
            {
                File.Delete(filename);
            }
        }
示例#15
0
        public void ReplaceLinkedImagesWithEmbeddedImages_replaces_cid_reference()
        {
            var embedder = new ImageEmbedder();
            var resource = embedder.ReferenceImage("postal.png");

            string body = "<img src=\"cid:" + resource.ContentId + @"""/>";
            var view = AlternateView.CreateAlternateViewFromString(body);
            embedder.AddImagesToView(view);

            string replaced = TemplateViewResult.ReplaceLinkedImagesWithEmbeddedImages(view, body);
            Assert.DoesNotContain("cid:", replaced);
        }
示例#16
0
 public void Determine_content_type_from_GIF_file_extension()
 {
     var embedder = new ImageEmbedder(StubLinkedResource);
     var resource = embedder.ReferenceImage("test.gif");
     resource.ContentType.ShouldEqual(new ContentType("image/gif"));
 }
示例#17
0
 public void Determine_content_type_from_PNG_http_file_extension()
 {
     var embedder = new ImageEmbedder(StubLinkedResource);
     var resource = embedder.ReferenceImage("http://test.com/test.png");
     resource.ContentType.ShouldEqual(new ContentType("image/png"));
 }
        public void ReplaceLinkedImagesWithEmbeddedImages_replaces_cid_reference_with_correct_mime()
        {
            var embedder = new ImageEmbedder();
            var resource = embedder.ReferenceImage("postal.png");

            string body = "<img src=\"cid:" + resource.ContentId + @"""/>";
            var view = AlternateView.CreateAlternateViewFromString(body);
            embedder.AddImagesToView(view);
            
            string replaced = EmailViewResult.ReplaceLinkedImagesWithEmbeddedImages(view, body);
            Assert.Contains("data:image/png;base64,", replaced);
        }
示例#19
0
 public void ReferenceImage_returns_LinkedResource()
 {
     var embedder = new ImageEmbedder(StubLinkedResource);
     var resource = embedder.ReferenceImage("test.png");
     resource.ShouldNotBeNull();
 }
示例#20
0
        public void Can_Read_From_Byte_Array()
        {
            var embedder = new ImageEmbedder();

            using (WebClient webClient = new WebClient())
            {
                byte[] data = webClient.DownloadData("http://placehold.it/350x150");

                var resource = embedder.ReferenceImage(data, "image/png");

                resource.ShouldNotBeNull();
                embedder.HasImages.ShouldBeTrue();
            }
        }