Пример #1
0
        public void ShouldOrderCommonDepsTopologicalBySolution(DependencySortOrder sortMode)
        {
            int projectCount = 10;
            var ws           = testData.GetLinearSolution(projectCount);
            var before       = ws.CurrentSolution.Projects.Select(p => p.Id).ToArray();
            var sln          = testData.AddRandomReferences(ws).CurrentSolution;

            sln.Projects.Select(p => p.Id).ToArray().Should().Equal(before);
            var projects = sln.Projects.ToDictionary(k => new FileInfoKey(k.FilePath), v => v);

            var dependencyOrder = new DependencyOrder(sln, sln.GetProjectDependencyGraph(), projects, sortMode, this.logger);

            var sorted = dependencyOrder.AllSortedProjectIds;

            sorted.Should().NotEqual(before);

            var result     = sorted.Select(i => sln.GetProject(i)).ToArray();
            var passed     = new HashSet <string>();
            int references = 0;

            foreach (var r in result)
            {
                var refedProjectNames = r.ProjectReferences.Select(p => sln.GetProject(p.ProjectId)?.Name).ToArray();
                foreach (var name in refedProjectNames)
                {
                    Assert.Contains(name, passed);
                    references++;
                }

                passed.Add(r.Name);
            }
        }
Пример #2
0
        public void ShouldOrderCommonDepsByDate(bool useGitDate)
        {
            int projectCount = 100;
            var ws           = testData.GetLinearSolution(projectCount);

            if (useGitDate)
            {
                void Git(string args)
                {
                    var p = Process.Start(new ProcessStartInfo("git", args)
                    {
                        WorkingDirectory = this.testData.Root, RedirectStandardOutput = true, RedirectStandardError = true
                    });

                    p.WaitForExit();
                    this.logger.Debug(p.StandardError.ReadToEnd() + p.StandardError.ReadToEnd());
                }

                Git("init");
                Git("add *5*");
                Git($"commit -m past --date \"{DateTime.Now.AddHours(-1):s}\"");
                Git("add .");
                Git("commit -m present");
            }

            var before = ws.CurrentSolution.Projects.Select(p => p.Id).ToArray();
            var sln    = testData.AddRandomReferences(ws).CurrentSolution;

            sln.Projects.Select(p => p.Id).ToArray().Should().Equal(before);
            var projects = sln.Projects.ToDictionary(k => new FileInfoKey(k.FilePath), v => v);

            Thread.Sleep(1000);
            foreach (var directoryInfo in projects
                     .Where(p => p.Value.Name.Contains("3"))
                     .Select(p => p.Key.Info.Directory).Distinct())
            {
                directoryInfo.LastWriteTimeUtc = DateTime.UtcNow.AddSeconds(10);
            }

            var dependencyOrder = new DependencyOrder(sln, sln.GetProjectDependencyGraph(), projects, DependencySortOrder.DateModified, this.logger);

            var sorted = dependencyOrder.AllSortedProjectIds;

            sorted.Should().NotEqual(before);
            var result = sorted.Select(i => sln.GetProject(i)).ToArray();

            if (!useGitDate)
            {
                foreach (var p in result.Skip(projectCount - 10))
                {
                    p.Name.Should().Contain("3");
                }
            }
            else
            {
                Assert.Equal(useGitDate, result.Take(10).All(p => p != null && p.Name.Contains("5")));
            }
            result.Select(p => DependencyOrder.GetProjectTime(p.FilePath, this.logger)).Should().BeInAscendingOrder();
        }