未验证 提交 b4a3c684 编写于 作者: A Adeel Mujahid 提交者: GitHub

Migrate host.tests from Newtonsoft to STJ (#76901)

上级 3df94def
......@@ -189,6 +189,7 @@
<NewtonsoftJsonBsonVersion>1.0.2</NewtonsoftJsonBsonVersion>
<SQLitePCLRawbundle_greenVersion>2.0.4</SQLitePCLRawbundle_greenVersion>
<MoqVersion>4.12.0</MoqVersion>
<FluentAssertionsVersion>6.7.0</FluentAssertionsVersion>
<FsCheckVersion>2.14.3</FsCheckVersion>
<!-- Android gRPC client tests -->
<GoogleProtobufVersion>3.19.4</GoogleProtobufVersion>
......
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
......@@ -12,6 +10,4 @@
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
......@@ -22,7 +22,7 @@ public static AndConstraint<CommandResultAssertions> 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<CommandResultAssertions> 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<CommandResultAssertions> 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<CommandResultAssertions> 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()}");
}
......
// 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());
......
......@@ -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");
}
......
// 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);
}
}
}
......@@ -21,105 +21,105 @@ public CommandResultAssertions(CommandResult commandResult)
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
......@@ -127,7 +127,7 @@ public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
......@@ -135,7 +135,7 @@ public AndConstraint<CommandResultAssertions> 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<CommandResultAssertions>(this);
}
......
......@@ -24,7 +24,7 @@ public DirectoryInfoAssertions(DirectoryInfo dir)
public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(this);
}
......@@ -32,7 +32,7 @@ public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(this);
}
......@@ -40,7 +40,7 @@ public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(this);
}
......@@ -68,7 +68,7 @@ public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(new DirectoryInfoAssertions(dir));
}
......@@ -77,7 +77,7 @@ public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(new DirectoryInfoAssertions(dir));
}
......@@ -90,10 +90,10 @@ public AndConstraint<DirectoryInfoAssertions> OnlyHaveFiles(IEnumerable<string>
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<DirectoryInfoAssertions>(this);
}
......@@ -104,7 +104,7 @@ public AndConstraint<DirectoryInfoAssertions> 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<DirectoryInfoAssertions>(this);
}
......
// 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)
/// </summary>
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<string, JToken> 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());
}
......
// 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());
}
......
......@@ -12,10 +12,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
<PackageReference Include="xunit.core" Version="$(XUnitVersion)" ExcludeAssets="build" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelVersion)" />
</ItemGroup>
......
......@@ -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<CompilationLibrary>(), It.IsAny<List<string>>()),
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
{
......
......@@ -138,11 +138,11 @@ public void SavesRuntimeGraph()
rids.Should().HaveProperty("win7-x64")
.Subject.Should().BeOfType<JArray>()
.Which.Values<string>().ShouldBeEquivalentTo(new[] { "win6", "win5" });
.Which.Values<string>().Should().BeEquivalentTo(new[] { "win6", "win5" });
rids.Should().HaveProperty("win8-x64")
.Subject.Should().BeOfType<JArray>()
.Which.Values<string>().ShouldBeEquivalentTo(new[] { "win7-x64" });
.Which.Values<string>().Should().BeEquivalentTo(new[] { "win7-x64" });
}
[Fact]
......
......@@ -22,12 +22,9 @@ public static JsonAssertions Should(this JToken jToken)
public class JsonAssertions: ReferenceTypeAssertions<JToken, JsonAssertions>
{
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<JsonAssertions, JToken> HaveProperty(string expected)
{
......
......@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-003121" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册