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 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")); }
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); } }
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); } }
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); }
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); }
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); } }
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")); }
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 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(); } }