Пример #1
0
        public void GivenAProjectWithATopLevelDependencyVerifyAllFrameworksInTargetGraphs()
        {
            var range = VersionRange.Parse("(, 2.0.0)");
            var tfi   = new List <TargetFrameworkInformation>
            {
                new TargetFrameworkInformation()
                {
                    FrameworkName = NuGetFramework.Parse("netstandard2.0")
                },
                new TargetFrameworkInformation()
                {
                    FrameworkName = NuGetFramework.Parse("net46")
                }
            };

            var project = new PackageSpec(tfi)
            {
                Name = "proj"
            };

            project.Dependencies.Add(new LibraryDependency()
            {
                LibraryRange = new LibraryRange("x", range, LibraryDependencyTarget.Package)
            });

            var log = UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Single();

            log.Code.Should().Be(NuGetLogCode.NU1604);
            log.TargetGraphs.ShouldBeEquivalentTo(new[] { NuGetFramework.Parse("netstandard2.0").DotNetFrameworkName, NuGetFramework.Parse("net46").DotNetFrameworkName });
        }
Пример #2
0
        public void GivenAProjectWithCorrectDependenciesVerifyNoMissingLowerBoundWarnings()
        {
            var tfi     = GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("a", VersionRange.Parse("1.0.0"), LibraryDependencyTarget.Package));
            var project = new PackageSpec(tfi)
            {
                Name         = "proj",
                Dependencies = GetDependencyList(new LibraryRange("b", VersionRange.Parse("1.0.0"), LibraryDependencyTarget.Package))
            };

            UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Should().BeEmpty("all dependencies are valid");
        }
Пример #3
0
        public void GivenAProjectWithNullRangesForNonPackageDependenciesVersionNoWarnings()
        {
            var tfi     = GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("a", null, LibraryDependencyTarget.Project));
            var project = new PackageSpec(tfi)
            {
                Name         = "proj",
                Dependencies = GetDependencyList(new LibraryRange("b", null, LibraryDependencyTarget.Reference))
            };

            UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Should().BeEmpty("non-project references should be ignored");
        }
Пример #4
0
        public void GivenAProjectWithADependencyOnAPackageWithANullRanageVerifyWarningMessage()
        {
            var tfi     = GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("x", null, LibraryDependencyTarget.Package));
            var project = new PackageSpec(tfi)
            {
                Name = "proj"
            };

            var log = UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Single();

            log.Code.Should().Be(NuGetLogCode.NU1604);
            log.Message.Should().Be("Project dependency x does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.");
        }
Пример #5
0
        public void GivenAProjectWithMultipleFrameworksAndDifferentRangesVerifyDifferentWarningsPerPackage()
        {
            var tfi = new List <TargetFrameworkInformation>();

            tfi.AddRange(GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("x", VersionRange.Parse("(, 2.0.0)"), LibraryDependencyTarget.Package)));
            tfi.AddRange(GetTFI(NuGetFramework.Parse("netstandard1.3"), new LibraryRange("x", VersionRange.Parse("(, 2.0.0]"), LibraryDependencyTarget.Package)));

            var project = new PackageSpec(tfi)
            {
                Name = "proj"
            };

            UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Count().Should().Be(2);
        }
Пример #6
0
        public void GivenAProjectWithAFrameworkSpecificDependencyVerifySingleTargetGraph()
        {
            var badRange  = VersionRange.Parse("(, 2.0.0)");
            var goodRange = VersionRange.Parse("[2.0.0]");
            var badTfi    = GetTFI(NuGetFramework.Parse("netstandard2.0"), new LibraryRange("x", badRange, LibraryDependencyTarget.Package));
            var goodTfi   = GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("x", goodRange, LibraryDependencyTarget.Package));

            var project = new PackageSpec(badTfi.Concat(goodTfi).ToList())
            {
                Name = "proj"
            };

            var log = UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project).Single();

            log.Code.Should().Be(NuGetLogCode.NU1604);
            log.TargetGraphs.ShouldBeEquivalentTo(
                new[] { NuGetFramework.Parse("netstandard2.0").DotNetFrameworkName },
                "net46 contains a valid range that should be filtered out");
        }
Пример #7
0
        public void GivenAProjectWithMultipleDependencyBoundIssuesVerifyWarnings()
        {
            var tfi = new List <TargetFrameworkInformation>();

            tfi.AddRange(GetTFI(NuGetFramework.Parse("net46"), new LibraryRange("x", VersionRange.Parse("(, 2.0.0)"), LibraryDependencyTarget.Package)));
            tfi.AddRange(GetTFI(NuGetFramework.Parse("netstandard1.3"), new LibraryRange("y", VersionRange.Parse("(, 3.0.0)"), LibraryDependencyTarget.Package)));

            var project = new PackageSpec(tfi)
            {
                Name = "proj"
            };

            var logs = UnexpectedDependencyMessages.GetProjectDependenciesMissingLowerBounds(project);

            logs.Select(e => e.Code).ShouldAllBeEquivalentTo(NuGetLogCode.NU1604);
            logs.Select(e => e.Level).ShouldAllBeEquivalentTo(LogLevel.Warning);
            logs.Select(e => e.Message)
            .ShouldBeEquivalentTo(new[]
            {
                "Project dependency x (< 2.0.0) does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.",
                "Project dependency y (< 3.0.0) does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results."
            });
        }