public async Task TestUninstallLastPackage()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var targetFramework            = NuGetFramework.Parse("net45");
                var metadata                   = GetTestMetadata(targetFramework);
                var packagesConfigNuGetProject = new PackagesConfigNuGetProject(randomTestFolder, metadata);
                var packageIdentity            = new PackageIdentity("A", new NuGetVersion("1.0.0"));
                var testNuGetProjectContext    = new TestNuGetProjectContext();
                var token = CancellationToken.None;
                MakeFileReadOnly(randomTestFolder);

                // Act
                await packagesConfigNuGetProject.InstallPackageAsync(packageIdentity, GetDownloadResourceResult(), testNuGetProjectContext, token);

                MakeFileReadOnly(randomTestFolder);

                // Assert
                var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
                Assert.Equal(1, installedPackagesList.Count);
                Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
                Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);

                // Main Act
                await packagesConfigNuGetProject.UninstallPackageAsync(packageIdentity, testNuGetProjectContext, token);

                // Main Assert
                installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
                Assert.Equal(0, installedPackagesList.Count);
            }
        }
Ejemplo n.º 2
0
        public async Task TestUninstallPenultimatePackage()
        {
            // Arrange
            var randomTestFolder       = TestFilesystemUtility.CreateRandomTestFolder();
            var packagesConfigFileName = "packages.config";
            var targetFramework        = NuGetFramework.Parse("net45");
            var metadata = new Dictionary <string, object>()
            {
                { NuGetProjectMetadataKeys.TargetFramework, targetFramework },
            };
            var packagesConfigFullPath     = Path.Combine(randomTestFolder, packagesConfigFileName);
            var packagesConfigNuGetProject = new PackagesConfigNuGetProject(packagesConfigFullPath, metadata);

            var packageA = new PackageIdentity("A", new NuGetVersion("1.0.0"));
            var packageB = new PackageIdentity("B", new NuGetVersion("1.0.0"));
            var testNuGetProjectContext = new TestNuGetProjectContext();
            var token = CancellationToken.None;

            MakeFileReadOnly(packagesConfigFullPath);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageA, Stream.Null, testNuGetProjectContext, token);

            MakeFileReadOnly(packagesConfigFullPath);

            // Assert
            var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();

            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageA, installedPackagesList[0].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageB, Stream.Null, testNuGetProjectContext, token);

            // Assert
            installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(2, installedPackagesList.Count);
            Assert.Equal(packageA, installedPackagesList[0].PackageIdentity);
            Assert.Equal(packageB, installedPackagesList[1].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);
            Assert.Equal(targetFramework, installedPackagesList[1].TargetFramework);

            // Main Act
            await packagesConfigNuGetProject.UninstallPackageAsync(packageA, testNuGetProjectContext, token);

            // Main Assert
            installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageB, installedPackagesList[0].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);
        }
Ejemplo n.º 3
0
        public async Task TestInstallPackageUnsupportedFx()
        {
            // Arrange
            var randomTestFolder       = TestFilesystemUtility.CreateRandomTestFolder();
            var packagesConfigFileName = "packages.config";
            var targetFramework        = NuGetFramework.UnsupportedFramework;
            var metadata = new Dictionary <string, object>()
            {
                { NuGetProjectMetadataKeys.TargetFramework, targetFramework },
            };
            var packagesConfigFullPath     = Path.Combine(randomTestFolder, packagesConfigFileName);
            var packagesConfigNuGetProject = new PackagesConfigNuGetProject(packagesConfigFullPath, metadata);
            var packageIdentity            = new PackageIdentity("A", new NuGetVersion("1.0.0"));
            var token = CancellationToken.None;

            MakeFileReadOnly(packagesConfigFullPath);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageIdentity, Stream.Null, new TestNuGetProjectContext(), token);

            MakeFileReadOnly(packagesConfigFullPath);

            // Assert
            var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();

            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
            Assert.True(installedPackagesList[0].TargetFramework.IsUnsupported);
        }
        public async Task TestInstallPackageUnsupportedFx()
        {
            // Arrange
            var randomTestFolder = TestFilesystemUtility.CreateRandomTestFolder();
            var packagesConfigFileName = "packages.config";
            var targetFramework = NuGetFramework.UnsupportedFramework;
            var metadata = new Dictionary<string, object>()
            {
                { NuGetProjectMetadataKeys.TargetFramework, targetFramework},
            };
            var packagesConfigFullPath = Path.Combine(randomTestFolder, packagesConfigFileName);
            var packagesConfigNuGetProject = new PackagesConfigNuGetProject(packagesConfigFullPath, metadata);
            var packageIdentity = new PackageIdentity("A", new NuGetVersion("1.0.0"));
            var token = CancellationToken.None;
            MakeFileReadOnly(packagesConfigFullPath);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageIdentity, Stream.Null, new TestNuGetProjectContext(), token);
            MakeFileReadOnly(packagesConfigFullPath);

            // Assert
            var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
            Assert.True(installedPackagesList[0].TargetFramework.IsUnsupported);
        }
        public async Task TestRenameOfPackagesConfigToIncludeProjectName()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var targetFramework            = NuGetFramework.Parse("net45");
                var projectName                = "TestProject";
                var metadata                   = GetTestMetadata(targetFramework, projectName);
                var packagesConfigNuGetProject = new PackagesConfigNuGetProject(randomTestFolder, metadata);
                var packageIdentity            = new PackageIdentity("A", new NuGetVersion("1.0.0"));
                var token = CancellationToken.None;
                MakeFileReadOnly(randomTestFolder);

                // Act
                await packagesConfigNuGetProject.InstallPackageAsync(packageIdentity, GetDownloadResourceResult(), new TestNuGetProjectContext(), token);

                MakeFileReadOnly(randomTestFolder);

                // Assert
                var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
                Assert.Equal(1, installedPackagesList.Count);
                Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
                Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);

                // Main Act
                var packagesConfigPath            = Path.Combine(randomTestFolder, "packages.config");
                var packagesProjectNameConfigPath = Path.Combine(randomTestFolder, "packages." + projectName + ".config");
                File.Move(packagesConfigPath, packagesProjectNameConfigPath);

                // Assert
                installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
                Assert.Equal(1, installedPackagesList.Count);
                Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
                Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);
            }
        }
