Exemple #1
0
        public void CanSortEmptyList()
        {
            var items = new List <PackageInProject>();

            var sorter = new PackageInProjectTopologicalSort(Substitute.For <INuKeeperLogger>());

            var sorted = sorter.Sort(items)
                         .ToList();

            Assert.That(sorted, Is.Not.Null);
            Assert.That(sorted, Is.Empty);
        }
        public void CanSortOneItem()
        {
            var items = new List <PackageInProject>
            {
                PackageFor("foo", "1.2.3", "bar{sep}fish.csproj"),
            };

            var sorter = new PackageInProjectTopologicalSort(Substitute.For <INuKeeperLogger>());

            var sorted = sorter.Sort(items)
                         .ToList();

            AssertIsASortOf(sorted, items);
            Assert.That(sorted[0], Is.EqualTo(items[0]));
        }
        public void CanSortTwoUnrelatedItems()
        {
            var items = new List <PackageInProject>
            {
                PackageFor("foo", "1.2.3", "bar{sep}fish.csproj"),
                PackageFor("bar", "2.3.4", "project2{sep}p2.csproj")
            };

            var logger = Substitute.For <INuKeeperLogger>();

            var sorter = new PackageInProjectTopologicalSort(logger);

            var sorted = sorter.Sort(items)
                         .ToList();

            AssertIsASortOf(sorted, items);
            logger.Received(1).Detailed("No dependencies between items, no need to sort on dependencies");
        }
Exemple #4
0
        public void CanSortTwoRelatedItemsinReverseOrder()
        {
            var aProj    = PackageFor("foo", "1.2.3", "someproject{sep}someproject.csproj");
            var testProj = PackageFor("bar", "2.3.4", "someproject.tests{sep}someproject.tests.csproj", aProj);

            var items = new List <PackageInProject>
            {
                aProj,
                testProj
            };

            var logger = Substitute.For <INuKeeperLogger>();

            var sorter = new PackageInProjectTopologicalSort(logger);

            var sorted = sorter.Sort(items)
                         .ToList();

            AssertIsASortOf(sorted, items);
            Assert.That(sorted[0], Is.EqualTo(testProj));
            Assert.That(sorted[1], Is.EqualTo(aProj));

            logger.Received(1).Detailed(Arg.Is <string>(s => s.StartsWith("Resorted 2 projects by dependencies,")));
        }
Exemple #5
0
        public void CanSortWithCycle()
        {
            var aProj    = PackageFor("foo", "1.2.3", "someproject{sep}someproject.csproj");
            var testProj = PackageFor("bar", "2.3.4", "someproject.tests{sep}someproject.tests.csproj", aProj);

            // fake a circular ref - aproj is a new object but the same file path as above
            aProj = PackageFor("foo", "1.2.3", "someproject{sep}someproject.csproj", testProj);

            var items = new List <PackageInProject>
            {
                aProj,
                testProj
            };

            var logger = Substitute.For <INuKeeperLogger>();

            var sorter = new PackageInProjectTopologicalSort(logger);

            var sorted = sorter.Sort(items)
                         .ToList();

            AssertIsASortOf(sorted, items);
            logger.Received(1).Minimal(Arg.Is <string>(s => s.StartsWith("Cannot sort by dependencies, cycle found at item")));
        }
Exemple #6
0
        private IEnumerable <PackageInProject> Sort(IReadOnlyCollection <PackageInProject> packages)
        {
            var sorter = new PackageInProjectTopologicalSort(_logger);

            return(sorter.Sort(packages));
        }