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);
                var expected = GetUniqueNames(projectA, projectB, projectC, projectD);
                actual.Should().BeEquivalentTo(expected);
                var results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectB, projectC, projectD);
                checker.ReportStatus(results);

                // Set-up, B => D
                projectB = projectB.WithTestProjectReference(projectD);
                dgSpec   = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(projectA, projectB, projectC, projectD);

                // Act & Assert
                actual   = checker.PerformUpToDateCheck(dgSpec);
                expected = GetUniqueNames(projectA, projectB);
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void PerformUpToDateCheck_WithNoChanges_ReturnsEmpty()
        {
            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);

                var dgSpec = new DependencyGraphSpec();
                dgSpec.AddProject(projectA);
                dgSpec.AddRestore(projectA.RestoreMetadata.ProjectUniqueName);
                dgSpec.AddProject(projectB);
                dgSpec.AddRestore(projectB.RestoreMetadata.ProjectUniqueName);
                dgSpec.AddProject(projectC);
                dgSpec.AddRestore(projectC.RestoreMetadata.ProjectUniqueName);

                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);

                // Act & Asset.
                actual = checker.PerformUpToDateCheck(dgSpec);
                actual.Should().BeEmpty();
            }
        }
        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);
                var expected = GetUniqueNames(projectA, projectB, projectC, projectD, projectE);
                actual.Should().BeEquivalentTo(expected);
                var results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectB, projectC, projectD, projectE);
                checker.ReportStatus(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);
                expected = GetUniqueNames(projectA, projectD);
                actual.Should().BeEquivalentTo(expected);
                results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectD);
                checker.ReportStatus(results);

                // Finally, last check. Run for a 3rd time. Everything should be up to date
                actual   = checker.PerformUpToDateCheck(dgSpec);
                expected = GetUniqueNames();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        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);
            var expected = GetUniqueNames(projectA, projectB, projectC, projectD, projectE);

            actual.Should().BeEquivalentTo(expected);

            // Now we run
            var results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectB, projectC, projectD, projectE);

            checker.ReportStatus(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);
            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);
                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
                }, projectA, projectB, projectC);
                checker.ReportStatus(results);

                // Act & Assert
                actual = checker.PerformUpToDateCheck(dgSpec);
                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);
                var expected = GetUniqueNames(projectA, projectB, projectC, projectD);
                actual.Should().BeEquivalentTo(expected);
                var results = RunRestore(failedProjects: new HashSet <string>(), projectA, projectB, projectC, projectD);
                checker.ReportStatus(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);
                expected = GetUniqueNames(projectA, projectC);
                actual.Should().BeEquivalentTo(expected);
            }
        }