public void PackagesLockFileFormat_Write() { var nuGetLockFileContent = @"{ ""version"": 1, ""dependencies"": { "".NETFramework,Version=v4.5"": { ""PackageA"": { ""type"": ""Direct"", ""requested"": ""[1.*, )"", ""resolved"": ""1.0.0"", ""sha512"": ""sbWWhjA2/cXJHBBKAVo3m2U0KxzNuW5dQANDwx8L96V+L6SML96cM/Myvmp6fiBqIDibvF6+Ss9YC+qqclrXnw=="", ""dependencies"": { ""PackageB"": ""1.0.0"" } }, ""PackageB"": { ""type"": ""Transitive"", ""resolved"": ""1.0.0"", ""sha512"": ""Fjiywrwerewr4dgbdgbfgjkoiuiorwrwn24+8hjnnuerwrwsfsHYWD3HJYUI7NJHssxDFSFSFEWEW34DFDFCVsxv=="", } } } }"; var lockFile = PackagesLockFileFormat.Parse(nuGetLockFileContent, "In Memory"); var output = JObject.Parse(PackagesLockFileFormat.Render(lockFile)); var expected = JObject.Parse(nuGetLockFileContent); // Assert Assert.Equal(expected.ToString(), output.ToString()); }
public void PackagesLockFileFormat_Read() { var nuGetLockFileContent = @"{ ""version"": 1, ""dependencies"": { "".NETFramework,Version=v4.5"": { ""PackageA"": { ""type"": ""Direct"", ""requested"": ""[1.*, )"", ""resolved"": ""1.0.0"", ""sha512"": ""sbWWhjA2/cXJHBBKAVo3m2U0KxzNuW5dQANDwx8L96V+L6SML96cM/Myvmp6fiBqIDibvF6+Ss9YC+qqclrXnw=="", ""dependencies"": { ""PackageB"": ""1.0.0"" } }, ""PackageB"": { ""type"": ""Transitive"", ""resolved"": ""1.0.0"", ""sha512"": ""Fjiywrwerewr4dgbdgbfgjkoiuiorwrwn24+8hjnnuerwrwsfsHYWD3HJYUI7NJHssxDFSFSFEWEW34DFDFCVsxv=="", } } } }"; var lockFile = PackagesLockFileFormat.Parse(nuGetLockFileContent, "In Memory"); Assert.Equal(1, lockFile.Targets.Count); var target = lockFile.Targets.First(); Assert.Equal(".NETFramework,Version=v4.5", target.Name); Assert.Equal(2, target.Dependencies.Count); Assert.Equal("PackageA", target.Dependencies[0].Id); Assert.Equal(PackageDependencyType.Direct, target.Dependencies[0].Type); Assert.Equal("[1.*, )", target.Dependencies[0].RequestedVersion.ToNormalizedString()); Assert.Equal("1.0.0", target.Dependencies[0].ResolvedVersion.ToNormalizedString()); Assert.NotEmpty(target.Dependencies[0].Sha512); Assert.Equal(1, target.Dependencies[0].Dependencies.Count); Assert.Equal("PackageB", target.Dependencies[0].Dependencies[0].Id); Assert.Equal("PackageB", target.Dependencies[1].Id); Assert.Equal(PackageDependencyType.Transitive, target.Dependencies[1].Type); Assert.Null(target.Dependencies[1].RequestedVersion); Assert.Equal("1.0.0", target.Dependencies[0].ResolvedVersion.ToNormalizedString()); Assert.NotEmpty(target.Dependencies[1].Sha512); }
public void PackagesLockFileFormat_ReadWithRuntimeGraph() { var nuGetLockFileContent = @"{ ""version"": 1, ""dependencies"": { "".NETFramework,Version=v4.5"": { ""PackageA"": { ""type"": ""Direct"", ""requested"": ""[1.*, )"", ""resolved"": ""1.0.0"", ""sha512"": ""sbWWhjA2/cXJHBBKAVo3m2U0KxzNuW5dQANDwx8L96V+L6SML96cM/Myvmp6fiBqIDibvF6+Ss9YC+qqclrXnw=="", ""dependencies"": { ""PackageB"": ""1.0.0"" } }, ""PackageB"": { ""type"": ""Transitive"", ""resolved"": ""1.0.0"", ""sha512"": ""Fjiywrwerewr4dgbdgbfgjkoiuiorwrwn24+8hjnnuerwrwsfsHYWD3HJYUI7NJHssxDFSFSFEWEW34DFDFCVsxv=="" } }, "".NETFramework,Version=v4.5/win10-arm"": { ""PackageA"": { ""type"": ""Direct"", ""requested"": ""[1.*, )"", ""resolved"": ""1.0.0"", ""sha512"": ""QuiokjhjA2/cXJHBBKAVo3m2U0KxzNuW5dQANDwx8L96V+L6SML96cM/Myvmp6fiBqIDibvF6+Ss9YC+qqcfwef=="", ""dependencies"": { ""PackageB"": ""1.0.0"", ""runtime.win10-arm.PackageA"": ""1.0.0"" } }, ""runtime.win10-arm.PackageA"": { ""type"": ""Transitive"", ""resolved"": ""1.0.0"", ""sha512"": ""dfgdgdfIY434jhjkhkRARFSZSGFSDG423452bgdnuerwrwsfsHYWD3HJYUI7NJHssxDFSFSFEWEW34DFjkyuerd=="", } } } }"; var lockFile = PackagesLockFileFormat.Parse(nuGetLockFileContent, "In Memory"); Assert.Equal(2, lockFile.Targets.Count); var target = lockFile.Targets.First(t => !string.IsNullOrEmpty(t.RuntimeIdentifier)); Assert.Equal(".NETFramework,Version=v4.5/win10-arm", target.Name); Assert.Equal(2, target.Dependencies.Count); Assert.Equal("PackageA", target.Dependencies[0].Id); Assert.Equal(PackageDependencyType.Direct, target.Dependencies[0].Type); Assert.Equal("[1.*, )", target.Dependencies[0].RequestedVersion.ToNormalizedString()); Assert.Equal("1.0.0", target.Dependencies[0].ResolvedVersion.ToNormalizedString()); Assert.NotEmpty(target.Dependencies[0].Sha512); Assert.Equal(2, target.Dependencies[0].Dependencies.Count); Assert.Equal("PackageB", target.Dependencies[0].Dependencies[0].Id); Assert.Equal("runtime.win10-arm.PackageA", target.Dependencies[0].Dependencies[1].Id); // Runtime graph will only have additional transitive dependenies which are not part of // original TFM graph Assert.Equal("runtime.win10-arm.PackageA", target.Dependencies[1].Id); Assert.Equal(PackageDependencyType.Transitive, target.Dependencies[1].Type); Assert.Null(target.Dependencies[1].RequestedVersion); Assert.Equal("1.0.0", target.Dependencies[0].ResolvedVersion.ToNormalizedString()); Assert.NotEmpty(target.Dependencies[1].Sha512); }
public void Read_VariousTargetFrameworksAndRuntimeIdentifiers_ParsedCorrectly() { // Arrange var lockFileContents = @"{ ""version"": 1, ""dependencies"": { "".NETFramework,Version=v4.7.2"": { }, "".NETStandard,Version=v2.0"": { }, "".NETCoreApp,Version=3.1"": { }, "".NETCoreApp,Version=3.1/win-x64"": { }, "".NETCoreApp,Version=5.0"": { }, "".NETCoreApp,Version=5.0/win-x64"": { }, ""net5.0-windows7.0"": { }, ""net5.0-windows7.0/win-x64"": { }, ""net6.0"": { }, ""net6.0/win-x64"": { }, ""net6.0-windows7.0"": { }, ""net6.0-windows7.0/win-x64"": { }, } }"; // Act var lockFile = PackagesLockFileFormat.Parse(lockFileContents, "In memory"); // Assert Assert.Equal(12, lockFile.Targets.Count); Assert.Equal(FrameworkConstants.CommonFrameworks.Net472, lockFile.Targets[0].TargetFramework); Assert.Null(lockFile.Targets[0].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.NetStandard20, lockFile.Targets[1].TargetFramework); Assert.Null(lockFile.Targets[1].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.NetCoreApp31, lockFile.Targets[2].TargetFramework); Assert.Null(lockFile.Targets[2].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.NetCoreApp31, lockFile.Targets[3].TargetFramework); Assert.Equal("win-x64", lockFile.Targets[3].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.Net50, lockFile.Targets[4].TargetFramework); Assert.Null(lockFile.Targets[4].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.Net50, lockFile.Targets[5].TargetFramework); Assert.Equal("win-x64", lockFile.Targets[5].RuntimeIdentifier); NuGetFramework net5win7 = NuGetFramework.Parse("net5.0-windows7.0"); Assert.Equal(net5win7, lockFile.Targets[6].TargetFramework); Assert.Null(lockFile.Targets[6].RuntimeIdentifier); Assert.Equal(net5win7, lockFile.Targets[7].TargetFramework); Assert.Equal("win-x64", lockFile.Targets[7].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.Net60, lockFile.Targets[8].TargetFramework); Assert.Null(lockFile.Targets[8].RuntimeIdentifier); Assert.Equal(FrameworkConstants.CommonFrameworks.Net60, lockFile.Targets[9].TargetFramework); Assert.Equal("win-x64", lockFile.Targets[9].RuntimeIdentifier); NuGetFramework net6win7 = NuGetFramework.Parse("net6.0-windows7.0"); Assert.Equal(net6win7, lockFile.Targets[10].TargetFramework); Assert.Null(lockFile.Targets[10].RuntimeIdentifier); Assert.Equal(net6win7, lockFile.Targets[11].TargetFramework); Assert.Equal("win-x64", lockFile.Targets[11].RuntimeIdentifier); }