コード例 #1
0
        public void CreateFromClosure_WhenClosureIsNull_Throws()
        {
            var dgSpec = new DependencyGraphSpec();

            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(
                () => dgSpec.CreateFromClosure(PackageSpecName, closure: null));

            Assert.Equal("closure", exception.ParamName);
        }
コード例 #2
0
        public void CreateFromClosure_WhenProjectUniqueNameIsNullOrEmpty_Throws(string projectUniqueName)
        {
            IReadOnlyList <PackageSpec> closure = new[] { new PackageSpec() };
            var dgSpec = new DependencyGraphSpec();

            ArgumentException exception = Assert.Throws <ArgumentException>(
                () => dgSpec.CreateFromClosure(projectUniqueName, closure));

            Assert.Equal("projectUniqueName", exception.ParamName);
        }
コード例 #3
0
        public void CreateFromClosure_WhenReadOnlyIsTrue_ReturnsSameClosure()
        {
            var expectedResult = new PackageSpec()
            {
                RestoreMetadata = new ProjectRestoreMetadata()
            };
            IReadOnlyList <PackageSpec> closure = new[] { expectedResult };
            var dgSpec = new DependencyGraphSpec(isReadOnly: true);

            DependencyGraphSpec newDgSpec = dgSpec.CreateFromClosure(PackageSpecName, closure);

            Assert.Collection(
                newDgSpec.Restore,
                actualResult => Assert.Equal(PackageSpecName, actualResult));

            Assert.Collection(
                newDgSpec.Projects,
                actualResult => Assert.Same(expectedResult, actualResult));
        }
コード例 #4
0
        public void CreateFromClosure_WhenReadOnlyIsFalse_ReturnsClonedClosure()
        {
            var expectedResult = new PackageSpec()
            {
                IsDefaultVersion = false,
                RestoreMetadata  = new ProjectRestoreMetadata()
            };
            IReadOnlyList <PackageSpec> closure = new[] { expectedResult };
            var dgSpec = new DependencyGraphSpec(isReadOnly: false);

            DependencyGraphSpec newDgSpec = dgSpec.CreateFromClosure(PackageSpecName, closure);

            Assert.Collection(
                newDgSpec.Restore,
                actualResult => Assert.Equal(PackageSpecName, actualResult));

            Assert.Collection(
                newDgSpec.Projects,
                actualResult =>
            {
                Assert.True(expectedResult.Equals(actualResult));
                Assert.NotSame(expectedResult, actualResult);
            });
        }
コード例 #5
0
        private IReadOnlyList <RestoreSummaryRequest> GetRequestsFromItems(RestoreArgs restoreContext, DependencyGraphSpec dgFile)
        {
            if (restoreContext == null)
            {
                throw new ArgumentNullException(nameof(restoreContext));
            }

            if (dgFile == null)
            {
                throw new ArgumentNullException(nameof(dgFile));
            }

            // Validate the dg file input, this throws if errors are found.
            SpecValidationUtility.ValidateDependencySpec(dgFile);

            // Create requests
            var requests     = new ConcurrentBag <RestoreSummaryRequest>();
            var toolRequests = new ConcurrentBag <RestoreSummaryRequest>();

            var parallelOptions = new ParallelOptions
            {
                // By default, max degree of parallelism is -1 which means no upper bound.
                // Limiting to processor count reduces task context switching which is better
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            using (var settingsLoadingContext = new SettingsLoadingContext())
            {
                // Parallel.Foreach has an optimization for Arrays, so calling .ToArray() is better and adds almost no overhead
                Parallel.ForEach(dgFile.Restore.ToArray(), parallelOptions, projectNameToRestore =>
                {
                    IReadOnlyList <PackageSpec> closure            = dgFile.GetClosure(projectNameToRestore);
                    DependencyGraphSpec projectDependencyGraphSpec = dgFile.CreateFromClosure(projectNameToRestore, closure);

                    var externalClosure = new HashSet <ExternalProjectReference>(closure.Select(GetExternalProject));

                    ExternalProjectReference rootProject = externalClosure.Single(p =>
                                                                                  StringComparer.Ordinal.Equals(projectNameToRestore, p.UniqueName));

                    RestoreSummaryRequest request = Create(
                        projectNameToRestore,
                        rootProject,
                        externalClosure,
                        restoreContext,
                        projectDependencyGraphSpec,
                        settingsLoadingContext);

                    if (request.Request.ProjectStyle == ProjectStyle.DotnetCliTool)
                    {
                        // Store tool requests to be filtered later
                        toolRequests.Add(request);
                    }
                    else
                    {
                        requests.Add(request);
                    }
                });
            }

            // Filter out duplicate tool restore requests
            foreach (RestoreSummaryRequest subSetRequest in ToolRestoreUtility.GetSubSetRequests(toolRequests))
            {
                requests.Add(subSetRequest);
            }

            return(requests.ToArray());
        }