public async Task IconUrl_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 builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = $"..{separator}icon.png" }; var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_EmbeddedIcon_RelativeParentPath_ReturnsDefault", Version = new NuGetVersion("1.0.0"), IconUrl = builder.Uri, PackagePath = zipPath, PackageFileService = _packageFileService, }; // Act BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); // Assert VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToNullStream, packageItemListViewModel.BitmapStatus); } }
public async Task IconUrl_WithMalformedUrlScheme_ReturnsDefaultInitallyAndFinally() { var iconUrl = new Uri("httphttphttp://fake.test/image.png"); var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_WithMalformedUrlScheme_ReturnsDefaultInitallyAndFinally", Version = new NuGetVersion("1.0.0"), IconUrl = iconUrl, PackageFileService = _packageFileService, }; var packageIdentity = new PackageIdentity(packageItemListViewModel.Id, packageItemListViewModel.Version); NuGetPackageFileService.AddIconToCache(packageIdentity, packageItemListViewModel.IconUrl); // initial result should be fetching and defaultpackageicon BitmapSource initialResult = packageItemListViewModel.IconBitmap; Assert.Same(initialResult, Images.DefaultPackageIcon); BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel, addIconToCache : false); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToNullStream, packageItemListViewModel.BitmapStatus); }
public PackageItemListViewModelTests( GlobalServiceProvider globalServiceProvider, ITestOutputHelper output, LocalPackageSearchMetadataFixture testData) : base(globalServiceProvider) { globalServiceProvider.Reset(); _serviceBroker.Setup( #pragma warning disable ISB001 // Dispose of proxies x => x.GetProxyAsync <INuGetPackageFileService>( It.Is <ServiceJsonRpcDescriptor>(d => d.Moniker == NuGetServices.PackageFileService.Moniker), It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>())) #pragma warning restore ISB001 // Dispose of proxies .Returns(new ValueTask <INuGetPackageFileService>(new NuGetPackageFileService(_serviceBroker.Object, _telemetryProvider.Object))); _packageFileService = new NuGetPackageFileService(_serviceBroker.Object, _telemetryProvider.Object); _testData = testData; _testInstance = new PackageItemListViewModel() { PackagePath = _testData.TestData.PackagePath, PackageFileService = _packageFileService, }; _output = output; }
public async Task IconUrl_WithLocalPathAndColorProfile_LoadsImage() { // Prepare using (var testDir = TestDirectory.Create()) { byte[] bytes; Assembly testAssembly = typeof(PackageItemListViewModelTests).Assembly; using (Stream sourceStream = testAssembly.GetManifestResourceStream("NuGet.PackageManagement.UI.Test.Resources.grayicc.png")) using (var memoryStream = new MemoryStream()) { sourceStream.CopyTo(memoryStream); bytes = memoryStream.ToArray(); } string grayiccImagePath = Path.Combine(testDir, "grayicc.png"); File.WriteAllBytes(grayiccImagePath, bytes); var packageItemListViewModel = new PackageItemListViewModel() { IconUrl = new Uri(grayiccImagePath, UriKind.Absolute) }; // Act BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); // Assert VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DownloadedIcon, packageItemListViewModel.BitmapStatus); } }
public async Task IconUrl_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 builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = $"..{separator}icon.png" }; var packageItemListViewModel = new PackageItemListViewModel() { IconUrl = builder.Uri, PackageReader = new Func <PackageReaderBase>(() => new PackageArchiveReader(zipPath)) }; // Act BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); // Assert VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToDecodingError, packageItemListViewModel.BitmapStatus); } }
public V3DetailControlModelTestBase(GlobalServiceProvider sp, V3PackageSearchMetadataFixture testData) { sp.Reset(); _testData = testData; // The versions pre-baked into the view model provide data for the first step of metadata extraction // which fails (null) in a V3 scenario--they need to be extracted using a metadata provider (below) var testVersion = new NuGetVersion(0, 0, 1); var testVersions = new List <VersionInfoContextInfo>() { new VersionInfoContextInfo(new NuGetVersion(0, 0, 1)), new VersionInfoContextInfo(new NuGetVersion(0, 0, 2)) }; _testViewModel = new PackageItemListViewModel() { Id = "nuget.psm", Version = testVersion, Versions = new Lazy <Task <IReadOnlyCollection <VersionInfoContextInfo> > >(() => Task.FromResult <IReadOnlyCollection <VersionInfoContextInfo> >(testVersions)), InstalledVersion = testVersion, Sources = new List <PackageSourceContextInfo> { new PackageSourceContextInfo("nuget.psm.test") }, }; }
public TestablePackageSearchResultViewModel( PackageItemListViewModel viewModel) : this( new FakeSolutionManager(), new FakeDotNetProject(), viewModel) { }
public PackageItemListViewModelTests(LocalPackageSearchMetadataFixture testData) { _testData = testData; _testInstance = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, }; }
PackageSearchResultViewModel CreatePackage(string id) { var packageViewModel = new PackageItemListViewModel { Id = id }; return(new PackageSearchResultViewModel(null, packageViewModel)); }
ManagePackagesSearchResultViewModel CreatePackageViewModel(PackageItemListViewModel viewModel) { bool showVersion = ShowPackageVersionInsteadOfDownloadCount(); return(new ManagePackagesSearchResultViewModel(this, viewModel) { ShowVersionInsteadOfDownloadCount = showVersion }); }
ManagePackagesSearchResultViewModel CreatePackageViewModel(PackageItemListViewModel viewModel) { bool showVersion = ShowPackageVersionInsteadOfDownloadCount(); return(new ManagePackagesSearchResultViewModel(this, viewModel) { ShowVersionInsteadOfDownloadCount = showVersion, SelectLatestVersion = IsConsolidatePageSelected }); }
void CreateViewModel(PackageItemListViewModel package) { metadataProvider = new FakePackageMetadataProvider(); packageSearchMetadata = metadataProvider.AddPackageMetadata(package.Id, package.Version.ToString()); var solutionManager = new FakeSolutionManager(); var project = new FakeDotNetProject(); parent = new TestableAllPackagesViewModel(solutionManager, project); viewModel = new TestablePackageSearchResultViewModel(parent, packageItemListViewModel); }
public ManagePackagesSearchResultViewModel( ManagePackagesViewModel parent, PackageItemListViewModel viewModel) { this.parent = parent; this.viewModel = viewModel; Versions = new ObservableCollection <NuGetVersion> (); SelectedVersion = Version; }
public TestablePackageSearchResultViewModel( FakeSolutionManager solutionManager, FakeDotNetProject project, PackageItemListViewModel viewModel) : this( new TestableAllPackagesViewModel(solutionManager, project), viewModel) { SolutionManager = solutionManager; Project = project; }
public PackageSearchResultViewModel( AllPackagesViewModel parent, PackageItemListViewModel viewModel) { this.parent = parent; this.viewModel = viewModel; Versions = new ObservableCollection <NuGetVersion> (); SelectedVersion = Version; IsLatestVersionSelected = true; }
PackageSearchResultViewModel CreateRecentPackage(string packageId, string packageVersion, string packageSource) { var allPackagesViewModelForRecentPackages = new TestableAllPackagesViewModel( new FakeSolutionManager(), new FakeDotNetProject()); var recentPackage = new PackageItemListViewModel { Id = packageId, Version = new NuGetVersion(packageVersion) }; return(new PackageSearchResultViewModel(allPackagesViewModelForRecentPackages, recentPackage)); }
PackageItemListViewModel CreatePackageItemListViewModel() { packageVersions = new List <VersionInfo> (); packageItemListViewModel = new PackageItemListViewModel { Id = "TestPackage", Version = new NuGetVersion("1.2.3"), Versions = AsyncLazy.New(() => { return(Task.FromResult(packageVersions.AsEnumerable())); }) }; return(packageItemListViewModel); }
public async Task SetCurrentPackageAsync_SortsVersions_ByNuGetVersionDesc() { // Arrange NuGetVersion installedVersion = NuGetVersion.Parse("1.0.0"); var testVersions = new List <VersionInfoContextInfo>() { new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01248")), new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01249")), new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01256")), new VersionInfoContextInfo(new NuGetVersion("2.10.1-dev-01265")), new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01187")), new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01191")), new VersionInfoContextInfo(new NuGetVersion("2.10.0-dev-01211")), new VersionInfoContextInfo(new NuGetVersion("2.10.0")), }; var vm = new PackageItemListViewModel() { InstalledVersion = installedVersion, Version = installedVersion, Versions = new Lazy <Task <IReadOnlyCollection <VersionInfoContextInfo> > >(() => Task.FromResult <IReadOnlyCollection <VersionInfoContextInfo> >(testVersions)), }; // Act await _testInstance.SetCurrentPackageAsync( vm, ItemFilter.All, () => vm); // Assert var expectedAdditionalInfo = string.Empty; // Remove any added `null` separators, and any Additional Info entries (eg, "Latest Prerelease", "Latest Stable"). List <DisplayVersion> actualVersions = _testInstance.Versions .Where(v => v != null && v.AdditionalInfo == expectedAdditionalInfo).ToList(); var expectedVersions = new List <DisplayVersion>() { new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01265"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01256"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01249"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.1-dev-01248"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.0"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01211"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01191"), additionalInfo: expectedAdditionalInfo), new DisplayVersion(version: new NuGetVersion("2.10.0-dev-01187"), additionalInfo: expectedAdditionalInfo), }; Assert.Equal(expectedVersions, actualVersions); }
public LocalDetailControlModelTestBase(GlobalServiceProvider sp, LocalPackageSearchMetadataFixture testData) { sp.Reset(); _testData = testData; var testVersion = new NuGetVersion(0, 0, 1); _testViewModel = new PackageItemListViewModel() { PackagePath = _testData.TestData.PackagePath, Version = testVersion, InstalledVersion = testVersion, }; }
public async Task IconUrl_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 UriBuilder builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = iconElement }; var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_FileUri_LoadsImage" + iconElement, Version = new NuGetVersion("1.0.0"), IconUrl = builder.Uri, PackagePath = zipPath, PackageFileService = _packageFileService, }; _output.WriteLine($"ZipPath {zipPath}"); _output.WriteLine($"File Exists {File.Exists(zipPath)}"); _output.WriteLine($"Url {builder.Uri}"); // Act BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); _output.WriteLine($"result {result}"); string resultFormat = result != null?result.Format.ToString() : ""; _output.WriteLine($"Pixel format: {resultFormat}"); // Assert Assert.Equal(IconBitmapStatus.DefaultIconDueToDecodingError, packageItemListViewModel.BitmapStatus); } }
public PackageItemListViewModelTests(DispatcherThreadFixture fixture, ITestOutputHelper output, LocalPackageSearchMetadataFixture testData) { _testData = testData; _testInstance = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, }; _output = output; Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
public async Task IconUrl_RelativeUri_ReturnsDefault() { // relative URIs are not supported in viewmodel. var iconUrl = new Uri("resources/testpackageicon.png", UriKind.Relative); var packageItemListViewModel = new PackageItemListViewModel() { IconUrl = iconUrl }; BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToRelativeUri, packageItemListViewModel.BitmapStatus); }
public async Task IconUrl_WhenFileNotFound_ReturnsDefault() { var iconUrl = new Uri(@"C:\path\to\image.png"); var packageItemListViewModel = new PackageItemListViewModel() { IconUrl = iconUrl }; BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToWebExceptionBadNetwork, packageItemListViewModel.BitmapStatus); }
public async Task IconUrl_WithValidImageUrl_FailsDownloadsImage_ReturnsDefault() { var iconUrl = new Uri("http://fake.test/image.png"); var packageItemListViewModel = new PackageItemListViewModel() { IconUrl = iconUrl }; BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToWebExceptionOther, packageItemListViewModel.BitmapStatus); }
/// <summary> /// Tests the final bitmap returned by the view model, by waiting for the BitmapStatus to be "complete". /// </summary> private static async Task <BitmapSource> GetFinalIconBitmapAsync(PackageItemListViewModel packageItemListViewModel) { BitmapSource result = packageItemListViewModel.IconBitmap; int millisecondsToWait = 3000; while (!IconBitmapStatusUtility.GetIsCompleted(packageItemListViewModel.BitmapStatus) && millisecondsToWait >= 0) { await Task.Delay(250); millisecondsToWait -= 250; } result = packageItemListViewModel.IconBitmap; return(result); }
public PackageItemListViewModelTests( GlobalServiceProvider globalServiceProvider, ITestOutputHelper output, LocalPackageSearchMetadataFixture testData) : base(globalServiceProvider) { globalServiceProvider.Reset(); _testData = testData; _testInstance = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, }; _output = output; }
public async Task IconUrl_WhenFileNotFound_ReturnsDefault() { var iconUrl = new Uri(@"C:\path\to\image.png"); var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_WhenFileNotFound_ReturnsDefault", Version = new NuGetVersion("1.0.0"), IconUrl = iconUrl, PackageFileService = _packageFileService, }; BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToNullStream, packageItemListViewModel.BitmapStatus); }
public async Task IconUrl_WithValidImageUrl_FailsDownloadsImage_ReturnsDefault() { var iconUrl = new Uri("http://fake.test/image.png"); var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_WithValidImageUrl_FailsDownloadsImage_ReturnsDefault", Version = new NuGetVersion("1.0.0"), IconUrl = iconUrl, PackageFileService = _packageFileService, }; BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); Assert.Equal(IconBitmapStatus.DefaultIconDueToNullStream, packageItemListViewModel.BitmapStatus); }
public async Task IconUrl_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, isRealImage: true); // prepare test var builder = new UriBuilder(new Uri(zipPath, UriKind.Absolute)) { Fragment = iconElement }; var packageItemListViewModel = new PackageItemListViewModel() { Id = "PackageId.IconUrl_EmbeddedIcon_HappyPath_LoadsImage", Version = new NuGetVersion("1.0.0"), IconUrl = builder.Uri, PackagePath = zipPath, PackageFileService = _packageFileService, }; _output.WriteLine($"ZipPath {zipPath}"); _output.WriteLine($"File Exists {File.Exists(zipPath)}"); _output.WriteLine($"Url {builder.Uri}"); // Act BitmapSource result = await GetFinalIconBitmapAsync(packageItemListViewModel); // Assert _output.WriteLine($"result {result}"); Assert.Equal(IconBitmapStatus.FetchedIcon, packageItemListViewModel.BitmapStatus); VerifyImageResult(result, packageItemListViewModel.BitmapStatus); } }
public DetailControlModelTestBase(LocalPackageSearchMetadataFixture testData) { _testData = testData; var testVersion = new NuGetVersion(0, 0, 1); _testViewModel = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, Version = testVersion, InstalledVersion = testVersion, }; #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext _joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_joinableTaskContext.Factory); }