Exemplo n.º 1
0
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageIdentity.Id, new VersionRange(packageIdentity.Version));

            var json = await GetJsonAsync();

            JsonConfigUtility.AddDependency(json, dependency);
            await SaveJsonAsync(json);

            var packageReader = downloadResourceResult.PackageReader
                                ?? new PackageArchiveReader(downloadResourceResult.PackageStream, leaveStreamOpen: true);
            IAsyncPackageContentReader packageContentReader = packageReader;
            IAsyncPackageCoreReader    packageCoreReader    = packageReader;

            var libItemGroups = await packageContentReader.GetLibItemsAsync(token);

            var referenceItemGroups = await packageContentReader.GetReferenceItemsAsync(token);

            var frameworkReferenceGroups = await packageContentReader.GetFrameworkItemsAsync(token);

            var contentFileGroups = await packageContentReader.GetContentItemsAsync(token);

            var buildFileGroups = await packageContentReader.GetBuildItemsAsync(token);

            var toolItemGroups = await packageContentReader.GetToolItemsAsync(token);

            var depsGroups = await packageContentReader.GetPackageDependenciesAsync(token);

            IEnumerable <FrameworkSpecificGroup> refItemGroups = null;

            if (packageReader is PackageArchiveReader reader)
            {
                refItemGroups = await reader.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }
            else if (packageReader is PackageFolderReader reader2)
            {
                refItemGroups = await reader2.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }

            var deps  = (PackageDependencyInfo)NuGetProjectActions.First(x => x.PackageIdentity.Equals(packageIdentity)).PackageIdentity;
            var entry = new WorkspaceEntry(packageIdentity, GetSha(downloadResourceResult.PackageStream),
                                           depsGroups, libItemGroups, toolItemGroups, refItemGroups, _mainFile);

            if (!SdkList.Dlls.Contains(entry.PackageIdentity.Id.ToLower()))
            {
                var workspace = await GetWorkspaceAsync();

                var updater = new WorkspaceWriter();
                var updated = updater.AddEntry(workspace, entry);
                await SaveWorkspaceAsync(updated);
            }

            return(await base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
        }
        public async Task <bool> AddDependency(PackageDependency dependency,
                                               CancellationToken token)
        {
            var json = await GetJsonAsync();

            JsonConfigUtility.AddDependency(json, dependency);

            await SaveJsonAsync(json);

            return(true);
        }
Exemplo n.º 3
0
        public void JsonConfigUtility_AddDependencyToNewFile()
        {
            // Arrange
            var json = BasicConfig;

            // Act
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackage", VersionRange.Parse("1.0.0")));

            // Assert
            Assert.Equal("1.0.0", json["dependencies"]["testpackage"].ToString());
        }
Exemplo n.º 4
0
        public async override Task <bool> InstallPackageAsync(
            string packageId,
            VersionRange range,
            INuGetProjectContext nuGetProjectContext,
            BuildIntegratedInstallationContext installationContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageId, range);

            var json = await GetJsonAsync();

            JsonConfigUtility.AddDependency(json, dependency);

            await SaveJsonAsync(json);

            return(true);
        }
Exemplo n.º 5
0
        public OneDasPackageManager(IExtensionFactory extensionFactory, IOptions <OneDasOptions> options, ILoggerFactory loggerFactory)
        {
            JObject      jobject;
            VersionRange versionRange;

            _extensionFactory = extensionFactory;
            _options          = options.Value;

            // settings
            _settings = new Settings(_options.NugetDirectoryPath);
            _settings.SetValues(ConfigurationConstants.PackageSources, new List <SettingValue>()
            {
                new SettingValue("NuGet", "https://api.nuget.org/v3/index.json", false)
            });
            _settings.SetValues(ConfigurationConstants.PackageSources, new List <SettingValue>()
            {
                new SettingValue("MyGet (CI)", "https://www.myget.org/F/onedas/api/v3/index.json", false)
            });

            if (!File.Exists(_options.NugetProjectFilePath))
            {
                jobject      = new JObject();
                versionRange = new VersionRange(new NuGetVersion("2.0.3"));

                JsonConfigUtility.AddFramework(jobject, FrameworkConstants.CommonFrameworks.NetStandard20);
                JsonConfigUtility.AddDependency(jobject, new PackageDependency("NETStandard.Library", versionRange));

                jobject.Add("runtimes", new JObject(new JProperty(_options.RestoreRuntimeId, new JObject())));

                File.WriteAllText(_options.NugetProjectFilePath, jobject.ToString(Formatting.Indented));
            }

            _project                  = new OneDasNugetProject(_options.NugetProjectFilePath);
            _projectContext           = new OneDasNuGetProjectContext(loggerFactory.CreateLogger("Nuget"));
            _sourceRepositoryProvider = this.CreateSourceRepositoryProvider();
            _packageManager           = this.CreateNuGetPackageManager(_sourceRepositoryProvider);

            this.PackageSourceSet = SettingsUtility.GetEnabledSources(_settings).ToList();
        }
