public void Convert_EmbeddedIcon_RelativeParentPath_ReturnsDefault(string separator) { using (var testDir = TestDirectory.Create()) { // Create decoy nuget package var zipPath = Path.Combine(testDir.Path, "file.nupkg"); CreateDummyPackage(zipPath); // prepare test var converter = new IconUrlToImageCacheConverter(); UriBuilder builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = $@"..{separator}icon.png" }; // Act var result = converter.Convert( values: new object[] { builder.Uri, new Func <PackageReaderBase>(() => new PackageArchiveReader(zipPath)) }, targetType: null, parameter: DefaultPackageIcon, culture: null); // Assert VerifyImageResult(result); Assert.Same(DefaultPackageIcon, result); } }
public void Convert_FileUri_LoadsImage() { // Prepare var converter = new IconUrlToImageCacheConverter(); using (var testDir = TestDirectory.Create()) { var imagePath = Path.Combine(testDir, "image.png"); CreateNoisePngImage(path: imagePath); var uri = new Uri(imagePath, UriKind.Absolute); // Act var result = converter.Convert( values: new object[] { uri, DependencyProperty.UnsetValue }, targetType: null, parameter: DefaultPackageIcon, culture: null); var image = result as BitmapImage; // Assert VerifyImageResult(result); Assert.NotSame(DefaultPackageIcon, result); } }
public void Convert_EmbeddedIcon_NotAnIcon_ReturnsDefault( string iconElement, string iconFileLocation, string fileSourceElement, string fileTargetElement) { using (var testDir = TestDirectory.Create()) { // Create decoy nuget package var zipPath = Path.Combine(testDir.Path, "file.nupkg"); CreateDummyPackage( zipPath: zipPath, iconName: iconElement, iconFile: iconFileLocation, iconFileSourceElement: fileSourceElement, iconFileTargetElement: fileTargetElement, isRealImage: false); // prepare test var converter = new IconUrlToImageCacheConverter(); UriBuilder builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = iconElement }; output.WriteLine($"ZipPath {zipPath}"); output.WriteLine($"File Exists {File.Exists(zipPath)}"); output.WriteLine($"Url {builder.Uri}"); // Act var result = converter.Convert( values: new object[] { builder.Uri, new Func <PackageReaderBase>(() => new PackageArchiveReader(zipPath)) }, targetType: null, parameter: DefaultPackageIcon, culture: null); VerifyImageResult(result); var image = result as BitmapSource; output.WriteLine($"result {result}"); output.WriteLine($"Pixel format: {image.Format}"); // Assert Assert.Same(DefaultPackageIcon, result); } }
public void Convert_WhenFileNotFound_ReturnsDefault() { var iconUrl = new Uri(@"C:\path\to\image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( iconUrl, typeof(ImageSource), DefaultPackageIcon, Thread.CurrentThread.CurrentCulture); Assert.Same(DefaultPackageIcon, image); }
public void Convert_WithMalformedUrlScheme_ReturnsDefault() { var iconUrl = new Uri("ttp://fake.com/image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( iconUrl, typeof(ImageSource), DefaultPackageIcon, Thread.CurrentThread.CurrentCulture); Assert.Same(DefaultPackageIcon, image); }
public void Convert_WhenFileNotFound_ReturnsDefault() { var iconUrl = new Uri(@"C:\path\to\image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( values: new object[] { iconUrl, DependencyProperty.UnsetValue }, targetType: null, parameter: DefaultPackageIcon, culture: null); Assert.Same(DefaultPackageIcon, image); }
public void Convert_WithMalformedUrlScheme_ReturnsDefault() { var iconUrl = new Uri("ttp://fake.com/image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( values: new object[] { iconUrl, DependencyProperty.UnsetValue }, targetType: null, parameter: DefaultPackageIcon, culture: null); Assert.Same(DefaultPackageIcon, image); }
public void Convert_EmbeddedIcon_HappyPath_LoadsImage( string iconElement, string iconFileLocation, string fileSourceElement, string fileTargetElement) { using (var testDir = TestDirectory.Create()) { // Create decoy nuget package var zipPath = Path.Combine(testDir.Path, "file.nupkg"); CreateDummyPackage( zipPath: zipPath, iconName: iconElement, iconFile: iconFileLocation, iconFileSourceElement: fileSourceElement, iconFileTargetElement: fileTargetElement); // prepare test var converter = new IconUrlToImageCacheConverter(); UriBuilder builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = iconElement }; output.WriteLine($"ZipPath {zipPath}"); output.WriteLine($"File Exists {File.Exists(zipPath)}"); output.WriteLine($"Url {builder.Uri.ToString()}"); // Act var result = converter.Convert( values: new object[] { builder.Uri, new Func <PackageReaderBase>(() => new Packaging.PackageArchiveReader(zipPath)) }, targetType: null, parameter: DefaultPackageIcon, culture: null); var image = result as BitmapImage; output.WriteLine($"result {result.ToString()}"); // Assert Assert.NotNull(result); Assert.NotSame(DefaultPackageIcon, result); Assert.Equal(32, image.PixelWidth); } }
public void Convert_WithValidImageUrl_DownloadsImage_DefaultImage() { var iconUrl = new Uri("http://fake.com/image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( values: new object[] { iconUrl, DependencyProperty.UnsetValue }, targetType: null, parameter: DefaultPackageIcon, culture: null) as BitmapImage; VerifyImageResult(image); Assert.NotSame(DefaultPackageIcon, image); Assert.Equal(iconUrl, image.UriSource); }
public void Convert_WithLocalPath_LoadsImage() { var iconUrl = new Uri(@"resources/packageicon.png", UriKind.Relative); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( values: new object[] { iconUrl, DependencyProperty.UnsetValue }, targetType: null, parameter: DefaultPackageIcon, culture: null) as BitmapImage; VerifyImageResult(image); Assert.NotSame(DefaultPackageIcon, image); Assert.Equal(iconUrl, image.UriSource); }
public void Convert_WithValidImageUrl_DownloadsImage() { var iconUrl = new Uri("http://fake.com/image.png"); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( iconUrl, typeof(ImageSource), DefaultPackageIcon, Thread.CurrentThread.CurrentCulture) as BitmapImage; Assert.NotNull(image); Assert.NotSame(DefaultPackageIcon, image); Assert.Equal(iconUrl, image.UriSource); }
public void Convert_WithLocalPath_LoadsImage() { var iconUrl = new Uri(@"resources/packageicon.png", UriKind.Relative); var converter = new IconUrlToImageCacheConverter(); var image = converter.Convert( iconUrl, typeof(ImageSource), DefaultPackageIcon, Thread.CurrentThread.CurrentCulture) as BitmapImage; Assert.NotNull(image); Assert.NotSame(DefaultPackageIcon, image); Assert.Equal(iconUrl, image.UriSource); }
public void IsEmbeddedIconUri_Tests(Uri testUri, bool expectedResult) { var result = IconUrlToImageCacheConverter.IsEmbeddedIconUri(testUri); Assert.Equal(expectedResult, result); }