예제 #1
0
        public async Task BuildIntegratedNuGetProject_IsRestoreRequiredMissingPackage()
        {
            // 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 ProjectJsonBuildIntegratedNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName, msBuildNuGetProjectSystem);

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

                    var testLogger = new TestLogger();

                    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 pathToDelete = resolver.GetInstallPath("nuget.versioning", NuGetVersion.Parse("1.0.7"));

                    TestFileSystemUtility.DeleteRandomTestFolder(pathToDelete);

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

                    // Assert
                    Assert.True(actual);
                }
        }
예제 #2
0
        public async Task BuildIntegratedNuGetProject_IsRestoreNotRequiredWithFloatingVersion()
        {
            // Arrange
            var projectName = "testproj";

            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));

                json.Add("dependencies", JObject.Parse("{ \"nuget.versioning\": \"1.0.*\" }"));

                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 ProjectJsonBuildIntegratedNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName, msBuildNuGetProjectSystem);

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

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

                var testLogger = new TestLogger();

                var restoreContext = new DependencyGraphCacheContext(testLogger);

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

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

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