Exemplo n.º 6
0
        public void JsonConfigUtility_VerifyPackagesAreSortedInProjectJson()
        {
            // Arrange
            var json = BasicConfig;

            // Act
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackageb", VersionRange.Parse("1.0.0")));
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackageE", VersionRange.Parse("2.0.0")));
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackageA", VersionRange.Parse("1.0.0")));
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackaged", VersionRange.Parse("4.0.0")));
            JsonConfigUtility.AddDependency(json, new PackageDependency("testpackageC", VersionRange.Parse("1.0.0")));

            JToken val = null;

            json.TryGetValue("dependencies", out val);

            // Assert
            Assert.Equal("testpackageA", ((JProperty)json["dependencies"].Children().First()).Name);
            Assert.Equal("testpackageb", ((JProperty)json["dependencies"].Children().Skip(1).First()).Name);
            Assert.Equal("testpackageC", ((JProperty)json["dependencies"].Children().Skip(2).First()).Name);
            Assert.Equal("testpackaged", ((JProperty)json["dependencies"].Children().Skip(3).First()).Name);
            Assert.Equal("testpackageE", ((JProperty)json["dependencies"].Children().Skip(4).First()).Name);
        }
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredWithNoChangesFallbackFolder()
        {
            // Arrange
            var projectName = "testproj";

            using (var globalFolder = TestDirectory.Create())
                using (var fallbackFolder = TestDirectory.Create())
                    using (var rootFolder = TestDirectory.Create())
                    {
                        var projectFolder = new DirectoryInfo(Path.Combine(rootFolder, projectName));
                        projectFolder.Create();
                        var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                        var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                        BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                        var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                        JsonConfigUtility.AddDependency(json, new NuGet.Packaging.Core.PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                        using (var writer = new StreamWriter(projectConfig.FullName))
                        {
                            writer.Write(json.ToString());
                        }

                        var sources = new List <SourceRepository>
                        {
                            Repository.Factory.GetVisualStudio("https://www.nuget.org/api/v2/")
                        };

                        var projectTargetFramework    = NuGetFramework.Parse("uap10.0");
                        var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext());
                        var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);

                        // Restore to the fallback folder
                        var solutionManager = new TestSolutionManager(false);
                        solutionManager.NuGetProjects.Add(project);

                        var testLogger = new TestLogger();

                        var restoreContext = new DependencyGraphCacheContext(testLogger, NullSettings.Instance);

                        await DependencyGraphRestoreUtility.RestoreAsync(
                            solutionManager,
                            restoreContext,
                            new RestoreCommandProvidersCache(),
                            (c) => { },
                            sources,
                            false,
                            await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                            testLogger,
                            CancellationToken.None);

                        var packageFolders = new List <string> {
                            globalFolder, fallbackFolder
                        };

                        // Act
                        //var actual = await project.IsRestoreRequired(
                        //    packageFolders.Select(p => new VersionFolderPathResolver(p)),
                        //    new HashSet<PackageIdentity>(),
                        //    restoreContext);

                        // Assert
                        //Assert.False(actual);
                    }
        }
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredChangedSha512()
        {
            // Arrange
            var projectName = "testproj";

            using (var packagesFolder = TestDirectory.Create())
                using (var rootFolder = TestDirectory.Create())
                {
                    var projectFolder = new DirectoryInfo(Path.Combine(rootFolder, projectName));
                    projectFolder.Create();
                    var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                    var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                    BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                    var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                    JsonConfigUtility.AddDependency(json, new PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                    using (var writer = new StreamWriter(projectConfig.FullName))
                    {
                        writer.Write(json.ToString());
                    }

                    var sources = new List <SourceRepository> {
                    };

                    var testLogger = new TestLogger();
                    var settings   = new Settings(rootFolder);
                    settings.SetValue(SettingsUtility.ConfigSection, "globalPackagesFolder", packagesFolder);

                    var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);

                    var solutionManager = new TestSolutionManager(false);
                    solutionManager.NuGetProjects.Add(project);

                    var restoreContext = new DependencyGraphCacheContext(testLogger, settings);
                    var providersCache = new RestoreCommandProvidersCache();
                    var dgSpec1        = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext);

                    await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        providersCache,
                        (c) => { },
                        sources,
                        false,
                        dgSpec1,
                        testLogger,
                        CancellationToken.None);

                    var dgSpec2 = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext);

                    var noOpRestoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        providersCache,
                        (c) => { },
                        sources,
                        false,
                        dgSpec2,
                        testLogger,
                        CancellationToken.None);

                    foreach (var restoreSummary in noOpRestoreSummaries)
                    {
                        Assert.True(restoreSummary.NoOpRestore);
                    }

                    var resolver = new VersionFolderPathResolver(packagesFolder);
                    var hashPath = resolver.GetHashPath("nuget.versioning", NuGetVersion.Parse("1.0.7"));

                    using (var writer = new StreamWriter(hashPath))
                    {
                        writer.Write("ANAWESOMELYWRONGHASH!!!");
                    }

                    var restoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        new RestoreCommandProvidersCache(),
                        (c) => { },
                        sources,
                        false,
                        await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                        testLogger,
                        CancellationToken.None);

                    foreach (var restoreSummary in restoreSummaries)
                    {
                        Assert.True(restoreSummary.Success);
                        Assert.False(restoreSummary.NoOpRestore);
                    }
                }
        }
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredWithNoChanges()
        {
            // Arrange
            var projectName = "testproj";

            using (var packagesFolder = TestDirectory.Create())
                using (var rootFolder = TestDirectory.Create())
                {
                    var projectFolder = new DirectoryInfo(Path.Combine(rootFolder, projectName));
                    projectFolder.Create();
                    var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                    var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                    BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                    var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                    JsonConfigUtility.AddDependency(json, new NuGet.Packaging.Core.PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                    using (var writer = new StreamWriter(projectConfig.FullName))
                    {
                        writer.Write(json.ToString());
                    }

                    var sources = new List <SourceRepository>
                    {
                        Repository.Factory.GetVisualStudio("https://www.nuget.org/api/v2/")
                    };

                    var projectTargetFramework    = NuGetFramework.Parse("uap10.0");
                    var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext());
                    var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);

                    var effectiveGlobalPackagesFolder = SettingsUtility.GetGlobalPackagesFolder(NullSettings.Instance);

                    var solutionManager = new TestSolutionManager(false);
                    solutionManager.NuGetProjects.Add(project);

                    var testLogger = new TestLogger();
                    var settings   = new Settings(rootFolder);
                    settings.SetValue(SettingsUtility.ConfigSection, "globalPackagesFolder", packagesFolder);

                    var providersCache = new RestoreCommandProvidersCache();
                    var restoreContext = new DependencyGraphCacheContext(testLogger, settings);

                    await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        providersCache,
                        (c) => { },
                        sources,
                        false,
                        await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                        testLogger,
                        CancellationToken.None);

                    var noOpRestoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        providersCache,
                        (c) => { },
                        sources,
                        false,
                        await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                        testLogger,
                        CancellationToken.None);

                    foreach (var restoreSummary in noOpRestoreSummaries)
                    {
                        Assert.True(restoreSummary.NoOpRestore);
                    }
                }
        }
