Exemplo n.º 1
0
        public async Task LocalDependencyInfoResource_SinglePackageAsync()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                var testLogger = new TestLogger();

                var packageX = new SimpleTestPackageContext()
                {
                    Id      = "x",
                    Version = "1.0.0"
                };

                var packageA = new SimpleTestPackageContext()
                {
                    Id           = "a",
                    Version      = "1.0.0",
                    Dependencies = new List <SimpleTestPackageContext>()
                    {
                        packageX
                    }
                };

                var packageContexts = new SimpleTestPackageContext[]
                {
                    packageA,
                    packageX
                };

                await SimpleTestPackageUtility.CreatePackagesAsync(root, packageContexts);

                var source        = Repository.Factory.GetCoreV3(root);
                var localResource = new FindLocalPackagesResourceV2(root);
                var resource      = new LocalDependencyInfoResource(localResource, source);

                // Act
                var result = (await resource.ResolvePackage(
                                  packageA.Identity,
                                  NuGetFramework.Parse("net46"),
                                  NullSourceCacheContext.Instance,
                                  testLogger,
                                  CancellationToken.None));

                // Assert
                Assert.Equal(packageA.Identity, result, PackageIdentity.Comparer);
                Assert.True(result.Listed);
                Assert.Contains("a.1.0.0.nupkg", result.DownloadUri.LocalPath);
                Assert.Equal(1, result.Dependencies.Count());
                Assert.Equal("x", result.Dependencies.Single().Id);
            }
        }
Exemplo n.º 2
0
        public async Task LocalDependencyInfoResource_SinglePackageNotFoundAsync()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                var testLogger = new TestLogger();

                var packageX = new SimpleTestPackageContext()
                {
                    Id      = "x",
                    Version = "1.0.0"
                };

                var packageA = new SimpleTestPackageContext()
                {
                    Id           = "a",
                    Version      = "1.0.0",
                    Dependencies = new List <SimpleTestPackageContext>()
                    {
                        packageX
                    }
                };

                var packageContexts = new SimpleTestPackageContext[]
                {
                    packageA,
                    packageX
                };

                await SimpleTestPackageUtility.CreatePackagesAsync(root, packageContexts);

                var source        = Repository.Factory.GetCoreV3(root);
                var localResource = new FindLocalPackagesResourceV2(root);
                var resource      = new LocalDependencyInfoResource(localResource, source);

                // Act
                var result = (await resource.ResolvePackage(
                                  new PackageIdentity("z", NuGetVersion.Parse("1.0.0")),
                                  NuGetFramework.Parse("net46"),
                                  NullSourceCacheContext.Instance,
                                  testLogger,
                                  CancellationToken.None));

                // Assert
                Assert.Null(result);
            }
        }
Exemplo n.º 3
0
        public async Task LocalDependencyInfoResource_SinglePackageNotFoundEmptyFolder()
        {
            using (var root = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Arrange
                var testLogger = new TestLogger();

                var source        = Repository.Factory.GetCoreV3(root);
                var localResource = new FindLocalPackagesResourceV2(root);
                var resource      = new LocalDependencyInfoResource(localResource, source);

                // Act
                var result = (await resource.ResolvePackage(
                                  new PackageIdentity("z", NuGetVersion.Parse("1.0.0")),
                                  NuGetFramework.Parse("net46"),
                                  testLogger,
                                  CancellationToken.None));

                // Assert
                Assert.Null(result);
            }
        }
Exemplo n.º 4
0
        public async Task LocalDependencyInfoResource_SinglePackageNearestDependencyGroupAsync()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                var testLogger = new TestLogger();

                var packageA = new SimpleTestPackageContext()
                {
                    Id      = "a",
                    Version = "1.0",
                    Nuspec  = XDocument.Parse($@"<?xml version=""1.0"" encoding=""utf-8""?>
                        <package>
                        <metadata>
                            <id>a</id>
                            <version>1.0</version>
                            <title />
                            <dependencies>
                                <group>
                                    <dependency id=""b"" version=""1.0"" />
                                </group>
                                <group targetFramework=""net46"">
                                    <dependency id=""x"" />
                                </group>
                                <group targetFramework=""net461"">
                                </group>
                            </dependencies>
                        </metadata>
                        </package>")
                };

                var packageContexts = new SimpleTestPackageContext[]
                {
                    packageA
                };

                await SimpleTestPackageUtility.CreatePackagesAsync(root, packageContexts);

                var source        = Repository.Factory.GetCoreV3(root);
                var localResource = new FindLocalPackagesResourceV2(root);
                var resource      = new LocalDependencyInfoResource(localResource, source);

                // Act
                var resultNet462 = (await resource.ResolvePackage(
                                        packageA.Identity,
                                        NuGetFramework.Parse("net462"),
                                        NullSourceCacheContext.Instance,
                                        testLogger,
                                        CancellationToken.None));

                var resultNet46 = (await resource.ResolvePackage(
                                       packageA.Identity,
                                       NuGetFramework.Parse("net46"),
                                       NullSourceCacheContext.Instance,
                                       testLogger,
                                       CancellationToken.None));

                var resultWin8 = (await resource.ResolvePackage(
                                      packageA.Identity,
                                      NuGetFramework.Parse("win8"),
                                      NullSourceCacheContext.Instance,
                                      testLogger,
                                      CancellationToken.None));

                // Assert
                Assert.Equal(0, resultNet462.Dependencies.Count());
                Assert.Equal(1, resultNet46.Dependencies.Count());
                Assert.Equal(1, resultWin8.Dependencies.Count());

                Assert.Equal("x", resultNet46.Dependencies.Single().Id);
                Assert.Equal(VersionRange.All, resultNet46.Dependencies.Single().VersionRange);
                Assert.Equal("b", resultWin8.Dependencies.Single().Id);
                Assert.Equal(VersionRange.Parse("1.0"), resultWin8.Dependencies.Single().VersionRange);
            }
        }