public async Task GivenAPackageWithAHigherMinClientVersionVerifyErrorCodeDisplayedAsync() { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard1.5")); var packageB = new SimpleTestPackageContext("b", "1.0.0") { MinClientVersion = "99.0.0" }; await SimpleTestPackageUtility.CreatePackagesAsync(pathContext.PackageSource, packageB); projectA.AddPackageToAllFrameworks(packageB); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var r = Util.Restore(pathContext, projectA.ProjectPath, expectedExitCode: 1); var output = r.Item2 + " " + r.Item3; // Assert Assert.Contains("NU1401", output, StringComparison.OrdinalIgnoreCase); } }
public async Task Restore_TamperedPackage_FailsAsync() { // Arrange var nupkg = new SimpleTestPackageContext("A", "1.0.0"); using (var pathContext = new SimpleTestPathContext()) using (var testCertificate = new X509Certificate2(_trustedTestCert.Source.Cert)) { // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard2.0")); var packageX = new SimpleTestPackageContext("X", "9.0.0"); var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync(testCertificate, packageX, pathContext.PackageSource); SignedArchiveTestUtility.TamperWithPackage(signedPackagePath); projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); var args = new string[] { projectA.ProjectPath, "-Source", pathContext.PackageSource }; // Act var result = RunRestore(_nugetExePath, pathContext, expectedExitCode: 1, additionalArgs: args); var reader = new LockFileFormat(); var lockFile = reader.Read(projectA.AssetsFileOutputPath); var errors = lockFile.LogMessages.Where(m => m.Level == LogLevel.Error); var warnings = lockFile.LogMessages.Where(m => m.Level == LogLevel.Warning); // Assert result.ExitCode.Should().Be(1); result.Errors.Should().Contain(_NU3008); result.AllOutput.Should().Contain($"WARNING: {_NU3027}"); errors.Count().Should().Be(1); errors.First().Code.Should().Be(NuGetLogCode.NU3008); errors.First().Message.Should().Be(_NU3008Message); errors.First().LibraryId.Should().Be(packageX.ToString()); warnings.Count().Should().Be(1); warnings.First().Code.Should().Be(NuGetLogCode.NU3027); warnings.First().Message.Should().Be(_NU3027Message); warnings.First().LibraryId.Should().Be("X.9.0.0"); } }
public async Task MsbuildRestore_WithCPPCliVcxproj_WithAssetTargetFallback_Succeeds() { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set-up packages var packageNative = new SimpleTestPackageContext("native", "1.0.0"); packageNative.AddFile("build/native/native.targets"); packageNative.AddFile("lib/native/native.dll"); var packageManaged = new SimpleTestPackageContext("managed", "1.0.0"); packageManaged.AddFile("build/net472/managed.targets"); packageManaged.AddFile("lib/net472/managed.dll"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( pathContext.PackageSource, packageNative, packageManaged); // Set up project var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var framework = NuGetFramework.Parse("net5.0-windows7.0"); var projectA = SimpleTestProjectContext.CreateNETCore("projectName", pathContext.SolutionRoot, framework); projectA.Properties.Add("CLRSupport", "NetCore"); projectA.Properties.Add("AssetTargetFallback", "net472"); //update path to vcxproj projectA.ProjectPath = Path.Combine(Path.GetDirectoryName(projectA.ProjectPath), projectA.ProjectName + ".vcxproj"); projectA.AddPackageToAllFrameworks(packageNative); projectA.AddPackageToAllFrameworks(packageManaged); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var result = _msbuildFixture.RunMsBuild(pathContext.WorkingDirectory, $"/t:restore {pathContext.SolutionRoot}"); // Assert result.Success.Should().BeTrue(because: result.AllOutput); File.Exists(projectA.AssetsFileOutputPath).Should().BeTrue(because: result.AllOutput); File.Exists(projectA.TargetsOutput).Should().BeTrue(because: result.AllOutput); File.Exists(projectA.PropsOutput).Should().BeTrue(because: result.AllOutput); var targetsSection = projectA.AssetsFile.Targets.First(e => string.IsNullOrEmpty(e.RuntimeIdentifier)); targetsSection.Libraries.Should().Contain(e => e.Name.Equals("native"), because: string.Join(",", targetsSection.Libraries)); targetsSection.Libraries.Should().Contain(e => e.Name.Equals("managed"), because: string.Join(",", targetsSection.Libraries)); var native = targetsSection.Libraries.First(e => e.Name.Equals("native")); native.CompileTimeAssemblies.Should().Contain("lib/native/native.dll"); native.Build.Should().Contain("build/native/native.targets"); var managed = targetsSection.Libraries.First(e => e.Name.Equals("managed")); managed.CompileTimeAssemblies.Should().Contain("lib/net472/managed.dll"); managed.Build.Should().Contain("build/net472/managed.targets"); } }
public async Task TestUtility_Solution() { using (var pathContext = new SimpleTestPathContext()) { // Arrange && Act var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("net45")); var packageX = new SimpleTestPackageContext() { Id = "x", Version = "1.0.0" }; var projectJson = JObject.Parse(@"{ 'dependencies': { }, 'frameworks': { 'net45': { } } }"); var projectB = SimpleTestProjectContext.CreateUAP( "b", pathContext.SolutionRoot, NuGetFramework.Parse("net45"), projectJson); projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Projects.Add(projectB); solution.Create(pathContext.SolutionRoot); await SimpleTestPackageUtility.CreateFolderFeedV3( pathContext.PackageSource, PackageSaveMode.Defaultv3, packageX); // Assert Assert.True(File.Exists(Path.Combine(pathContext.SolutionRoot, "solution.sln"))); Assert.True(File.Exists(Path.Combine(pathContext.SolutionRoot, "a", "a.csproj"))); Assert.True(File.Exists(Path.Combine(pathContext.WorkingDirectory, "NuGet.Config"))); Assert.True(File.Exists(Path.Combine(pathContext.SolutionRoot, "b", "b.csproj"))); Assert.True(File.Exists(Path.Combine(pathContext.SolutionRoot, "b", "project.json"))); } }
public async Task DotnetRestore_PackageReferenceWithAliases_ReflectedInTheAssetsFile() { using (var pathContext = _msbuildFixture.CreateSimpleTestPathContext()) { // Set up solution, and project var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projFramework = FrameworkConstants.CommonFrameworks.Net462; var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, projFramework); //Setup packages and feed var packageX = new SimpleTestPackageContext() { Id = "x", Version = "1.0.0" }; packageX.Files.Clear(); packageX.AddFile($"lib/{projFramework.GetShortFolderName()}/x.dll"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( pathContext.PackageSource, PackageSaveMode.Defaultv3, packageX); packageX.Aliases = "Core"; //add the packe to the project projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var args = $" --source \"{pathContext.PackageSource}\" "; var projdir = Path.GetDirectoryName(projectA.ProjectPath); var projfilename = Path.GetFileNameWithoutExtension(projectA.ProjectName); _msbuildFixture.RestoreProject(projdir, projfilename, args); Assert.True(File.Exists(projectA.AssetsFileOutputPath)); var library = projectA.AssetsFile.Targets.First(e => e.RuntimeIdentifier == null).Libraries.First(); library.Should().NotBeNull("The assets file is expect to have a single library"); library.CompileTimeAssemblies.Count.Should().Be(1, because: "The package has 1 compatible file"); library.CompileTimeAssemblies.Single().Properties.Should().Contain(new KeyValuePair <string, string>(LockFileItem.AliasesProperty, "Core")); } }
public async Task GivenAProjectIsUsedOverAPackageVerifyNoDowngradeWarningAsync() { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard1.5")); var projectB = SimpleTestProjectContext.CreateNETCore( "b", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard1.5")); // A -> B projectA.AddProjectToAllFrameworks(projectB); var packageX = new SimpleTestPackageContext("x", "9.0.0"); var packageB = new SimpleTestPackageContext("b", "9.0.0"); packageX.Dependencies.Add(packageB); await SimpleTestPackageUtility.CreatePackagesAsync(pathContext.PackageSource, packageX, packageB); // PackageB will be overridden by ProjectB projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Projects.Add(projectB); solution.Create(pathContext.SolutionRoot); // Act var r = Util.Restore(pathContext, projectA.ProjectPath); var output = r.Item2 + " " + r.Item3; var reader = new LockFileFormat(); var lockFileObj = reader.Read(projectA.AssetsFileOutputPath); // Assert Assert.NotNull(lockFileObj); Assert.Equal(0, lockFileObj.LogMessages.Count()); Assert.DoesNotContain("downgrade", output, StringComparison.OrdinalIgnoreCase); } }
public async Task GivenAPackageDowngradeVerifyDowngradeWarningAsync() { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard1.5")); var packageB = new SimpleTestPackageContext("b", "9.0.0"); var packageI1 = new SimpleTestPackageContext("i", "9.0.0"); var packageI2 = new SimpleTestPackageContext("i", "1.0.0"); packageB.Dependencies.Add(packageI1); await SimpleTestPackageUtility.CreatePackagesAsync(pathContext.PackageSource, packageB, packageI1, packageI2); projectA.AddPackageToAllFrameworks(packageB); projectA.AddPackageToAllFrameworks(packageI2); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var r = Util.Restore(pathContext, projectA.ProjectPath); var output = r.Item2 + " " + r.Item3; var reader = new LockFileFormat(); var lockFileObj = reader.Read(projectA.AssetsFileOutputPath); // Assert Assert.NotNull(lockFileObj); Assert.Equal(1, lockFileObj.LogMessages.Count()); Assert.Contains("Detected package downgrade: i from 9.0.0 to 1.0.0", lockFileObj.LogMessages.First().Message, StringComparison.OrdinalIgnoreCase); Assert.Contains("Detected package downgrade: i from 9.0.0 to 1.0.0", output, StringComparison.OrdinalIgnoreCase); } }
public async Task MsbuildRestore_WithCPPCliVcxproj_RestoresSuccessfullyWithPackageReference(bool isStaticGraphRestore) { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set-up packages var packageX = new SimpleTestPackageContext("x", "1.0.0"); packageX.AddFile("lib/net5.0/a.dll"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( pathContext.PackageSource, packageX); // Set up project var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var framework = NuGetFramework.Parse("net5.0-windows7.0"); var projectA = SimpleTestProjectContext.CreateNETCore("projectName", pathContext.SolutionRoot, framework); projectA.Properties.Add("CLRSupport", "NetCore"); //update path to vcxproj projectA.ProjectPath = Path.Combine(Path.GetDirectoryName(projectA.ProjectPath), projectA.ProjectName + ".vcxproj"); projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var result = _msbuildFixture.RunMsBuild(pathContext.WorkingDirectory, $"/t:restore {pathContext.SolutionRoot}" + (isStaticGraphRestore ? " /p:RestoreUseStaticGraphEvaluation=true" : string.Empty)); // Assert result.Success.Should().BeTrue(because: result.AllOutput); File.Exists(projectA.AssetsFileOutputPath).Should().BeTrue(because: result.AllOutput); File.Exists(projectA.TargetsOutput).Should().BeTrue(because: result.AllOutput); File.Exists(projectA.PropsOutput).Should().BeTrue(because: result.AllOutput); var targetsSection = projectA.AssetsFile.Targets.First(e => string.IsNullOrEmpty(e.RuntimeIdentifier)); targetsSection.Libraries.Should().Contain(e => e.Name.Equals("x"), because: string.Join(",", targetsSection.Libraries)); var lockFileTargetLibrary = targetsSection.Libraries.First(e => e.Name.Equals("x")); lockFileTargetLibrary.CompileTimeAssemblies.Should().Contain("lib/net5.0/a.dll"); } }
public void GivenAnUnknownPackageVerifyError() { // Arrange using (var pathContext = new SimpleTestPathContext()) { // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard1.5")); var packageB = new SimpleTestPackageContext("b", "9.0.0"); projectA.AddPackageToAllFrameworks(packageB); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); // Act var r = Util.Restore(pathContext, projectA.ProjectPath, expectedExitCode: 1); var output = r.Item2 + " " + r.Item3; var reader = new LockFileFormat(); var lockFileObj = reader.Read(projectA.AssetsFileOutputPath); // Assert Assert.NotNull(lockFileObj); Assert.Equal(1, lockFileObj.LogMessages.Count()); Assert.Contains("Unable to find package b. No packages exist with this id in source(s): source", lockFileObj.LogMessages.First().Message, StringComparison.OrdinalIgnoreCase); Assert.Contains("Unable to find package b. No packages exist with this id in source(s): source", output, StringComparison.OrdinalIgnoreCase); } }
public void MockServer_RestorePRVerifySessionId() { // Arrange using (var pathContext = new SimpleTestPathContext()) { var nugetexe = Util.GetNuGetExePath(); var packageA = new FileInfo(Util.CreateTestPackage("a", "1.0.0", pathContext.PackageSource)); var packageB = new FileInfo(Util.CreateTestPackage("b", "1.0.0", pathContext.PackageSource)); var project = SimpleTestProjectContext.CreateNETCore("proj", pathContext.SolutionRoot, NuGetFramework.Parse("net46")); project.AddPackageToAllFrameworks(new SimpleTestPackageContext("a", "1.0.0")); project.AddPackageToAllFrameworks(new SimpleTestPackageContext("b", "1.0.0")); project.Save(); var ids = new List <string>(); using (var server = Util.CreateMockServer(new[] { packageA, packageB })) { server.RequestObserver = context => { ids.Add(context.Request.Headers.Get(ProtocolConstants.SessionId)); }; server.Start(); var result = Util.Restore(pathContext, project.ProjectPath, 0, "-Source", server.Uri + "nuget"); result.Success.Should().BeTrue(); ids.Distinct().Count().Should().Be(1, "all requests should be in the same session"); ids.All(s => !string.IsNullOrEmpty(s) && Guid.TryParse(s, out var r)).Should().BeTrue("the values should guids"); } } }
public async Task DotnetRestore_LockedMode_NewProjectOutOfBox() { using (var pathContext = new SimpleTestPathContext()) { // Set up solution, and project var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var projFramework = FrameworkConstants.CommonFrameworks.Net462.GetShortFolderName(); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse(projFramework)); var runtimeidentifiers = new List <string>() { "win7-x64", "win-x86", "win" }; projectA.Properties.Add("RuntimeIdentifiers", string.Join(";", runtimeidentifiers)); projectA.Properties.Add("RestorePackagesWithLockFile", "true"); //Setup packages and feed var packageX = new SimpleTestPackageContext() { Id = "x", Version = "1.0.0" }; packageX.Files.Clear(); packageX.AddFile("lib/netcoreapp2.0/x.dll"); packageX.AddFile("ref/netcoreapp2.0/x.dll"); packageX.AddFile("lib/net461/x.dll"); packageX.AddFile("ref/net461/x.dll"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( pathContext.PackageSource, PackageSaveMode.Defaultv3, packageX); //add the packe to the project projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); solution.Save(); projectA.Save(); // Act var args = $" --source \"{pathContext.PackageSource}\" "; var projdir = Path.GetDirectoryName(projectA.ProjectPath); var projfilename = Path.GetFileNameWithoutExtension(projectA.ProjectName); _msbuildFixture.RestoreProject(projdir, projfilename, args); Assert.True(File.Exists(projectA.NuGetLockFileOutputPath)); //Now set it to locked mode projectA.Properties.Add("RestoreLockedMode", "true"); projectA.Save(); //Act //Run the restore and it should still properly restore. //Assert within RestoreProject piece _msbuildFixture.RestoreProject(projdir, projfilename, args); Assert.True(File.Exists(projectA.NuGetLockFileOutputPath)); } }
public async Task DotnetRestore_VerifyPerProjectConfigSourcesAreUsedForChildProjectsWithSolutionAsync() { // Arrange using (var pathContext = new SimpleTestPathContext()) { var projects = new Dictionary <string, SimpleTestProjectContext>(); var sources = new List <string>(); var projFramework = FrameworkConstants.CommonFrameworks.Net462; foreach (var letter in new[] { "A", "B", "C" }) { // Project var project = SimpleTestProjectContext.CreateNETCore( $"project{letter}", pathContext.SolutionRoot, projFramework); projects.Add(letter, project); // Package var package = new SimpleTestPackageContext() { Id = $"package{letter}", Version = "1.0.0" }; // Do not flow the reference up package.PrivateAssets = "all"; project.AddPackageToAllFrameworks(package); project.Properties.Clear(); // Source var source = Path.Combine(pathContext.WorkingDirectory, $"source{letter}"); await SimpleTestPackageUtility.CreatePackagesAsync(source, package); sources.Add(source); // Create a nuget.config for the project specific source. var projectDir = Path.GetDirectoryName(project.ProjectPath); Directory.CreateDirectory(projectDir); var configPath = Path.Combine(projectDir, "NuGet.Config"); var doc = new XDocument(); var configuration = new XElement(XName.Get("configuration")); doc.Add(configuration); var config = new XElement(XName.Get("config")); configuration.Add(config); var packageSources = new XElement(XName.Get("packageSources")); configuration.Add(packageSources); var sourceEntry = new XElement(XName.Get("add")); sourceEntry.Add(new XAttribute(XName.Get("key"), "projectSource")); sourceEntry.Add(new XAttribute(XName.Get("value"), source)); packageSources.Add(sourceEntry); File.WriteAllText(configPath, doc.ToString()); } // Create root project var projectRoot = SimpleTestProjectContext.CreateNETCore( "projectRoot", pathContext.SolutionRoot, projFramework); // Link the root project to all other projects // Save them. foreach (var child in projects.Values) { projectRoot.AddProjectToAllFrameworks(child); child.Save(); } projectRoot.Save(); var solutionPath = Path.Combine(pathContext.SolutionRoot, "solution.sln"); _msbuildFixture.RunDotnet(pathContext.SolutionRoot, $"new sln {solutionPath}"); foreach (var child in projects.Values) { _msbuildFixture.RunDotnet(pathContext.SolutionRoot, $"sln {solutionPath} add {child.ProjectPath}"); } _msbuildFixture.RunDotnet(pathContext.SolutionRoot, $"sln {solutionPath} add {projectRoot.ProjectPath}"); // Act var result = _msbuildFixture.RunDotnet(pathContext.SolutionRoot, $"restore {solutionPath}"); result.Success.Should().BeTrue(because: result.AllOutput); // Assert projects.Count.Should().BeGreaterThan(0); foreach (var letter in projects.Keys) { projects[letter].AssetsFile.Should().NotBeNull(because: result.AllOutput); projects[letter].AssetsFile.Libraries.Select(e => e.Name).Should().Contain($"package{letter}", because: result.AllOutput); } } }
public async Task Restore_PackageWithCompressedSignature_RequireMode_FailsAndDoesNotExpandAsync() { // Arrange var packageX = new SimpleTestPackageContext(); using (var pathContext = new SimpleTestPathContext()) using (var packageStream = await packageX.CreateAsStreamAsync()) using (var testCertificate = new X509Certificate2(_trustedTestCert.Source.Cert)) { var signature = await SignedArchiveTestUtility.CreateAuthorSignatureForPackageAsync(testCertificate, packageStream); using (var package = new ZipArchive(packageStream, ZipArchiveMode.Update, leaveOpen: true)) { var signatureEntry = package.CreateEntry(SigningSpecifications.V1.SignaturePath); using (var signatureStream = new MemoryStream(signature.GetBytes())) using (var signatureEntryStream = signatureEntry.Open()) { signatureStream.CopyTo(signatureEntryStream); } } var packagePath = Path.Combine(pathContext.PackageSource, $"{packageX.ToString()}.nupkg"); packageStream.Seek(offset: 0, loc: SeekOrigin.Begin); using (var fileStream = File.OpenWrite(packagePath)) { packageStream.CopyTo(fileStream); } // Set up solution, project, and packages var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var propsFile = Path.Combine(pathContext.SolutionRoot, "NuGet.Config"); using (var stream = File.OpenWrite(propsFile)) using (var textWritter = new StreamWriter(stream)) { textWritter.Write(@"<configuration><config><add key=""signatureValidationMode"" value=""require"" /></config></configuration>"); } var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("NETStandard2.0")); projectA.AddPackageToAllFrameworks(packageX); solution.Projects.Add(projectA); solution.Create(pathContext.SolutionRoot); var args = new string[] { projectA.ProjectPath }; // Act var result = RunRestore(_nugetExePath, pathContext, expectedExitCode: 1, additionalArgs: args); var assetFileReader = new LockFileFormat(); var assetsFile = assetFileReader.Read(projectA.AssetsFileOutputPath); var errors = assetsFile.LogMessages.Where(m => m.Level == LogLevel.Error); var warnings = assetsFile.LogMessages.Where(m => m.Level == LogLevel.Warning); // Assert result.ExitCode.Should().Be(1); result.Errors.Should().Contain(string.Format(_NU3005, SigningTestUtility.AddSignatureLogPrefix(_NU3005CompressedMessage, packageX.Identity, pathContext.PackageSource))); errors.Count().Should().Be(1); errors.First().Code.Should().Be(NuGetLogCode.NU3005); errors.First().Message.Should().Be(SigningTestUtility.AddSignatureLogPrefix(_NU3005CompressedMessage, packageX.Identity, pathContext.PackageSource)); errors.First().LibraryId.Should().Be(packageX.Identity.Id.ToString()); warnings.Count().Should().Be(0); var installedPackageDir = Path.Combine(pathContext.UserPackagesFolder, packageX.Identity.Id); Directory.Exists(installedPackageDir).Should().BeFalse(); } }
public void FeedPackagePruning_GivenThatAV3FeedPrunesAPackageDuringRestoreVerifyRestoreRecovers() { // Arrange using (var server = new MockServer()) using (var pathContext = new SimpleTestPathContext()) { // Set up solution, project, and packages var testLogger = new TestLogger(); var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); var serverRepoPath = Path.Combine(pathContext.WorkingDirectory, "serverPackages"); var packageX100 = new SimpleTestPackageContext("x", "1.0.0"); var packageX200 = new SimpleTestPackageContext("x", "2.0.0"); SimpleTestPackageUtility.CreatePackages( serverRepoPath, packageX100, packageX200); var projectA = SimpleTestProjectContext.CreateNETCore( "a", pathContext.SolutionRoot, NuGetFramework.Parse("net45")); projectA.AddPackageToAllFrameworks(packageX200); solution.Projects.Add(projectA); var projectB = SimpleTestProjectContext.CreateNETCore( "b", pathContext.SolutionRoot, NuGetFramework.Parse("net45")); projectB.AddPackageToAllFrameworks(packageX100); solution.Projects.Add(projectB); solution.Create(pathContext.SolutionRoot); // Server setup var indexJson = Util.CreateIndexJson(); Util.AddFlatContainerResource(indexJson, server); Util.AddRegistrationResource(indexJson, server); server.Get.Add("/", request => { return(ServerHandlerV3(request, server, indexJson, serverRepoPath)); }); server.Start(); var feedUrl = server.Uri + "index.json"; // Restore x 2.0.0 and populate the http cache var r = Util.Restore(pathContext, projectA.ProjectPath, 0, "-Source", feedUrl); // Delete x 1.0.0 File.Delete(LocalFolderUtility.GetPackageV2(serverRepoPath, packageX100.Identity, testLogger).Path); // Act // Restore x 1.0.0 r = Util.Restore(pathContext, projectB.ProjectPath, 0, "-Source", feedUrl); var xLib = projectB.AssetsFile.Libraries.SingleOrDefault(e => e.Name == "x"); // Assert Assert.Equal("2.0.0", xLib.Version.ToNormalizedString()); } }