Exemplo n.º 10
0
        public async Task BuildIntegratedNuGetProject_RestoreFailed_PersistDGSpecFile()
        {
            // Arrange
            var projectName = "testproj";

            using (var packagesFolder = TestDirectory.Create())
                using (var rootFolder = TestDirectory.Create())
                {
                    var projectFolder = new DirectoryInfo(Path.Combine(rootFolder, projectName));
                    projectFolder.Create();
                    var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                    var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                    BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                    var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                    // invalid version for nuget.versioning package which will make this restore fail.
                    JsonConfigUtility.AddDependency(json, new PackageDependency("nuget.versioning", VersionRange.Parse("3000.0.0")));

                    using (var writer = new StreamWriter(projectConfig.FullName))
                    {
                        writer.Write(json.ToString());
                    }

                    var sources = new List <SourceRepository> {
                    };

                    var testLogger = new TestLogger();
                    var settings   = new Settings(rootFolder);
                    settings.SetValue(SettingsUtility.ConfigSection, "globalPackagesFolder", packagesFolder);

                    var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);

                    var solutionManager = new TestSolutionManager(false);
                    solutionManager.NuGetProjects.Add(project);

                    var restoreContext = new DependencyGraphCacheContext(testLogger, settings);
                    var providersCache = new RestoreCommandProvidersCache();
                    var dgSpec         = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext);

                    var restoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        providersCache,
                        (c) => { },
                        sources,
                        false,
                        dgSpec,
                        testLogger,
                        CancellationToken.None);

                    foreach (var restoreSummary in restoreSummaries)
                    {
                        Assert.False(restoreSummary.Success);
                    }

                    var filePath = Path.Combine(
                        NuGetEnvironment.GetFolderPath(NuGetFolderPath.Temp),
                        "nuget-dg",
                        "nugetSpec.dg");

                    Assert.True(File.Exists(filePath));
                }
        }
