public void ValidatePackageReferenceNugetPropertyGeneratorTest() { string projectAssetsJsonFile = Path.Combine(TestRootPath, "project.assets.json"); string projectPackageReferenceFile = Path.Combine(TestRootPath, "foo.proj"); PackageRestoreData packageRestoreData = LoadPackageRestoreObject(projectPackageReferenceFile, GetTempFileName(), _packageReferenceRestoreFlagContents.Replace("#RestoreOutputPath#", TestRootPath.Replace(@"\", @"\\"))); string outputFile = Path.Combine(TestRootPath, "output.props"); string expectedOutputContent = $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> <NuGetPath_Newtonsoft_Json>{TestRootPath}\packages\newtonsoft.json\6.0.3</NuGetPath_Newtonsoft_Json> <NuGetVersion_Newtonsoft_Json>6.0.3</NuGetVersion_Newtonsoft_Json> </PropertyGroup> <ItemGroup> <CBTNuGetPackageDir Include=""{TestRootPath}\packages\newtonsoft.json\6.0.3"" /> </ItemGroup> </Project>"; CreateProjectAssetsJsonFile(projectAssetsJsonFile, (new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") })); string packagePath = CreatePackagesFolder(new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") }, @"\"); MockSettings settings = new MockSettings { { "config", new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "globalPackagesFolder", packagePath }, } } }; new NuGetPropertyGenerator(_log, settings, projectPackageReferenceFile).Generate(outputFile, "NuGetVersion_", "NuGetPath_", packageRestoreData); _log.HasLoggedErrors.ShouldBeFalse(); File.Exists(outputFile).ShouldBe(true); File.ReadAllText(outputFile).NormalizeNewLine().ShouldBe(expectedOutputContent.NormalizeNewLine()); }
public void VerifyPackageReferenceParserTest() { string projectPackageReferenceFile = Path.Combine(TestRootPath, "foo.proj"); string projectAssetsJsonFile = Path.Combine(TestRootPath, "project.assets.json"); PackageRestoreData packageRestoreData = LoadPackageRestoreObject(projectPackageReferenceFile, GetTempFileName(), _packageReferenceRestoreFlagContents.Replace("#RestoreOutputPath#", TestRootPath.Replace(@"\", @"\\"))); CreateProjectAssetsJsonFile(projectAssetsJsonFile, (new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") })); string packagePath = CreatePackagesFolder(new List <Tuple <string, string> > { new Tuple <string, string>("Newtonsoft.Json", "6.0.3") }, @"\"); MockSettings settings = new MockSettings { { "config", new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "globalPackagesFolder", packagePath }, } } }; bool result = new NuGetPackageReferenceProjectParser(settings, _log).TryGetPackages(packagePath, packageRestoreData, out IEnumerable <PackageIdentityWithPath> packages); result.ShouldBeTrue(); IList <PackageIdentityWithPath> packageIdentityWithPaths = packages as IList <PackageIdentityWithPath> ?? packages.ToList(); packageIdentityWithPaths.Count.ShouldBe(1); packageIdentityWithPaths.First().Id.ShouldBe("Newtonsoft.Json"); packageIdentityWithPaths.First().Version.ToString().ShouldBe("6.0.3"); }