예제 #1
0
        public async Task Cycle_TransitiveProjectWithSameNameAsPackageVerifyCycleDetectedAsync(string packageId)
        {
            // Arrange
            using (var cacheContext = new SourceCacheContext())
                using (var pathContext = new SimpleTestPathContext())
                {
                    var logger  = new TestLogger();
                    var sources = new List <PackageSource>
                    {
                        new PackageSource(pathContext.PackageSource)
                    };

                    var spec1 = NETCoreRestoreTestUtility.GetProject(projectName: "projectA", framework: "netstandard1.6");
                    var spec2 = NETCoreRestoreTestUtility.GetProject(projectName: "projectB", framework: "netstandard1.6");

                    spec2.TargetFrameworks[0].Dependencies.Add(new LibraryDependency()
                    {
                        LibraryRange = new LibraryRange(packageId, VersionRange.Parse("1.0.0"), LibraryDependencyTarget.Package)
                    });

                    var specs = new[] { spec1, spec2 };

                    var projects = NETCoreRestoreTestUtility.CreateProjectsFromSpecs(pathContext, specs);

                    // Link projects
                    spec1.RestoreMetadata.TargetFrameworks.Single().ProjectReferences.Add(new ProjectRestoreReference()
                    {
                        ProjectPath       = projects[1].ProjectPath,
                        ProjectUniqueName = spec2.RestoreMetadata.ProjectUniqueName,
                    });

                    await SimpleTestPackageUtility.CreateFolderFeedV2Async(pathContext.PackageSource, new PackageIdentity("projectA", NuGetVersion.Parse("1.0.0")));

                    await SimpleTestPackageUtility.CreateFolderFeedV2Async(pathContext.PackageSource, new PackageIdentity("projectB", NuGetVersion.Parse("1.0.0")));

                    // Create dg file
                    var dgFile = new DependencyGraphSpec();

                    // Only add projectA
                    dgFile.AddProject(spec1);
                    dgFile.AddProject(spec2);
                    dgFile.AddRestore(spec1.RestoreMetadata.ProjectUniqueName);

                    dgFile.Save(Path.Combine(pathContext.WorkingDirectory, "out.dg"));

                    // Act
                    var summaries = await NETCoreRestoreTestUtility.RunRestore(pathContext, logger, sources, dgFile, cacheContext);

                    var success = summaries.All(s => s.Success);

                    // Assert
                    Assert.False(success, "Failed: " + string.Join(Environment.NewLine, logger.Messages));
                    Assert.Contains("Cycle detected", string.Join(Environment.NewLine, logger.ErrorMessages));
                }
        }
예제 #2
0
        private async Task CreateFeedsAsync(string rootV2, string rootV3, string rootUnzip, string rootPackagesConfig, params PackageIdentity[] packages)
        {
            foreach (var package in packages)
            {
                await SimpleTestPackageUtility.CreateFolderFeedV2Async(rootV2, package);

                await SimpleTestPackageUtility.CreateFolderFeedV3Async(rootV3, package);

                await SimpleTestPackageUtility.CreateFolderFeedUnzipAsync(rootUnzip, package);

                await SimpleTestPackageUtility.CreateFolderFeedPackagesConfigAsync(rootPackagesConfig, package);
            }
        }
        public async Task FindPackageByIdResource_V2V3CompareAsync()
        {
            using (var rootV3 = TestDirectory.Create())
                using (var rootV2 = TestDirectory.Create())
                {
                    // Arrange
                    var testLogger = new TestLogger();

                    var a1 = new PackageIdentity("a", NuGetVersion.Parse("1.0.0-alpha.1.2"));
                    var a2 = new PackageIdentity("a", NuGetVersion.Parse("1.0.0+server.2"));
                    var b  = new PackageIdentity("b", NuGetVersion.Parse("1.0.0.0"));

                    await SimpleTestPackageUtility.CreateFolderFeedV2Async(rootV2, a1, a2, b);

                    await SimpleTestPackageUtility.CreateFolderFeedV3Async(rootV3, a1, a2, b);

                    var resourceV2 = new LocalV2FindPackageByIdResource(new PackageSource(rootV2));
                    var resourceV3 = new LocalV3FindPackageByIdResource(new PackageSource(rootV3));

                    using (var cacheContext = new SourceCacheContext())
                    {
                        var bNonNorm = new PackageIdentity("B", NuGetVersion.Parse("1.0"));

                        // Act
                        var versionsV2 = new HashSet <NuGetVersion>(await resourceV2.GetAllVersionsAsync(
                                                                        "A",
                                                                        cacheContext,
                                                                        testLogger,
                                                                        CancellationToken.None));

                        var versionsV3 = new HashSet <NuGetVersion>(await resourceV3.GetAllVersionsAsync(
                                                                        "A",
                                                                        cacheContext,
                                                                        testLogger,
                                                                        CancellationToken.None));

                        var emptyV2 = (await resourceV2.GetAllVersionsAsync(
                                           "c",
                                           cacheContext,
                                           testLogger,
                                           CancellationToken.None))
                                      .ToList();

                        var emptyV3 = (await resourceV3.GetAllVersionsAsync("c",
                                                                            cacheContext,
                                                                            testLogger,
                                                                            CancellationToken.None))
                                      .ToList();

                        var v2Stream = new MemoryStream();
                        await resourceV2.CopyNupkgToStreamAsync(
                            bNonNorm.Id,
                            bNonNorm.Version,
                            v2Stream,
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        var v3Stream = new MemoryStream();
                        await resourceV3.CopyNupkgToStreamAsync(
                            bNonNorm.Id,
                            bNonNorm.Version,
                            v3Stream,
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        var depV2 = await resourceV2.GetDependencyInfoAsync(
                            bNonNorm.Id,
                            bNonNorm.Version,
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        var depV3 = await resourceV3.GetDependencyInfoAsync(
                            bNonNorm.Id,
                            bNonNorm.Version,
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        var depEmptyV2 = await resourceV2.GetDependencyInfoAsync(
                            bNonNorm.Id,
                            NuGetVersion.Parse("2.9"),
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        var depEmptyV3 = await resourceV3.GetDependencyInfoAsync(
                            bNonNorm.Id,
                            NuGetVersion.Parse("2.9"),
                            cacheContext,
                            testLogger,
                            CancellationToken.None);

                        // Assert
                        Assert.True(versionsV2.SetEquals(versionsV3));
                        Assert.Equal(0, emptyV2.Count);
                        Assert.Equal(0, emptyV3.Count);
                        Assert.True(v2Stream.Length > 0);
                        Assert.True(v3Stream.Length > 0);
                        Assert.Equal(0, depV2.DependencyGroups.Count);
                        Assert.Equal(0, depV3.DependencyGroups.Count);
                        Assert.Null(depEmptyV2);
                        Assert.Null(depEmptyV3);
                    }
                }
        }