Exemplo n.º 11
0
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredChangedSha512()
        {
            // Arrange
            var projectName = "testproj";

            using (var solutionManager = new TestSolutionManager(false))
            {
                var projectFolder = new DirectoryInfo(Path.Combine(solutionManager.SolutionDirectory, projectName));
                projectFolder.Create();
                var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);
                var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                JsonConfigUtility.AddDependency(json, new PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                using (var writer = new StreamWriter(projectConfig.FullName))
                {
                    writer.Write(json.ToString());
                }

                var sources    = new List <SourceRepository> {
                };
                var testLogger = new TestLogger();
                var settings   = Settings.LoadSpecificSettings(solutionManager.SolutionDirectory, "NuGet.Config");
                var project    = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);

                solutionManager.NuGetProjects.Add(project);

                var restoreContext = new DependencyGraphCacheContext(testLogger, settings);
                var providersCache = new RestoreCommandProvidersCache();
                var dgSpec1        = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext);

                await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    dgSpec1,
                    restoreContext,
                    providersCache,
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                var dgSpec2 = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext);

                var noOpRestoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    dgSpec2,
                    restoreContext,
                    providersCache,
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                foreach (var restoreSummary in noOpRestoreSummaries)
                {
                    Assert.True(restoreSummary.NoOpRestore);
                }

                var resolver = new VersionFolderPathResolver(solutionManager.GlobalPackagesFolder);
                var hashPath = resolver.GetHashPath("nuget.versioning", NuGetVersion.Parse("1.0.7"));

                File.Delete(hashPath);

                var restoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                    restoreContext,
                    new RestoreCommandProvidersCache(),
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                foreach (var restoreSummary in restoreSummaries)
                {
                    Assert.True(restoreSummary.Success);
                    Assert.False(restoreSummary.NoOpRestore);
                }

                var filePath = Path.Combine(
                    NuGetEnvironment.GetFolderPath(NuGetFolderPath.Temp),
                    "nuget-dg",
                    "nugetSpec.dg");

                Assert.True(File.Exists(filePath));
            }
        }
