public void DeleteDirectory(string path, bool recursive) { var fullPath = Path.Combine(ProjectFullPath, path); // this will delete recursive regadless of input, doesn't matter for testing TestFileSystemUtility.DeleteRandomTestFolder(fullPath); }
public void Dispose() { WorkingPath.Dispose(); TestFileSystemUtility.DeleteRandomTestFolder(SourceParamFolder); _sourceDirectory?.Dispose(); _randomNupkgDirectory?.Dispose(); }
public async Task TestPackageRestoredEvent() { // Arrange using (var testSolutionManager = new TestSolutionManager(true)) { var projectA = testSolutionManager.AddNewMSBuildProject(); var projectB = testSolutionManager.AddNewMSBuildProject(); var packageIdentity = Packages[0]; var testNuGetProjectContext = new TestNuGetProjectContext(); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSettings = Configuration.NullSettings.Instance; var resolutionContext = new ResolutionContext(); var token = CancellationToken.None; var deleteOnRestartManager = new TestDeleteOnRestartManager(); var nuGetPackageManager = new NuGetPackageManager( sourceRepositoryProvider, testSettings, testSolutionManager, deleteOnRestartManager); await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); await nuGetPackageManager.InstallPackageAsync(projectB, packageIdentity, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); var packageRestoreManager = new PackageRestoreManager( sourceRepositoryProvider, testSettings, testSolutionManager); var restoredPackages = new List <PackageIdentity>(); packageRestoreManager.PackageRestoredEvent += delegate(object sender, PackageRestoredEventArgs args) { if (args.Restored) { restoredPackages.Add(args.Package); } }; Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(packageIdentity)); // Delete packages folder TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages")); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity))); // Act await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, testNuGetProjectContext, new TestLogger(), CancellationToken.None); Assert.Equal(1, restoredPackages.Count); Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity))); } }
public async Task TestCheckForMissingPackages() { // Arrange using (var testSolutionManager = new TestSolutionManager(true)) using (var randomPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder()) { var projectA = testSolutionManager.AddNewMSBuildProject(); var projectB = testSolutionManager.AddNewMSBuildProject(); var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0")); var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomPackageSourcePath, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var testNuGetProjectContext = new TestNuGetProjectContext(); var token = CancellationToken.None; using (var packageStream = GetDownloadResult(packageFileInfo)) { // Act await projectA.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token); await projectB.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token); } var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSettings = Configuration.NullSettings.Instance; var deleteOnRestartManager = new TestDeleteOnRestartManager(); var packageRestoreManager = new PackageRestoreManager( sourceRepositoryProvider, testSettings, testSolutionManager); var packagesMissingEventCount = 0; var packagesMissing = false; packageRestoreManager.PackagesMissingStatusChanged += delegate(object sender, PackagesMissingStatusEventArgs args) { packagesMissingEventCount++; packagesMissing = args.PackagesMissing; }; // Act await packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(testSolutionManager.SolutionDirectory, token); // Assert Assert.Equal(1, packagesMissingEventCount); Assert.False(packagesMissing); // Delete packages folder TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages")); // Act await packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(testSolutionManager.SolutionDirectory, token); // Assert Assert.Equal(2, packagesMissingEventCount); Assert.True(packagesMissing); } }
public async Task TestGetMissingPackagesForSolution() { // Arrange using (var testSolutionManager = new TestSolutionManager(true)) using (var randomPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder()) { var projectA = testSolutionManager.AddNewMSBuildProject(); var projectB = testSolutionManager.AddNewMSBuildProject(); var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0")); var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomPackageSourcePath, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var testNuGetProjectContext = new TestNuGetProjectContext(); var token = CancellationToken.None; using (var packageStream = GetDownloadResult(packageFileInfo)) { // Act await projectA.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token); await projectB.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token); } var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSettings = Configuration.NullSettings.Instance; var deleteOnRestartManager = new TestDeleteOnRestartManager(); var packageRestoreManager = new PackageRestoreManager( sourceRepositoryProvider, testSettings, testSolutionManager); // Act var packagesFromSolution = (await packageRestoreManager.GetPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, token)); var packagesFromSolutionList = packagesFromSolution.ToList(); var missingPackagesFromSolutionList = packagesFromSolution.Where(p => p.IsMissing).ToList(); Assert.Equal(1, packagesFromSolutionList.Count); Assert.Equal(0, missingPackagesFromSolutionList.Count); // Delete packages folder TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages")); packagesFromSolution = (await packageRestoreManager.GetPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, token)); packagesFromSolutionList = packagesFromSolution.ToList(); missingPackagesFromSolutionList = packagesFromSolution.Where(p => p.IsMissing).ToList(); Assert.Equal(1, missingPackagesFromSolutionList.Count); } }
public void Dispose() { TestFileSystemUtility.DeleteRandomTestFolder(ProjectDirectory); }
public async Task Test_PackageRestoreFailure_WithRaisedEvents() { // Arrange using (var testSolutionManager = new TestSolutionManager(true)) using (var randomTestPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder()) { var projectA = testSolutionManager.AddNewMSBuildProject("projectA"); var projectB = testSolutionManager.AddNewMSBuildProject("projectB"); var projectC = testSolutionManager.AddNewMSBuildProject("projectC"); var jQuery144 = Packages[0]; var jQueryValidation = Packages[2]; var testNuGetProjectContext = new TestNuGetProjectContext(); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSettings = Configuration.NullSettings.Instance; var resolutionContext = new ResolutionContext(); var token = CancellationToken.None; var deleteOnRestartManager = new TestDeleteOnRestartManager(); var nuGetPackageManager = new NuGetPackageManager( sourceRepositoryProvider, testSettings, testSolutionManager, deleteOnRestartManager); await nuGetPackageManager.InstallPackageAsync(projectA, jQueryValidation, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); await nuGetPackageManager.InstallPackageAsync(projectB, jQueryValidation, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); var testPackage1 = new PackageIdentity("package1A", new NuGetVersion("1.0.0")); var testPackage2 = new PackageIdentity("package1B", new NuGetVersion("1.0.0")); var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomTestPackageSourcePath, testPackage1.Id, testPackage1.Version.ToNormalizedString()); using (var packageStream = GetDownloadResult(packageFileInfo)) { // Act await projectB.InstallPackageAsync(testPackage1, packageStream, testNuGetProjectContext, token); await projectC.InstallPackageAsync(testPackage1, packageStream, testNuGetProjectContext, token); } packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomTestPackageSourcePath, testPackage2.Id, testPackage2.Version.ToNormalizedString()); using (var packageStream = GetDownloadResult(packageFileInfo)) { // Act await projectA.InstallPackageAsync(testPackage2, packageStream, testNuGetProjectContext, token); await projectC.InstallPackageAsync(testPackage2, packageStream, testNuGetProjectContext, token); } var packageRestoreManager = new PackageRestoreManager( sourceRepositoryProvider, testSettings, testSolutionManager); var restoredPackages = new List <PackageIdentity>(); packageRestoreManager.PackageRestoredEvent += delegate(object sender, PackageRestoredEventArgs args) { restoredPackages.Add(args.Package); }; var restoreFailedPackages = new ConcurrentDictionary <Packaging.PackageReference, IEnumerable <string> >(new PackageReferenceComparer()); packageRestoreManager.PackageRestoreFailedEvent += delegate(object sender, PackageRestoreFailedEventArgs args) { restoreFailedPackages.AddOrUpdate(args.RestoreFailedPackageReference, args.ProjectNames, (Packaging.PackageReference packageReference, IEnumerable <string> oldValue) => { return(oldValue); }); }; Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation)); // Delete packages folder TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages")); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(jQuery144)); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation)); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage1)); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage2)); // Act await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, testNuGetProjectContext, CancellationToken.None); // Assert Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQuery144)); Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation)); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage1)); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage2)); Assert.Equal(4, restoredPackages.Count); // The ordering is not guaranteed and can vary. Do not assert based on that Assert.True(restoredPackages.Contains(jQuery144)); Assert.True(restoredPackages.Contains(jQueryValidation)); Assert.True(restoredPackages.Contains(testPackage1)); Assert.True(restoredPackages.Contains(testPackage2)); Assert.Equal(2, restoreFailedPackages.Count); // The ordering is not guaranteed and can vary. Do not assert based on that var restoreFailedPackageKeys = restoreFailedPackages.Keys; var testPackage1Key = restoreFailedPackageKeys.Where(r => r.PackageIdentity.Equals(testPackage1)).First(); var testPackage1ProjectNames = restoreFailedPackages[testPackage1Key].ToList(); Assert.Equal(2, testPackage1ProjectNames.Count); Assert.True(testPackage1ProjectNames.Contains("projectB", StringComparer.OrdinalIgnoreCase)); Assert.True(testPackage1ProjectNames.Contains("projectC", StringComparer.OrdinalIgnoreCase)); var testPackage2Key = restoreFailedPackageKeys.Where(r => r.PackageIdentity.Equals(testPackage2)).First(); var testPackage2ProjectNames = restoreFailedPackages[testPackage2Key].ToList(); Assert.Equal(2, testPackage2ProjectNames.Count); Assert.True(testPackage2ProjectNames.Contains("projectA", StringComparer.OrdinalIgnoreCase)); Assert.True(testPackage2ProjectNames.Contains("projectC", StringComparer.OrdinalIgnoreCase)); } }
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> { }; var projectTargetFramework = NuGetFramework.Parse("uap10.0"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var project = new ProjectJsonNuGetProject(projectConfig.FullName, msbuildProjectPath.FullName); 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 restoreContext = new DependencyGraphCacheContext(testLogger, settings); var providersCache = new RestoreCommandProvidersCache(); 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); } var resolver = new VersionFolderPathResolver(packagesFolder); var pathToDelete = resolver.GetInstallPath("nuget.versioning", NuGetVersion.Parse("1.0.7")); TestFileSystemUtility.DeleteRandomTestFolder(pathToDelete); 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 void Dispose() { TestFileSystemUtility.DeleteRandomTestFolder(SourceParamFolder); TestFileSystemUtility.DeleteRandomTestFolder(RandomNupkgFolder); TestFileSystemUtility.DeleteRandomTestFolder(WorkingPath); }
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); } }
public void Dispose() { TestFileSystemUtility.DeleteRandomTestFolder(WorkingPath); TestFileSystemUtility.DeleteRandomTestFolder(SourceFeed); TestFileSystemUtility.DeleteRandomTestFolder(DestinationFeed); }