public void PerformUpToDateCheck_WhenALeafProjectHasNoGlobalPackagesFolder_ReturnsOnlyThatProject() { using (var testDirectory = TestDirectory.Create()) { var projectA = GetPackageSpec("A", testDirectory.Path); var projectB = GetPackageSpec("B", testDirectory.Path); var projectC = GetPackageSpec("C", testDirectory.Path); projectC.RestoreMetadata.PackagesPath = Path.Combine(testDirectory.Path, "gpf"); // A => B projectA = projectA.WithTestProjectReference(projectB); // B => C projectB = projectB.WithTestProjectReference(projectC); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC); var checker = new SolutionUpToDateChecker(); // Preconditions, run 1st check var actual = checker.PerformUpToDateCheck(dgSpec); var expected = GetUniqueNames(projectA, projectB, projectC); actual.Should().BeEquivalentTo(expected); var results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectB, projectC); checker.ReportStatus(results); // Set-up, delete C's outputs Directory.Delete(projectC.RestoreMetadata.PackagesPath, recursive: true); // Act & Assert actual = checker.PerformUpToDateCheck(dgSpec); expected = GetUniqueNames(projectC); actual.Should().BeEquivalentTo(expected); } }
public void PerformUpToDateCheck_LeafProjectChanges_ReturnsAllItsParents() { using (var testDirectory = TestDirectory.Create()) { var projectA = GetPackageSpec("A", testDirectory.Path); var projectB = GetPackageSpec("B", testDirectory.Path); var projectC = GetPackageSpec("C", testDirectory.Path); var projectD = GetPackageSpec("D", testDirectory.Path); // A => B projectA = projectA.WithTestProjectReference(projectB); // B => C projectB = projectB.WithTestProjectReference(projectC); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD); var checker = new SolutionUpToDateChecker(); // Preconditions, run 1st check var actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); var expected = GetUniqueNames(projectA, projectB, projectC, projectD); actual.Should().BeEquivalentTo(expected); var results = RunRestore(failedProjects: new HashSet <string>(), projectsWithWarnings: new HashSet <string>(), projectA, projectB, projectC, projectD); checker.SaveRestoreStatus(results); // Set-up, B => D projectB = projectB.WithTestProjectReference(projectD); dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD); // Act & Assert actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); expected = GetUniqueNames(projectA, projectB); actual.Should().BeEquivalentTo(expected); } }
public async Task GetInstalledVersion_WithFloating_WithAssetsFile_ReturnsVersionsFromAssetsSpecs() { using (var testDirectory = TestDirectory.Create()) { // Setup var projectName = "project1"; var projectFullPath = Path.Combine(testDirectory.Path, projectName + ".csproj"); // Project var projectCache = new ProjectSystemCache(); IVsProjectAdapter projectAdapter = (new Mock <IVsProjectAdapter>()).Object; var project = CreateNetCorePackageReferenceProject(projectName, projectFullPath, projectCache); var projectNames = GetTestProjectNames(projectFullPath, projectName); var packageSpec = GetPackageSpec(projectName, projectFullPath, "[*, )"); // Restore info var projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, new List <IAssetsLogMessage>()); projectCache.AddProject(projectNames, projectAdapter, project).Should().BeTrue(); // Package directories var sources = new List <PackageSource>(); var packagesDir = new DirectoryInfo(Path.Combine(testDirectory, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(testDirectory, "packageSource")); packagesDir.Create(); packageSource.Create(); sources.Add(new PackageSource(packageSource.FullName)); var logger = new TestLogger(); var request = new TestRestoreRequest(packageSpec, sources, packagesDir.FullName, logger) { LockFilePath = Path.Combine(testDirectory, "project.assets.json") }; await SimpleTestPackageUtility.CreateFullPackageAsync(packageSource.FullName, "packageA", "4.0.0"); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var packages = await project.GetInstalledPackagesAsync(CancellationToken.None); // Asert Assert.True(result.Success); packages.Should().Contain(a => a.PackageIdentity.Equals(new PackageIdentity("packageA", new NuGetVersion("4.0.0")))); var cache_packages = await project.GetInstalledPackagesAsync(CancellationToken.None); cache_packages.Should().Contain(a => a.PackageIdentity.Equals(new PackageIdentity("packageA", new NuGetVersion("4.0.0")))); } }
private static void AddPackageDependency(ProjectSystemCache projectSystemCache, ProjectNames projectNames, PackageSpec packageSpec, SimpleTestPackageContext package) { var dependency = new LibraryDependency() { LibraryRange = new LibraryRange( name: package.Id, versionRange: new VersionRange(package.Identity.Version), typeConstraint: LibraryDependencyTarget.Package) }; packageSpec.TargetFrameworks.First().Dependencies.Add(dependency); DependencyGraphSpec projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectSystemCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, Array.Empty <IAssetsLogMessage>()); }
public void ReportStatus_WhenPartialResultsAreAvailable_OldStatusIsRetained() { using (var testDirectory = TestDirectory.Create()) { var projectA = GetPackageSpec("A", testDirectory.Path); var projectB = GetPackageSpec("B", testDirectory.Path); var projectC = GetPackageSpec("C", testDirectory.Path); var projectD = GetPackageSpec("D", testDirectory.Path); var projectE = GetPackageSpec("E", testDirectory.Path); // A => B projectA = projectA.WithTestProjectReference(projectB); // B => C projectB = projectB.WithTestProjectReference(projectC); // A => D projectA = projectA.WithTestProjectReference(projectD); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD, projectE); var checker = new SolutionUpToDateChecker(); // Preconditions, run 1st check var actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); var expected = GetUniqueNames(projectA, projectB, projectC, projectD, projectE); actual.Should().BeEquivalentTo(expected); var results = RunRestore(failedProjects: new HashSet <string>(), projectsWithWarnings: new HashSet <string>(), projectA, projectB, projectC, projectD, projectE); checker.SaveRestoreStatus(results); // D => E projectD = projectD.WithTestProjectReference(projectE); // Set-up dg spec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD, projectE); // 2nd check actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); expected = GetUniqueNames(projectA, projectD); actual.Should().BeEquivalentTo(expected); results = RunRestore(failedProjects: new HashSet <string>(), projectsWithWarnings: new HashSet <string>(), projectA, projectD); checker.SaveRestoreStatus(results); // Finally, last check. Run for a 3rd time. Everything should be up to date actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); expected = GetUniqueNames(); actual.Should().BeEquivalentTo(expected); } }
public async Task GetInstalledVersion_WithoutPackages_ReturnsEmpty() { using (var testDirectory = TestDirectory.Create()) { // Setup var projectName = "project1"; var projectFullPath = Path.Combine(testDirectory.Path, projectName + ".csproj"); // Project var projectCache = new ProjectSystemCache(); IVsProjectAdapter projectAdapter = (new Mock <IVsProjectAdapter>()).Object; var project = CreateNetCorePackageReferenceProject(projectName, projectFullPath, projectCache); var projectNames = GetTestProjectNames(projectFullPath, projectName); var packageSpec = GetPackageSpecNoPackages(projectName, projectFullPath); // Restore info var projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, new List <IAssetsLogMessage>()); projectCache.AddProject(projectNames, projectAdapter, project).Should().BeTrue(); // Package directories var sources = new List <PackageSource>(); var packagesDir = new DirectoryInfo(Path.Combine(testDirectory, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(testDirectory, "packageSource")); packagesDir.Create(); packageSource.Create(); sources.Add(new PackageSource(packageSource.FullName)); var logger = new TestLogger(); var request = new TestRestoreRequest(packageSpec, sources, packagesDir.FullName, logger); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var packages = await project.GetInstalledPackagesAsync(CancellationToken.None); // Asert packages.Should().BeEmpty(); } }
public async Task GetInstalledVersion_WithoutAssetsFile_ReturnsVersionsFromPackageSpecs() { using (var testDirectory = TestDirectory.Create()) { // Setup var projectName = "project1"; var projectFullPath = Path.Combine(testDirectory.Path, projectName + ".csproj"); // Project var projectCache = new ProjectSystemCache(); IVsProjectAdapter projectAdapter = (new Mock <IVsProjectAdapter>()).Object; var project = CreateNetCorePackageReferenceProject(projectName, projectFullPath, projectCache); var projectNames = GetTestProjectNames(projectFullPath, projectName); var packageSpec = GetPackageSpec(projectName, projectFullPath, "[2.0.0, )"); // Restore info var projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, new List <IAssetsLogMessage>()); projectCache.AddProject(projectNames, projectAdapter, project).Should().BeTrue(); // Package directories var sources = new List <PackageSource>(); var packagesDir = new DirectoryInfo(Path.Combine(testDirectory, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(testDirectory, "packageSource")); packagesDir.Create(); packageSource.Create(); sources.Add(new PackageSource(packageSource.FullName)); var logger = new TestLogger(); // Act var packages = await project.GetInstalledPackagesAsync(CancellationToken.None); // Asert packages.Should().Contain(a => a.PackageIdentity.Equals(new PackageIdentity("packageA", new NuGetVersion("2.0.0")))); var cache_packages = await project.GetInstalledPackagesAsync(CancellationToken.None); cache_packages.Should().Contain(a => a.PackageIdentity.Equals(new PackageIdentity("packageA", new NuGetVersion("2.0.0")))); } }
public void PerformUpToDateCheck_WhenNonBuildIntegratedProjectIsAParentOfADirtySpec_ReturnsAListWithoutNonBuildIntegratedProjects() { var projectA = GetPackageSpec("A"); var projectB = GetPackageSpec("B"); var projectC = GetPackageSpec("C"); var projectD = GetPackageSpec("D"); var projectE = GetPackageSpec("E"); var projectF = GetUnknownPackageSpec("F"); // A => B & D & E projectA = projectA.WithTestProjectReference(projectB).WithTestProjectReference(projectD).WithTestProjectReference(projectE); // B => C projectB = projectB.WithTestProjectReference(projectC); // E => F projectE = projectE.WithTestProjectReference(projectF); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD, projectE, projectF); var checker = new SolutionUpToDateChecker(); var actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); var expected = GetUniqueNames(projectA, projectB, projectC, projectD, projectE); actual.Should().BeEquivalentTo(expected); // Now we run var results = RunRestore(failedProjects: new HashSet <string>(), projectsWithWarnings: new HashSet <string>(), projectA, projectB, projectC, projectD, projectE); checker.SaveRestoreStatus(results); // Prepare the new DG Spec: // Make projectE dirty by setting a random value that's usually not there :) projectF = projectF.Clone(); projectF.RestoreMetadata.PackagesPath = @"C:\"; dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD, projectE, projectF); // Act & Assert. expected = GetUniqueNames(projectA, projectE); actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); actual.Should().BeEquivalentTo(expected); }
public void PerformUpToDateCheck_WithFailedPastRestore_ReturnsADirtyProject() { using (var testDirectory = TestDirectory.Create()) { var projectA = GetPackageSpec("A", testDirectory.Path); var projectB = GetPackageSpec("B", testDirectory.Path); var projectC = GetPackageSpec("C", testDirectory.Path); // A => B projectA = projectA.WithTestProjectReference(projectB); // B => C projectB = projectB.WithTestProjectReference(projectC); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC); var checker = new SolutionUpToDateChecker(); // Preconditions, run 1st check var actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); new List <string>() { projectA.RestoreMetadata.ProjectUniqueName, projectB.RestoreMetadata.ProjectUniqueName, projectC.RestoreMetadata.ProjectUniqueName }.Should().BeEquivalentTo(actual); // Set-up, ensure the last status for projectC is a failure. var results = RunRestore(failedProjects: new HashSet <string>() { projectC.RestoreMetadata.ProjectUniqueName }, projectsWithWarnings: new HashSet <string>(), projectA, projectB, projectC); checker.SaveRestoreStatus(results); // Act & Assert actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); var expected = new List <string>() { projectC.RestoreMetadata.ProjectUniqueName }; actual.Should().BeEquivalentTo(expected); } }
public void PerformUpToDateCheck_WithProjectJsonProjects_ReturnsOnlyDirtyProjects() { using (var testDirectory = TestDirectory.Create()) { var projectA = GetPackageSpec("A", testDirectory.Path); var projectB = GetPackageSpec("B", testDirectory.Path); var projectC = GetProjectJsonPackageSpec("C", testDirectory.Path); var projectD = GetProjectJsonPackageSpec("D", testDirectory.Path); // A => B & C projectA = projectA.WithTestProjectReference(projectB).WithTestProjectReference(projectC); DependencyGraphSpec dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD); var checker = new SolutionUpToDateChecker(); // Preconditions, run 1st check var actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); var expected = GetUniqueNames(projectA, projectB, projectC, projectD); actual.Should().BeEquivalentTo(expected); var results = RunRestore(failedProjects: new HashSet <string>(), projectsWithWarnings: new HashSet <string>(), projectA, projectB, projectC, projectD); checker.SaveRestoreStatus(results); // Set-up, make C dirty. projectC = projectC.Clone(); projectC.RestoreMetadata.ConfigFilePaths = new List <string>() { "newFeed" }; dgSpec = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD); // Act & Assert actual = checker.PerformUpToDateCheck(dgSpec, NullLogger.Instance); expected = GetUniqueNames(projectA, projectC); actual.Should().BeEquivalentTo(expected); } }
public async Task GetInstallActionsAsync_WithProjectReferenceProject_WhenUpdatingPackage_ReturnsCorrectActions() { const string projectName = "a"; string projectId = Guid.NewGuid().ToString(); var projectSystemCache = new ProjectSystemCache(); using (TestDirectory testDirectory = TestDirectory.Create()) { var packageV1 = new SimpleTestPackageContext(packageId: "b", version: "1.0.0"); var packageV2 = new SimpleTestPackageContext(packageV1.Id, version: "2.0.0"); string packageSourceDirectoryPath = Path.Combine(testDirectory, "packageSource"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( packageSourceDirectoryPath, PackageSaveMode.Defaultv3, packageV1, packageV2); var packageSource = new PackageSource(packageSourceDirectoryPath); var packageSources = new List <PackageSource>() { packageSource }; Initialize(packageSources); string projectFullPath = Path.Combine(testDirectory.Path, $"{projectName}.csproj"); var unconfiguredProject = new Mock <UnconfiguredProject>(); var configuredProject = new Mock <ConfiguredProject>(); var projectServices = new Mock <ConfiguredProjectServices>(); var packageReferencesService = new Mock <IPackageReferencesService>(); var result = new Mock <IUnresolvedPackageReference>(); unconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync()) .ReturnsAsync(configuredProject.Object); configuredProject.SetupGet(x => x.Services) .Returns(projectServices.Object); projectServices.SetupGet(x => x.PackageReferences) .Returns(packageReferencesService.Object); packageReferencesService.Setup(x => x.AddAsync(It.IsNotNull <string>(), It.IsNotNull <string>())) .ReturnsAsync(new AddReferenceResult <IUnresolvedPackageReference>(result.Object, added: true)); var nuGetProjectServices = new Mock <INuGetProjectServices>(); nuGetProjectServices.SetupGet(x => x.ScriptService) .Returns(Mock.Of <IProjectScriptHostService>()); var project = new CpsPackageReferenceProject( projectName: projectName, projectUniqueName: projectFullPath, projectFullPath: projectFullPath, projectSystemCache, unconfiguredProject.Object, nuGetProjectServices.Object, projectId); PackageSpec packageSpec = CreatePackageSpec( project.ProjectName, Path.Combine(testDirectory, "package.spec")); DependencyGraphSpec projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectRestoreInfo.AddProject(packageSpec); var projectNames = new ProjectNames( fullName: projectFullPath, uniqueName: projectFullPath, shortName: projectName, customUniqueName: projectName, projectId: projectId); projectSystemCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, Array.Empty <IAssetsLogMessage>()); _solutionManager.NuGetProjects.Add(project); string[] projectIds = new[] { projectId }; string[] packageSourceNames = new[] { packageSource.Name }; await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV1.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(1, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV1.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); Assert.Equal(1, action.ImplicitActions.Count); ImplicitProjectAction implicitAction = action.ImplicitActions[0]; Assert.Equal(packageV1.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, implicitAction.ProjectActionType); await projectManager.ExecuteActionsAsync(actions, CancellationToken.None); }); await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV2.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(1, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV2.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); Assert.Equal(2, action.ImplicitActions.Count); ImplicitProjectAction implicitAction = action.ImplicitActions[0]; Assert.Equal(packageV1.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, implicitAction.ProjectActionType); implicitAction = action.ImplicitActions[1]; Assert.Equal(packageV2.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, implicitAction.ProjectActionType); }); } }