public void TestGetPathPackagesConfig_CacheFallback() { using (var tempDir = TempDir.Create()) { File.WriteAllText(Path.Combine(tempDir, "packages.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Microsoft.CodeDom.Providers.DotNetCompilerPlatform"" version=""1.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Net.Compilers"" version=""1.0.0"" targetFramework=""net46"" developmentDependency=""true"" /> <package id=""Microsoft.Web.Infrastructure"" version=""1.0.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Web.Xdt"" version=""2.1.1"" targetFramework=""net46"" /> <package id=""Newtonsoft.Json"" version=""8.0.3"" allowedVersions=""[8,10)"" targetFramework=""net46"" /> <package id=""NuGet.Core"" version=""2.11.1"" targetFramework=""net46"" /> <package id=""NuGet.Server"" version=""2.11.2"" targetFramework=""net46"" /> <package id=""RouteMagic"" version=""1.3"" targetFramework=""net46"" /> <package id=""MSTest.TestAdapter"" version=""{PreprocessorTests.mstestVersion}"" targetFramework=""net46"" /> </packages>"); var result = NuGetLogic.GetPackagePath(tempDir, "packages", "MSTest.TestAdapter"); Assert.AreEqual(Path.Combine(NuGetLogic.GetNuGetCacheDir(), "MSTest.TestAdapter", PreprocessorTests.mstestVersion).ToLowerInvariant(), result.ToLowerInvariant()); } }
public void TestGetPathPackagesConfig_UnknownPackage() { using (var tempDir = TempDir.Create()) { File.WriteAllText(Path.Combine(tempDir, "packages.config"), @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Microsoft.CodeDom.Providers.DotNetCompilerPlatform"" version=""1.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Net.Compilers"" version=""1.0.0"" targetFramework=""net46"" developmentDependency=""true"" /> <package id=""Microsoft.Web.Infrastructure"" version=""1.0.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Web.Xdt"" version=""2.1.1"" targetFramework=""net46"" /> <package id=""Newtonsoft.Json"" version=""8.0.3"" allowedVersions=""[8,10)"" targetFramework=""net46"" /> <package id=""NuGet.Core"" version=""2.11.1"" targetFramework=""net46"" /> <package id=""NuGet.Server"" version=""2.11.2"" targetFramework=""net46"" /> <package id=""RouteMagic"" version=""1.3"" targetFramework=""net46"" /> <package id=""SomeRandomNotInstalledPackage"" version=""2.1.0"" targetFramework=""net46"" /> </packages>"); var e = Assert.ThrowsException <InvalidOperationException>(() => NuGetLogic.GetPackagePath(tempDir, "packages", "SomeRandomNotInstalledPackage")); Assert.IsTrue(e.Message.Contains("are all packages restored?"), "e.Message.Contains('are all packages restored?')"); } }
public void TestGetPathPackagesConfig() { using (var tempDir = TempDir.Create()) { File.WriteAllText(Path.Combine(tempDir, "packages.config"), @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Microsoft.CodeDom.Providers.DotNetCompilerPlatform"" version=""1.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Net.Compilers"" version=""1.0.0"" targetFramework=""net46"" developmentDependency=""true"" /> <package id=""Microsoft.Web.Infrastructure"" version=""1.0.0.0"" targetFramework=""net46"" /> <package id=""Microsoft.Web.Xdt"" version=""2.1.1"" targetFramework=""net46"" /> <package id=""Newtonsoft.Json"" version=""8.0.3"" allowedVersions=""[8,10)"" targetFramework=""net46"" /> <package id=""NuGet.Core"" version=""2.11.1"" targetFramework=""net46"" /> <package id=""NuGet.Server"" version=""2.11.2"" targetFramework=""net46"" /> <package id=""RouteMagic"" version=""1.3"" targetFramework=""net46"" /> <package id=""WebActivatorEx"" version=""2.1.0"" targetFramework=""net46"" /> </packages>"); var d = Directory.CreateDirectory(Path.Combine(tempDir, "packages", "Nuget.Core.2.11.1")); var path = NuGetLogic.GetPackagePath(tempDir, "packages", "nuGet.cOre"); Assert.AreEqual(d.FullName.ToLowerInvariant(), path.ToLowerInvariant()); } }