Exemplo n.º 12
0
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredMissingPackage()
        {
            // Arrange
            var projectName = "testproj";

            using (var solutionManager = new TestSolutionManager(false))
            {
                var projectFolder = new DirectoryInfo(Path.Combine(solutionManager.SolutionDirectory, projectName));
                projectFolder.Create();
                var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                JsonConfigUtility.AddDependency(json, new NuGet.Packaging.Core.PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                using (var writer = new StreamWriter(projectConfig.FullName))
                {
                    writer.Write(json.ToString());
                }

                var sources = new List <SourceRepository> {
                };

                var projectTargetFramework    = NuGetFramework.Parse("uap10.0");
                var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext());
                var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName);
                solutionManager.NuGetProjects.Add(project);

                var testLogger     = new TestLogger();
                var settings       = Settings.LoadSpecificSettings(solutionManager.SolutionDirectory, "NuGet.Config");
                var restoreContext = new DependencyGraphCacheContext(testLogger, settings);
                var providersCache = new RestoreCommandProvidersCache();

                await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                    restoreContext,
                    providersCache,
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                var noOpRestoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                    restoreContext,
                    providersCache,
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                foreach (var restoreSummary in noOpRestoreSummaries)
                {
                    Assert.True(restoreSummary.NoOpRestore);
                }

                var resolver     = new VersionFolderPathResolver(solutionManager.GlobalPackagesFolder);
                var pathToDelete = resolver.GetInstallPath("nuget.versioning", NuGetVersion.Parse("1.0.7"));

                TestFileSystemUtility.DeleteRandomTestFolder(pathToDelete);

                var restoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                    solutionManager,
                    await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(solutionManager, restoreContext),
                    restoreContext,
                    new RestoreCommandProvidersCache(),
                    (c) => { },
                    sources,
                    Guid.Empty,
                    false,
                    true,
                    testLogger,
                    CancellationToken.None);

                foreach (var restoreSummary in restoreSummaries)
                {
                    Assert.True(restoreSummary.Success);
                    Assert.False(restoreSummary.NoOpRestore);
                }
            }
        }
Exemplo n.º 13
0
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredChangedSha512()
        {
            // Arrange
            var projectName = "testproj";

            using (var packagesFolder = TestDirectory.Create())
                using (var rootFolder = TestDirectory.Create())
                {
                    var projectFolder = new DirectoryInfo(Path.Combine(rootFolder, projectName));
                    projectFolder.Create();
                    var projectConfig      = new FileInfo(Path.Combine(projectFolder.FullName, "project.json"));
                    var msbuildProjectPath = new FileInfo(Path.Combine(projectFolder.FullName, $"{projectName}.csproj"));

                    BuildIntegrationTestUtility.CreateConfigJson(projectConfig.FullName);

                    var json = JObject.Parse(File.ReadAllText(projectConfig.FullName));

                    JsonConfigUtility.AddDependency(json, new PackageDependency("nuget.versioning", VersionRange.Parse("1.0.7")));

                    using (var writer = new StreamWriter(projectConfig.FullName))
                    {
                        writer.Write(json.ToString());
                    }

                    var sources = new List <SourceRepository>
                    {
                        Repository.Factory.GetVisualStudio("https://www.nuget.org/api/v2/")
                    };

                    var testLogger = new TestLogger();

                    var projectTargetFramework    = NuGetFramework.Parse("uap10.0");
                    var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext());
                    var project = new ProjectJsonBuildIntegratedNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName, msBuildNuGetProjectSystem);

                    var solutionManager = new TestSolutionManager(false);
                    solutionManager.NuGetProjects.Add(project);

                    var restoreContext = new DependencyGraphCacheContext(testLogger);

                    await DependencyGraphRestoreUtility.RestoreAsync(
                        solutionManager,
                        restoreContext,
                        new RestoreCommandProvidersCache(),
                        (c) => { },
                        sources,
                        packagesFolder,
                        NullSettings.Instance,
                        testLogger,
                        CancellationToken.None);

                    var resolver = new VersionFolderPathResolver(packagesFolder);
                    var hashPath = resolver.GetHashPath("nuget.versioning", NuGetVersion.Parse("1.0.7"));

                    using (var writer = new StreamWriter(hashPath))
                    {
                        writer.Write("ANAWESOMELYWRONGHASH!!!");
                    }

                    // Act
                    var actual = await project.IsRestoreRequired(
                        new[] { resolver },
                        new HashSet <PackageIdentity>(),
                        restoreContext);

                    // Assert
                    Assert.True(actual);
                }
        }