public void PutImageWidthAndHeightInTheCache_WhenTheyAreNotSpecifiedAndAreMissingInTheCache() { // Arrange var runContext = new RunContext(new RunConfiguration() { RelativeUrlsHost = "http://mywebsite.com" }); var imageElement = ElementFactory.CreateImage(); imageElement.Source = "/images/logo1.png"; var imageSanitizer = new ImageSanitizerTestDouble(); imageSanitizer.Configure(runContext); imageSanitizer.DownloadImageResult = (imageUrl) => new Bitmap(100, 200); // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = imageSanitizer.Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(1, runContext.ImagesCache.Count); Assert.AreEqual(100, runContext.ImagesCache["/images/logo1.png"].Width); Assert.AreEqual(200, runContext.ImagesCache["/images/logo1.png"].Height); }
public void ReturnAmpImageElementWithLayoutAttributeSetToResponsive_IfTheOriginalImageElementHasNoWidthAndHeightButShouldDownloadImagesEqualsTrue() { // Arrange var runContext = new RunContext(new RunConfiguration { ShouldDownloadImages = true }); const string ExpectedResult = "responsive"; var imageElement = ElementFactory.CreateImage(); imageElement.Source = "http://www.mywebsite.com/img1.jpg"; ElementFactory.Document.Body.Append(imageElement); var imageSanitizer = new ImageSanitizerTestDouble(); imageSanitizer.DownloadImageResult = (imageUrl) => new Bitmap(100, 200); imageSanitizer.Configure(runContext); // Act var actualResult = imageSanitizer.Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, actualResult.GetAttribute("layout")); }
public void SetImageHeight_WhenItIsNotSpecifiedAndTheImageUrlIsValid() { // Arrange const int ExpectedResult = 200; var runContext = new RunContext(new RunConfiguration() { RelativeUrlsHost = "http://mywebsite.com" }); var imageElement = ElementFactory.CreateImage(); imageElement.Source = "/images/logo.png"; var imageSanitizer = new ImageSanitizerTestDouble(); imageSanitizer.Configure(runContext); imageSanitizer.DownloadImageResult = (imageUrl) => new Bitmap(100, 200); // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = imageSanitizer.Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, int.Parse(ampElement.GetAttribute("height"))); }
// TODO: Remove "Ignore" attribute when we set the absolute url of images always. public void ResolveImageUrl_WhenSourceAttributeIsRelative() { // Arrange const string ExpectedResult = "http://mywebsite.com/images/logo.png"; var runContext = new RunContext(new RunConfiguration() { RelativeUrlsHost = "http://mywebsite.com" }); var imageElement = ElementFactory.CreateImage(); imageElement.Source = "/images/logo.png"; var imageSanitizer = new ImageSanitizerTestDouble(); imageSanitizer.Configure(runContext); imageSanitizer.DownloadImageResult = (imageUrl) => null; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = imageSanitizer.Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, ampElement.GetAttribute("src")); }
public void ThrowInvalidOperationException_WhenTheImageHasNoWidthAndHeightAndTheImageUrlIsInvalid() { // Arrange var runContext = new RunContext(new RunConfiguration { ShouldDownloadImages = true }); var imageElement = ElementFactory.CreateImage(); imageElement.Source = "/images/logo.png"; var imageSanitizer = new ImageSanitizerTestDouble(); imageSanitizer.Configure(runContext); imageSanitizer.DownloadImageResult = (imageUrl) => null; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = imageSanitizer.Sanitize(ElementFactory.Document, imageElement); }