Ejemplo n.º 6
0
        private async Task <IVsPathContext> GetPathContextForPackagesConfigAsync(
            IVsProjectAdapter vsProjectAdapter, CancellationToken token)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var props = new Dictionary <string, object>();

            props.Add(NuGetProjectMetadataKeys.Name, Path.GetFileNameWithoutExtension(vsProjectAdapter.FullProjectPath));
            props.Add(NuGetProjectMetadataKeys.TargetFramework, await vsProjectAdapter.GetTargetFrameworkAsync());

            var packagesProject = new PackagesConfigNuGetProject(vsProjectAdapter.ProjectDirectory, props);

            var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(_solutionManager.Value, _settings.Value);
            var folderProject      = new FolderNuGetProject(packagesFolderPath);

            // switch to a background thread to process packages data
            await TaskScheduler.Default;

            var packageReferences = await packagesProject.GetInstalledPackagesAsync(token);

            var trie = new PathLookupTrie <string>();

            foreach (var pid in packageReferences.Select(pr => pr.PackageIdentity))
            {
                var packageInstallPath = folderProject.GetInstalledPath(pid);
                if (string.IsNullOrEmpty(packageInstallPath))
                {
                    throw new KeyNotFoundException(string.Format(CultureInfo.CurrentCulture, VsResources.PathContext_PackageDirectoryNotFound, pid));
                }

                trie[packageInstallPath] = packageInstallPath;
            }

            var pathContext = GetSolutionPathContext();

            return(new VsIndexedPathContext(
                       pathContext.UserPackageFolder,
                       pathContext.FallbackPackageFolders.Cast <string>(),
                       trie));
        }
Ejemplo n.º 7
0
        public async Task TestInstallPackageUnsupportedFx()
        {
            // Arrange
            using (var randomTestFolder = TestFileSystemUtility.CreateRandomTestFolder())
            {
                var targetFramework            = NuGetFramework.UnsupportedFramework;
                var metadata                   = GetTestMetadata(targetFramework);
                var packagesConfigNuGetProject = new PackagesConfigNuGetProject(randomTestFolder, metadata);
                var packageIdentity            = new PackageIdentity("A", new NuGetVersion("1.0.0"));
                var token = CancellationToken.None;
                MakeFileReadOnly(randomTestFolder);

                // Act
                await packagesConfigNuGetProject.InstallPackageAsync(packageIdentity, GetDownloadResourceResult(), new TestNuGetProjectContext(), token);

                MakeFileReadOnly(randomTestFolder);

                // Assert
                var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
                Assert.Equal(1, installedPackagesList.Count);
                Assert.Equal(packageIdentity, installedPackagesList[0].PackageIdentity);
                Assert.True(installedPackagesList[0].TargetFramework.IsUnsupported);
            }
        }
        public async Task TestUninstallPenultimatePackage()
        {
            // Arrange
            var randomTestFolder = TestFilesystemUtility.CreateRandomTestFolder();
            var packagesConfigFileName = "packages.config";
            var targetFramework = NuGetFramework.Parse("net45");
            var metadata = new Dictionary<string, object>()
            {
                { NuGetProjectMetadataKeys.TargetFramework, targetFramework},
            };
            var packagesConfigFullPath = Path.Combine(randomTestFolder, packagesConfigFileName);
            var packagesConfigNuGetProject = new PackagesConfigNuGetProject(packagesConfigFullPath, metadata);

            var packageA = new PackageIdentity("A", new NuGetVersion("1.0.0"));
            var packageB = new PackageIdentity("B", new NuGetVersion("1.0.0"));
            var testNuGetProjectContext = new TestNuGetProjectContext();
            var token = CancellationToken.None;
            MakeFileReadOnly(packagesConfigFullPath);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageA, Stream.Null, testNuGetProjectContext, token);
            MakeFileReadOnly(packagesConfigFullPath);

            // Assert
            var installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageA, installedPackagesList[0].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);

            // Act
            await packagesConfigNuGetProject.InstallPackageAsync(packageB, Stream.Null, testNuGetProjectContext, token);
            // Assert
            installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(2, installedPackagesList.Count);
            Assert.Equal(packageA, installedPackagesList[0].PackageIdentity);
            Assert.Equal(packageB, installedPackagesList[1].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);
            Assert.Equal(targetFramework, installedPackagesList[1].TargetFramework);

            // Main Act
            await packagesConfigNuGetProject.UninstallPackageAsync(packageA, testNuGetProjectContext, token);

            // Main Assert
            installedPackagesList = (await packagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
            Assert.Equal(1, installedPackagesList.Count);
            Assert.Equal(packageB, installedPackagesList[0].PackageIdentity);
            Assert.Equal(targetFramework, installedPackagesList[0].TargetFramework);
        }