Example #1
0
        public void UpdatePackageFromUI()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte             = VisualStudio.Dte;
            var solutionService = VisualStudio.Get <SolutionService>();

            solutionService.CreateEmptySolution();
            var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            VisualStudio.ClearWindows();

            // Act
            dte.ExecuteCommand("Project.ManageNuGetPackages");
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            uiwindow.InstallPackageFromUI("newtonsoft.json", "9.0.1");
            project.Build();

            // Assert
            Assert.True(uiwindow.IsPackageInstalled("newtonsoft.json", "9.0.1"));
            VisualStudio.AssertNoErrors();

            // Act
            VisualStudio.ClearWindows();
            uiwindow.UpdatePackageFromUI("newtonsoft.json", "10.0.3");
            project.Build();

            // Assert
            Assert.True(uiwindow.IsPackageInstalled("newtonsoft.json", "10.0.3"));
            VisualStudio.AssertNoErrors();
        }
Example #2
0
        public void UninstallPackageFromUI()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte             = VisualStudio.Dte;
            var solutionService = VisualStudio.Get <SolutionService>();

            solutionService.CreateEmptySolution();
            var      project            = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");
            FileInfo packagesConfigFile = GetPackagesConfigFile(project);

            dte.ExecuteCommand("Project.ManageNuGetPackages");
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            uiwindow.InstallPackageFromUI("newtonsoft.json", "9.0.1");

            WaitForFileExists(packagesConfigFile);

            VisualStudio.ClearWindows();

            // Act
            uiwindow.UninstallPackageFromUI("newtonsoft.json");

            WaitForFileNotExists(packagesConfigFile);

            // Assert
            CommonUtility.AssertPackageNotInPackagesConfig(VisualStudio, project, "newtonsoft.json", XunitLogger);
        }
Example #3
0
        public void UpdatePackageFromUI()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte             = VisualStudio.Dte;
            var solutionService = VisualStudio.Get <SolutionService>();

            solutionService.CreateEmptySolution();
            var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            VisualStudio.ClearWindows();
            solutionService.SaveAll();

            // Act
            OpenNuGetPackageManagerWithDte();
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            uiwindow.InstallPackageFromUI("newtonsoft.json", "9.0.1");

            // Act
            VisualStudio.ClearWindows();
            uiwindow.UpdatePackageFromUI("newtonsoft.json", "10.0.3");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "newtonsoft.json", "10.0.3", XunitLogger);
        }
Example #4
0
        public async Task UpdatePackageFromUI_PackageNamespace_WithSingleFeed_Succeeds()
        {
            // Arrange
            EnsureVisualStudioHost();
            var    solutionService   = VisualStudio.Get <SolutionService>();
            string solutionDirectory = CommonUtility.CreateSolutionDirectory(Directory.GetCurrentDirectory());

            solutionService.CreateEmptySolution("TestSolution", solutionDirectory);

            var privateRepositoryPath = Path.Combine(solutionService.ContainingDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            var packageName      = "Contoso.A";
            var packageVersionV1 = "1.0.0";
            var packageVersionV2 = "2.0.0";

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersionV1);

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersionV2);

            // Create nuget.config with Package namespace filtering rules before project is created.
            CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageNamespaces>
        <packageSource key=""PrivateRepository"">
            <namespace id=""Contoso.*"" />             
            <namespace id=""Test.*"" />
        </packageSource>
    </packageNamespaces>
//</configuration>");

            var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            VisualStudio.ClearOutputWindow();
            solutionService.SaveAll();

            // Act
            OpenNuGetPackageManagerWithDte();
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            uiwindow.InstallPackageFromUI("contoso.a", "1.0.0");

            // Act
            VisualStudio.ClearWindows();
            uiwindow.UpdatePackageFromUI("contoso.a", "2.0.0");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "contoso.a", "2.0.0", XunitLogger);
        }
        public async Task WithSourceMappingEnabled_InstallAndUpdatePackageFromPMUIFromExpectedSource_Succeeds(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var simpleTestPathContext = new SimpleTestPathContext())
            {
                string solutionDirectory     = simpleTestPathContext.SolutionRoot;
                var    privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
                Directory.CreateDirectory(privateRepositoryPath);
                var externalRepositoryPath = Path.Combine(solutionDirectory, "ExternalRepository");
                Directory.CreateDirectory(externalRepositoryPath);

                var packageName     = "Contoso.a";
                var packageVersion1 = "1.0.0";
                var packageVersion2 = "2.0.0";

                await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1);

                await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion1);

                await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion2);

                await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion2);

                // Create nuget.config with Package source mapping filtering rules before project is created.
                CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.Config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
        <add key=""ExternalRepository"" value=""{externalRepositoryPath}"" />
        <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageSourceMapping>
        <packageSource key=""externalRepository"">
            <package pattern=""External.*"" />
            <package pattern=""Others.*"" />
        </packageSource>
        <packageSource key=""PrivateRepository"">
            <package pattern=""contoso.*"" />
            <package pattern=""Test.*"" />
        </packageSource>
        <packageSource key=""nuget"">
            <package pattern=""Microsoft.*"" />
            <package pattern=""NetStandard*"" />
        </packageSource>
    </packageSourceMapping>
</configuration>");

                using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, addNetStandardFeeds: true, simpleTestPathContext: simpleTestPathContext))
                {
                    VisualStudio.AssertNoErrors();

                    // Arrange
                    CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, XunitLogger);
                    var nugetTestService = GetNuGetTestService();
                    var uiwindow         = nugetTestService.GetUIWindowfromProject(testContext.SolutionService.Projects[0]);
                    uiwindow.InstallPackageFromUI(packageName, packageVersion1);
                    testContext.SolutionService.SaveAll();
                    VisualStudio.AssertNuGetOutputDoesNotHaveErrors();
                    VisualStudio.ClearWindows();

                    // Act
                    uiwindow.UpdatePackageFromUI(packageName, packageVersion2);

                    // Assert
                    VisualStudio.AssertNuGetOutputDoesNotHaveErrors();
                    CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.SolutionService.Projects[0], packageName, packageVersion2, XunitLogger);
                    Assert.Contains($"Installed {packageName} {packageVersion2} from {privateRepositoryPath}", GetPackageManagerOutputWindowPaneText());
                }
            }
        }