From b4a3c684fd6f88f84f9bf7d06d9430b63c1331fc Mon Sep 17 00:00:00 2001
From: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Date: Fri, 21 Oct 2022 06:20:15 +0300
Subject: [PATCH] Migrate host.tests from Newtonsoft to STJ (#76901)
---
eng/Versions.props | 1 +
.../PortableApp/PortableApp.csproj | 6 +-
...ndencyResolutionCommandResultExtensions.cs | 8 +-
.../LightupAppActivation.cs | 24 +--
.../BundlerConsistencyTests.cs | 4 +-
.../Assertions/AssertionScopeExtensions.cs | 20 ---
.../Assertions/CommandResultAssertions.cs | 34 ++--
.../Assertions/DirectoryInfoAssertions.cs | 16 +-
.../tests/TestUtils/RuntimeConfig.cs | 59 ++++---
.../tests/TestUtils/SharedFramework.cs | 161 ++++++++----------
.../tests/TestUtils/TestUtils.csproj | 3 +-
.../tests/CompilationLibraryTests.cs | 4 +-
.../tests/DependencyContextJsonWriterTests.cs | 4 +-
.../tests/JsonAssetions.cs | 7 +-
...ft.Extensions.DependencyModel.Tests.csproj | 2 +-
15 files changed, 154 insertions(+), 199 deletions(-)
delete mode 100644 src/installer/tests/TestUtils/Assertions/AssertionScopeExtensions.cs
diff --git a/eng/Versions.props b/eng/Versions.props
index a9d5999c72a..7882b339f24 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -189,6 +189,7 @@
1.0.2
2.0.4
4.12.0
+ 6.7.0
2.14.3
3.19.4
diff --git a/src/installer/tests/Assets/TestProjects/PortableApp/PortableApp.csproj b/src/installer/tests/Assets/TestProjects/PortableApp/PortableApp.csproj
index 96f7d139662..9cf6012fd61 100644
--- a/src/installer/tests/Assets/TestProjects/PortableApp/PortableApp.csproj
+++ b/src/installer/tests/Assets/TestProjects/PortableApp/PortableApp.csproj
@@ -1,6 +1,4 @@
-
-
-
+
$(NetCoreAppCurrent)
@@ -12,6 +10,4 @@
-
-
diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/DependencyResolutionCommandResultExtensions.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/DependencyResolutionCommandResultExtensions.cs
index 149eead4c7a..a4e5d55fd02 100644
--- a/src/installer/tests/HostActivation.Tests/DependencyResolution/DependencyResolutionCommandResultExtensions.cs
+++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/DependencyResolutionCommandResultExtensions.cs
@@ -22,7 +22,7 @@ public static AndConstraint HaveRuntimePropertyContaini
foreach (string value in values)
{
Execute.Assertion.ForCondition(propertyValue != null && propertyValue.Contains(value))
- .FailWithPreformatted($"The property {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
+ .FailWith($"The property {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}
@@ -37,7 +37,7 @@ public static AndConstraint NotHaveRuntimePropertyConta
foreach (string value in values)
{
Execute.Assertion.ForCondition(propertyValue != null && !propertyValue.Contains(value))
- .FailWithPreformatted($"The property {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
+ .FailWith($"The property {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}
@@ -84,7 +84,7 @@ public static AndConstraint HaveSuccessfullyResolvedCom
foreach (string value in values)
{
Execute.Assertion.ForCondition(propertyValue != null && propertyValue.Contains(value))
- .FailWithPreformatted($"The resolved {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
+ .FailWith($"The resolved {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}
@@ -102,7 +102,7 @@ public static AndConstraint HaveSuccessfullyResolvedCom
foreach (string value in values)
{
Execute.Assertion.ForCondition(propertyValue != null && !propertyValue.Contains(value))
- .FailWithPreformatted($"The resolved {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
+ .FailWith($"The resolved {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}
diff --git a/src/installer/tests/HostActivation.Tests/LightupAppActivation.cs b/src/installer/tests/HostActivation.Tests/LightupAppActivation.cs
index f301ac06e00..acab6db7128 100644
--- a/src/installer/tests/HostActivation.Tests/LightupAppActivation.cs
+++ b/src/installer/tests/HostActivation.Tests/LightupAppActivation.cs
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using Newtonsoft.Json.Linq;
using System;
using System.IO;
+using System.Text.Json.Nodes;
using Xunit;
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation
@@ -400,9 +400,11 @@ public void SharedFx_With_Higher_Version_Wins_Against_Additional_Deps()
// Create a deps.json file in the folder "additionalDeps\shared\Microsoft.NETCore.App\9999.0.0"
string additionalDepsRootPath = Path.Combine(_fxBaseDir, "additionalDeps");
- JObject versionInfo = new JObject();
- versionInfo.Add(new JProperty("assemblyVersion", "0.0.0.1"));
- versionInfo.Add(new JProperty("fileVersion", "0.0.0.2"));
+ JsonObject versionInfo = new JsonObject
+ {
+ ["assemblyVersion"] = "0.0.0.1",
+ ["fileVersion"] = "0.0.0.2"
+ };
string additionalDepsPath = CreateAdditionalDeps(additionalDepsRootPath, versionInfo);
// Version: NetCoreApp 9999.0.0
@@ -456,10 +458,12 @@ public void SharedFx_With_Lower_Version_Loses_Against_Additional_Deps()
// Create a deps.json file in the folder "additionalDeps\shared\Microsoft.NETCore.App\9999.0.0"
string additionalDepsRootPath = Path.Combine(_fxBaseDir, "additionalDeps");
- JObject versionInfo = new JObject();
- // Use Higher version numbers to win
- versionInfo.Add(new JProperty("assemblyVersion", "99.9.9.9"));
- versionInfo.Add(new JProperty("fileVersion", "98.9.9.9"));
+ JsonObject versionInfo = new JsonObject
+ {
+ // Use Higher version numbers to win
+ ["assemblyVersion"] = "99.9.9.9",
+ ["fileVersion"] = "98.9.9.9"
+ };
string additionalDepsPath = CreateAdditionalDeps(additionalDepsRootPath, versionInfo);
// Version: NetCoreApp 9999.0.0
@@ -492,7 +496,7 @@ private static void CreateLightupFolder(string customLightupPath, string version
File.Copy(libDepsJson, Path.Combine(customLightupPath, Path.GetFileName(libDepsJson)));
}
- private static string CreateAdditionalDeps(string destDir, JObject immutableCollectionVersionInfo)
+ private static string CreateAdditionalDeps(string destDir, JsonObject immutableCollectionVersionInfo)
{
DirectoryInfo dir = new DirectoryInfo(destDir);
if (dir.Exists)
@@ -502,7 +506,7 @@ private static string CreateAdditionalDeps(string destDir, JObject immutableColl
dir.Create();
- JObject depsjson = SharedFramework.CreateDepsJson("Microsoft.NETCore.App", "LightupLib/1.0.0", "LightupLib");
+ JsonObject depsjson = SharedFramework.CreateDepsJson("Microsoft.NETCore.App", "LightupLib/1.0.0", "LightupLib");
string depsFile = Path.Combine(destDir, "My.deps.json");
File.WriteAllText(depsFile, depsjson.ToString());
diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs
index 6a843806c2f..667b17a95be 100644
--- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs
+++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs
@@ -173,9 +173,9 @@ public void TestWithIdenticalBundlesShouldBeBinaryEqualPasses()
var secondBundle = CreateSampleBundle(true);
byte[] secondBundleContent = File.ReadAllBytes(secondBundle.bundleFileName);
- firstBundle.bundleId.ShouldBeEquivalentTo(secondBundle.bundleId,
+ firstBundle.bundleId.Should().BeEquivalentTo(secondBundle.bundleId,
"Deterministic/Reproducible build should produce identical bundle id for identical inputs");
- firstBundleContent.ShouldBeEquivalentTo(secondBundleContent,
+ firstBundleContent.Should().BeEquivalentTo(secondBundleContent,
"Deterministic/Reproducible build should produce identical binary for identical inputs");
}
diff --git a/src/installer/tests/TestUtils/Assertions/AssertionScopeExtensions.cs b/src/installer/tests/TestUtils/Assertions/AssertionScopeExtensions.cs
deleted file mode 100644
index 5dcc970d16f..00000000000
--- a/src/installer/tests/TestUtils/Assertions/AssertionScopeExtensions.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using FluentAssertions.Execution;
-
-namespace Microsoft.DotNet.CoreSetup.Test
-{
- public static class AssertionScopeExtensions
- {
- public static Continuation FailWithPreformatted(this AssertionScope assertionScope, string message)
- {
- if (!assertionScope.Succeeded)
- {
- assertionScope.AddFailure(message);
- }
-
- return new Continuation(assertionScope, assertionScope.Succeeded);
- }
- }
-}
diff --git a/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs b/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs
index d9f632aa2c1..f939ba13883 100644
--- a/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs
+++ b/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs
@@ -21,105 +21,105 @@ public CommandResultAssertions(CommandResult commandResult)
public AndConstraint ExitWith(int expectedExitCode)
{
Execute.Assertion.ForCondition(Result.ExitCode == expectedExitCode)
- .FailWithPreformatted($"Expected command to exit with {expectedExitCode} but it did not.{GetDiagnosticsInfo()}");
+ .FailWith($"Expected command to exit with {expectedExitCode} but it did not.{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint Pass()
{
Execute.Assertion.ForCondition(Result.ExitCode == 0)
- .FailWithPreformatted($"Expected command to pass but it did not.{GetDiagnosticsInfo()}");
+ .FailWith($"Expected command to pass but it did not.{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint Fail()
{
Execute.Assertion.ForCondition(Result.ExitCode != 0)
- .FailWithPreformatted($"Expected command to fail but it did not.{GetDiagnosticsInfo()}");
+ .FailWith($"Expected command to fail but it did not.{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdOut()
{
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(Result.StdOut))
- .FailWithPreformatted($"Command did not output anything to stdout{GetDiagnosticsInfo()}");
+ .FailWith($"Command did not output anything to stdout{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdOut(string expectedOutput)
{
Execute.Assertion.ForCondition(Result.StdOut.Equals(expectedOutput, StringComparison.Ordinal))
- .FailWithPreformatted($"Command did not output with Expected Output. Expected: '{expectedOutput}'{GetDiagnosticsInfo()}");
+ .FailWith($"Command did not output with Expected Output. Expected: '{expectedOutput}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdOutContaining(string pattern)
{
Execute.Assertion.ForCondition(Result.StdOut.Contains(pattern))
- .FailWithPreformatted($"The command output did not contain expected result: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"The command output did not contain expected result: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint NotHaveStdOutContaining(string pattern)
{
Execute.Assertion.ForCondition(!Result.StdOut.Contains(pattern))
- .FailWithPreformatted($"The command output contained a result it should not have contained: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"The command output contained a result it should not have contained: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
{
Execute.Assertion.ForCondition(Regex.IsMatch(Result.StdOut, pattern, options))
- .FailWithPreformatted($"Matching the command output failed. Pattern: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"Matching the command output failed. Pattern: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdErr()
{
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(Result.StdErr))
- .FailWithPreformatted($"Command did not output anything to stderr.{GetDiagnosticsInfo()}");
+ .FailWith($"Command did not output anything to stderr.{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdErrContaining(string pattern)
{
Execute.Assertion.ForCondition(Result.StdErr.Contains(pattern))
- .FailWithPreformatted($"The command error output did not contain expected result: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"The command error output did not contain expected result: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint NotHaveStdErrContaining(string pattern)
{
Execute.Assertion.ForCondition(!Result.StdErr.Contains(pattern))
- .FailWithPreformatted($"The command error output contained a result it should not have contained: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"The command error output contained a result it should not have contained: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint HaveStdErrMatching(string pattern, RegexOptions options = RegexOptions.None)
{
Execute.Assertion.ForCondition(Regex.IsMatch(Result.StdErr, pattern, options))
- .FailWithPreformatted($"Matching the command error output failed. Pattern: '{pattern}'{GetDiagnosticsInfo()}");
+ .FailWith($"Matching the command error output failed. Pattern: '{pattern}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint NotHaveStdOut()
{
Execute.Assertion.ForCondition(string.IsNullOrEmpty(Result.StdOut))
- .FailWithPreformatted($"Expected command to not output to stdout but it was not:{GetDiagnosticsInfo()}");
+ .FailWith($"Expected command to not output to stdout but it was not:{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint NotHaveStdErr()
{
Execute.Assertion.ForCondition(string.IsNullOrEmpty(Result.StdErr))
- .FailWithPreformatted($"Expected command to not output to stderr but it was not:{GetDiagnosticsInfo()}");
+ .FailWith($"Expected command to not output to stderr but it was not:{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
public AndConstraint FileExists(string path)
{
Execute.Assertion.ForCondition(System.IO.File.Exists(path))
- .FailWithPreformatted($"The command did not write the expected file: '{path}'{GetDiagnosticsInfo()}");
+ .FailWith($"The command did not write the expected file: '{path}'{GetDiagnosticsInfo()}");
return new AndConstraint(this);
}
@@ -127,7 +127,7 @@ public AndConstraint FileContains(string path, string p
{
string fileContent = System.IO.File.ReadAllText(path);
Execute.Assertion.ForCondition(fileContent.Contains(pattern))
- .FailWithPreformatted($"The command did not write the expected result '{pattern}' to the file: '{path}'{GetDiagnosticsInfo()}{Environment.NewLine}file content: >>{fileContent}<<");
+ .FailWith($"The command did not write the expected result '{pattern}' to the file: '{path}'{GetDiagnosticsInfo()}{Environment.NewLine}file content: >>{fileContent}<<");
return new AndConstraint(this);
}
@@ -135,7 +135,7 @@ public AndConstraint NotFileContains(string path, strin
{
string fileContent = System.IO.File.ReadAllText(path);
Execute.Assertion.ForCondition(!fileContent.Contains(pattern))
- .FailWithPreformatted($"The command did not write the expected result '{pattern}' to the file: '{path}'{GetDiagnosticsInfo()}{Environment.NewLine}file content: >>{fileContent}<<");
+ .FailWith($"The command did not write the expected result '{pattern}' to the file: '{path}'{GetDiagnosticsInfo()}{Environment.NewLine}file content: >>{fileContent}<<");
return new AndConstraint(this);
}
diff --git a/src/installer/tests/TestUtils/Assertions/DirectoryInfoAssertions.cs b/src/installer/tests/TestUtils/Assertions/DirectoryInfoAssertions.cs
index d4915024c00..9dccb26045c 100644
--- a/src/installer/tests/TestUtils/Assertions/DirectoryInfoAssertions.cs
+++ b/src/installer/tests/TestUtils/Assertions/DirectoryInfoAssertions.cs
@@ -24,7 +24,7 @@ public DirectoryInfoAssertions(DirectoryInfo dir)
public AndConstraint Exist()
{
Execute.Assertion.ForCondition(_dirInfo.Exists)
- .FailWithPreformatted($"Expected directory '{_dirInfo.FullName}' does not exist.");
+ .FailWith($"Expected directory '{_dirInfo.FullName}' does not exist.");
return new AndConstraint(this);
}
@@ -32,7 +32,7 @@ public AndConstraint HaveFile(string expectedFile)
{
var file = _dirInfo.EnumerateFiles(expectedFile, SearchOption.TopDirectoryOnly).SingleOrDefault();
Execute.Assertion.ForCondition(file != null)
- .FailWithPreformatted($"Expected File '{expectedFile}' cannot be found in directory '{_dirInfo.FullName}.");
+ .FailWith($"Expected File '{expectedFile}' cannot be found in directory '{_dirInfo.FullName}.");
return new AndConstraint(this);
}
@@ -40,7 +40,7 @@ public AndConstraint NotHaveFile(string expectedFile)
{
var file = _dirInfo.EnumerateFiles(expectedFile, SearchOption.TopDirectoryOnly).SingleOrDefault();
Execute.Assertion.ForCondition(file == null)
- .FailWithPreformatted($"File '{expectedFile}' should not be found in directory '{_dirInfo.FullName}'.");
+ .FailWith($"File '{expectedFile}' should not be found in directory '{_dirInfo.FullName}'.");
return new AndConstraint(this);
}
@@ -68,7 +68,7 @@ public AndConstraint HaveDirectory(string expectedDir)
{
var dir = _dirInfo.EnumerateDirectories(expectedDir, SearchOption.TopDirectoryOnly).SingleOrDefault();
Execute.Assertion.ForCondition(dir != null)
- .FailWithPreformatted($"Expected directory '{expectedDir}' cannot be found inside directory '{_dirInfo.FullName}'.");
+ .FailWith($"Expected directory '{expectedDir}' cannot be found inside directory '{_dirInfo.FullName}'.");
return new AndConstraint(new DirectoryInfoAssertions(dir));
}
@@ -77,7 +77,7 @@ public AndConstraint NotHaveDirectory(string expectedDi
{
var dir = _dirInfo.EnumerateDirectories(expectedDir, SearchOption.TopDirectoryOnly).SingleOrDefault();
Execute.Assertion.ForCondition(dir == null)
- .FailWithPreformatted($"Directory '{expectedDir}' should not be found in found inside directory '{_dirInfo.FullName}'.");
+ .FailWith($"Directory '{expectedDir}' should not be found in found inside directory '{_dirInfo.FullName}'.");
return new AndConstraint(new DirectoryInfoAssertions(dir));
}
@@ -90,10 +90,10 @@ public AndConstraint OnlyHaveFiles(IEnumerable
var nl = Environment.NewLine;
Execute.Assertion.ForCondition(!missingFiles.Any())
- .FailWithPreformatted($"Following files cannot be found inside directory {_dirInfo.FullName} {nl} {string.Join(nl, missingFiles)}");
+ .FailWith($"Following files cannot be found inside directory {_dirInfo.FullName} {nl} {string.Join(nl, missingFiles)}");
Execute.Assertion.ForCondition(!extraFiles.Any())
- .FailWithPreformatted($"Following extra files are found inside directory {_dirInfo.FullName} {nl} {string.Join(nl, extraFiles)}");
+ .FailWith($"Following extra files are found inside directory {_dirInfo.FullName} {nl} {string.Join(nl, extraFiles)}");
return new AndConstraint(this);
}
@@ -104,7 +104,7 @@ public AndConstraint NotBeModifiedAfter(DateTime timeUt
DateTime writeTime = _dirInfo.LastWriteTimeUtc;
Execute.Assertion.ForCondition(writeTime <= timeUtc)
- .FailWithPreformatted($"Directory '{_dirInfo.FullName}' should not be modified after {timeUtc}, but is modified at {writeTime}.");
+ .FailWith($"Directory '{_dirInfo.FullName}' should not be modified after {timeUtc}, but is modified at {writeTime}.");
return new AndConstraint(this);
}
diff --git a/src/installer/tests/TestUtils/RuntimeConfig.cs b/src/installer/tests/TestUtils/RuntimeConfig.cs
index b4abe04cdbc..057346a3192 100644
--- a/src/installer/tests/TestUtils/RuntimeConfig.cs
+++ b/src/installer/tests/TestUtils/RuntimeConfig.cs
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text.Json;
+using System.Text.Json.Nodes;
namespace Microsoft.DotNet.CoreSetup.Test
{
@@ -45,9 +45,9 @@ public Framework WithApplyPatches(bool? value)
return this;
}
- internal JObject ToJson()
+ internal JsonObject ToJson()
{
- JObject frameworkReference = new JObject();
+ JsonObject frameworkReference = new();
if (Name != null)
{
@@ -83,9 +83,9 @@ internal JObject ToJson()
return frameworkReference;
}
- internal static Framework FromJson(JObject jobject)
+ internal static Framework FromJson(JsonObject jobject)
{
- return new Framework((string)jobject["name"], (string)jobject["version"])
+ return new Framework(jobject["name"].ToString(), jobject["version"].ToString())
{
RollForward = (string)jobject[Constants.RollForwardSetting.RuntimeConfigPropertyName],
RollForwardOnNoCandidateFx = (int?)jobject[Constants.RollForwardOnNoCandidateFxSetting.RuntimeConfigPropertyName],
@@ -117,44 +117,43 @@ public RuntimeConfig(string path)
///
public static RuntimeConfig FromFile(string path)
{
- RuntimeConfig runtimeConfig = new RuntimeConfig(path);
+ RuntimeConfig runtimeConfig = new(path);
if (File.Exists(path))
{
- using (TextReader textReader = File.OpenText(path))
- using (var reader = new JsonTextReader(textReader) { MaxDepth = null })
+ var reader = new Utf8JsonReader(File.ReadAllBytes(path));
{
- JObject root = (JObject)JToken.ReadFrom(reader);
- JObject runtimeOptions = (JObject)root["runtimeOptions"];
- var singleFramework = runtimeOptions["framework"] as JObject;
+ JsonObject root = (JsonObject)JsonNode.Parse(ref reader);
+ JsonObject runtimeOptions = (JsonObject)root["runtimeOptions"];
+ var singleFramework = runtimeOptions["framework"] as JsonObject;
if (singleFramework != null)
{
runtimeConfig.WithFramework(Framework.FromJson(singleFramework));
}
- var frameworks = runtimeOptions["frameworks"];
+ JsonArray frameworks = runtimeOptions["frameworks"] as JsonArray;
if (frameworks != null)
{
- foreach (JObject framework in frameworks)
+ foreach (var framework in frameworks)
{
- runtimeConfig.WithFramework(Framework.FromJson(framework));
+ runtimeConfig.WithFramework(Framework.FromJson((JsonObject)framework));
}
}
- var includedFrameworks = runtimeOptions["includedFrameworks"];
+ JsonArray includedFrameworks = runtimeOptions["includedFrameworks"] as JsonArray;
if (includedFrameworks != null)
{
- foreach (JObject includedFramework in includedFrameworks)
+ foreach (var includedFramework in includedFrameworks)
{
- runtimeConfig.WithFramework(Framework.FromJson(includedFramework));
+ runtimeConfig.WithFramework(Framework.FromJson((JsonObject)includedFramework));
}
}
- var configProperties = runtimeOptions["configProperties"] as JObject;
+ JsonObject configProperties = runtimeOptions["configProperties"] as JsonObject;
if (configProperties != null)
{
- foreach (KeyValuePair property in configProperties)
+ foreach (var property in configProperties)
{
- runtimeConfig.WithProperty(property.Key, (string)property.Value);
+ runtimeConfig.WithProperty(property.Key, property.Value.ToString());
}
}
@@ -242,19 +241,19 @@ public RuntimeConfig WithProperty(string name, string value)
public void Save()
{
- JObject runtimeOptions = new JObject();
+ JsonObject runtimeOptions = new JsonObject();
if (_frameworks.Any())
{
runtimeOptions.Add(
"frameworks",
- new JArray(_frameworks.Select(f => f.ToJson()).ToArray()));
+ new JsonArray(_frameworks.Select(f => f.ToJson()).ToArray()));
}
if (_includedFrameworks.Any())
{
runtimeOptions.Add(
"includedFrameworks",
- new JArray(_includedFrameworks.Select(f => f.ToJson()).ToArray()));
+ new JsonArray(_includedFrameworks.Select(f => f.ToJson()).ToArray()));
}
if (_rollForward != null)
@@ -287,21 +286,21 @@ public void Save()
if (_properties.Count > 0)
{
- JObject configProperties = new JObject();
+ JsonObject configProperties = new JsonObject();
foreach (var property in _properties)
{
var tokenValue = (property.Item2 == "false" || property.Item2 == "true") ?
- JToken.Parse(property.Item2) : property.Item2;
+ JsonNode.Parse(property.Item2) : property.Item2;
configProperties.Add(property.Item1, tokenValue);
}
runtimeOptions.Add("configProperties", configProperties);
}
- JObject json = new JObject()
- {
- { "runtimeOptions", runtimeOptions }
- };
+ JsonObject json = new JsonObject
+ {
+ ["runtimeOptions"] = runtimeOptions
+ };
File.WriteAllText(_path, json.ToString());
}
diff --git a/src/installer/tests/TestUtils/SharedFramework.cs b/src/installer/tests/TestUtils/SharedFramework.cs
index 408cf58f37b..f30fa8fa578 100644
--- a/src/installer/tests/TestUtils/SharedFramework.cs
+++ b/src/installer/tests/TestUtils/SharedFramework.cs
@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using Newtonsoft.Json.Linq;
using System.IO;
+using System.Linq;
+using System.Text.Json;
+using System.Text.Json.Nodes;
using System.Threading;
namespace Microsoft.DotNet.CoreSetup.Test
@@ -91,18 +93,18 @@ public static void AddAvailableSharedUberFxVersions(string sharedFxDir, string s
* }
* }
*/
- public static void SetRuntimeConfigJson(string destFile, string version, int? rollFwdOnNoCandidateFx = null, bool? useUberFramework = false, JArray frameworks = null)
+ public static void SetRuntimeConfigJson(string destFile, string version, int? rollFwdOnNoCandidateFx = null, bool? useUberFramework = false, JsonArray frameworks = null)
{
string name = useUberFramework.HasValue && useUberFramework.Value ? "Microsoft.UberFramework" : "Microsoft.NETCore.App";
- JObject runtimeOptions = new JObject(
- new JProperty("framework",
- new JObject(
- new JProperty("name", name),
- new JProperty("version", version)
- )
- )
- );
+ JsonObject runtimeOptions = new JsonObject
+ {
+ ["framework"] = new JsonObject
+ {
+ ["name"] = name,
+ ["version"] = version
+ }
+ };
if (rollFwdOnNoCandidateFx.HasValue)
{
@@ -120,7 +122,7 @@ public static void SetRuntimeConfigJson(string destFile, string version, int? ro
file.Directory.Create();
}
- JObject json = new JObject();
+ JsonObject json = new JsonObject();
json.Add("runtimeOptions", runtimeOptions);
File.WriteAllText(destFile, json.ToString());
}
@@ -173,18 +175,18 @@ public static void CreateUberFrameworkArtifacts(string builtSharedFxDir, string
dir.Create();
- JObject versionInfo = new JObject();
+ JsonObject versionInfo = new JsonObject();
if (assemblyVersion != null)
{
- versionInfo.Add(new JProperty("assemblyVersion", assemblyVersion));
+ versionInfo.Add("assemblyVersion", (JsonNode)assemblyVersion);
}
if (fileVersion != null)
{
- versionInfo.Add(new JProperty("fileVersion", fileVersion));
+ versionInfo.Add("fileVersion", (JsonNode)fileVersion);
}
- JObject depsjson = CreateDepsJson("UberFx", "System.Collections.Immutable/1.0.0", "System.Collections.Immutable", versionInfo);
+ JsonObject depsjson = CreateDepsJson("UberFx", "System.Collections.Immutable/1.0.0", "System.Collections.Immutable", versionInfo);
string depsFile = Path.Combine(builtSharedUberFxDir, "Microsoft.UberFramework.deps.json");
File.WriteAllText(depsFile, depsjson.ToString());
@@ -194,7 +196,7 @@ public static void CreateUberFrameworkArtifacts(string builtSharedFxDir, string
File.Copy(fileSource, fileDest);
}
- public static JObject CreateDepsJson(string fxName, string testPackage, string testAssembly, JObject versionInfo = null)
+ public static JsonObject CreateDepsJson(string fxName, string testPackage, string testAssembly, JsonObject versionInfo = null)
{
// Create the deps.json. Generated file (example)
/*
@@ -224,49 +226,39 @@ public static JObject CreateDepsJson(string fxName, string testPackage, string t
if (versionInfo == null)
{
- versionInfo = new JObject();
+ versionInfo = new JsonObject();
}
- JObject depsjson = new JObject(
- new JProperty("runtimeTarget",
- new JObject(
- new JProperty("name", fxName)
- )
- ),
- new JProperty("targets",
- new JObject(
- new JProperty(fxName,
- new JObject(
- new JProperty(testPackage,
- new JObject(
- new JProperty("dependencies",
- new JObject()
- ),
- new JProperty("runtime",
- new JObject(
- new JProperty(testAssembly + ".dll",
- versionInfo
- )
- )
- )
- )
- )
- )
- )
- )
- ),
- new JProperty("libraries",
- new JObject(
- new JProperty(testPackage,
- new JObject(
- new JProperty("type", "assemblyreference"),
- new JProperty("serviceable", false),
- new JProperty("sha512", "")
- )
- )
- )
- )
- );
+ JsonObject depsjson = new JsonObject
+ {
+ ["runtimeTarget"] = new JsonObject
+ {
+ ["name"] = fxName
+ },
+ ["targets"] = new JsonObject
+ {
+ [fxName] = new JsonObject
+ {
+ [testPackage] = new JsonObject
+ {
+ ["dependencies"] = new JsonObject(),
+ ["runtime"] = new JsonObject
+ {
+ [testAssembly + ".dll"] = versionInfo
+ }
+ }
+ }
+ },
+ ["libraries"] = new JsonObject
+ {
+ [testPackage] = new JsonObject
+ {
+ ["type"] = "assemblyreference",
+ ["serviceable"] = false,
+ ["sha512"] = ""
+ }
+ }
+ };
return depsjson;
}
@@ -276,52 +268,39 @@ public static JObject CreateDepsJson(string fxName, string testPackage, string t
string fxNameWithVersion,
string testPackage,
string testPackageVersion,
- JObject testAssemblyVersionInfo = null,
+ JsonObject testAssemblyVersionInfo = null,
string testAssembly = null)
{
- JObject depsjson = JObject.Parse(File.ReadAllText(jsonFile));
+ JsonObject depsjson = (JsonObject)JsonObject.Parse(File.ReadAllText(jsonFile));
string testPackageWithVersion = testPackage + "/" + testPackageVersion;
testAssembly = testAssembly ?? (testPackage + ".dll");
- JProperty targetsProperty = (JProperty)depsjson["targets"].First;
- JObject targetsValue = (JObject)targetsProperty.Value;
+ JsonObject targetsValue = (JsonObject)depsjson["targets"].AsObject().First().Value;
- var assembly = new JProperty(testPackage, testPackageVersion);
- JObject packageDependencies = (JObject)targetsValue[fxNameWithVersion]["dependencies"];
- packageDependencies.Add(assembly);
+ JsonObject packageDependencies = (JsonObject)targetsValue[fxNameWithVersion]["dependencies"];
+ packageDependencies.Add(testPackage, (JsonNode)testPackageVersion);
if (testAssemblyVersionInfo == null)
{
- testAssemblyVersionInfo = new JObject();
+ testAssemblyVersionInfo = new JsonObject();
}
- var package = new JProperty(testPackageWithVersion,
- new JObject(
- new JProperty("runtime",
- new JObject(
- new JProperty(testAssembly,
- new JObject(
- testAssemblyVersionInfo
- )
- )
- )
- )
- )
- );
-
- targetsValue.Add(package);
-
- var library = new JProperty(testPackageWithVersion,
- new JObject(
- new JProperty("type", "assemblyreference"),
- new JProperty("serviceable", false),
- new JProperty("sha512", "")
- )
- );
-
- JObject libraries = (JObject)depsjson["libraries"];
- libraries.Add(library);
+ targetsValue.Add(testPackageWithVersion, new JsonObject
+ {
+ ["runtime"] = new JsonObject
+ {
+ [testAssembly] = testAssemblyVersionInfo
+ }
+ });
+
+ JsonObject libraries = (JsonObject)depsjson["libraries"];
+ libraries.Add(testPackageWithVersion, new JsonObject
+ {
+ ["type"] = "assemblyreference",
+ ["serviceable"] = false,
+ ["sha512"] = ""
+ });
File.WriteAllText(jsonFile, depsjson.ToString());
}
diff --git a/src/installer/tests/TestUtils/TestUtils.csproj b/src/installer/tests/TestUtils/TestUtils.csproj
index 8b3aa595237..268d4af5451 100644
--- a/src/installer/tests/TestUtils/TestUtils.csproj
+++ b/src/installer/tests/TestUtils/TestUtils.csproj
@@ -12,10 +12,9 @@
-
+
-
diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/CompilationLibraryTests.cs b/src/libraries/Microsoft.Extensions.DependencyModel/tests/CompilationLibraryTests.cs
index 82af4c38d17..8ea5551b760 100644
--- a/src/libraries/Microsoft.Extensions.DependencyModel/tests/CompilationLibraryTests.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/CompilationLibraryTests.cs
@@ -39,7 +39,7 @@ public void ResolveReferencePathsAcceptsCustomResolvers()
var result = library.ResolveReferencePaths(resolvers);
- result.ShouldBeEquivalentTo(new[] { "Assembly" });
+ result.Should().BeEquivalentTo(new[] { "Assembly" });
fail.Verify(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>()),
Times.Once());
@@ -61,7 +61,7 @@ public void ResolveReferencePathsAcceptsNullCustomResolvers()
try
{
var result = library.ResolveReferencePaths(null);
- result.ShouldBeEquivalentTo(new[] { assemblyPath });
+ result.Should().BeEquivalentTo(new[] { assemblyPath });
}
finally
{
diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextJsonWriterTests.cs b/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextJsonWriterTests.cs
index 56120539576..3e306f0a46b 100644
--- a/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextJsonWriterTests.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextJsonWriterTests.cs
@@ -138,11 +138,11 @@ public void SavesRuntimeGraph()
rids.Should().HaveProperty("win7-x64")
.Subject.Should().BeOfType()
- .Which.Values().ShouldBeEquivalentTo(new[] { "win6", "win5" });
+ .Which.Values().Should().BeEquivalentTo(new[] { "win6", "win5" });
rids.Should().HaveProperty("win8-x64")
.Subject.Should().BeOfType()
- .Which.Values().ShouldBeEquivalentTo(new[] { "win7-x64" });
+ .Which.Values().Should().BeEquivalentTo(new[] { "win7-x64" });
}
[Fact]
diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/JsonAssetions.cs b/src/libraries/Microsoft.Extensions.DependencyModel/tests/JsonAssetions.cs
index 03d7790df56..80527195b3d 100644
--- a/src/libraries/Microsoft.Extensions.DependencyModel/tests/JsonAssetions.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/JsonAssetions.cs
@@ -22,12 +22,9 @@ public static JsonAssertions Should(this JToken jToken)
public class JsonAssertions: ReferenceTypeAssertions
{
- public JsonAssertions(JToken token)
- {
- Subject = token;
- }
+ public JsonAssertions(JToken token) : base(token) { }
- protected override string Context => nameof(JToken);
+ protected override string Identifier => nameof(JToken);
public AndWhichConstraint HaveProperty(string expected)
{
diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/Microsoft.Extensions.DependencyModel.Tests.csproj b/src/libraries/Microsoft.Extensions.DependencyModel/tests/Microsoft.Extensions.DependencyModel.Tests.csproj
index 1b00d522895..f6e4a1bbea1 100644
--- a/src/libraries/Microsoft.Extensions.DependencyModel/tests/Microsoft.Extensions.DependencyModel.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/Microsoft.Extensions.DependencyModel.Tests.csproj
@@ -9,7 +9,7 @@
-
+
--
GitLab