Update corefx dependencies (dotnet/extensions#1898)

\n\nCommit migrated from b398a5db3d
This commit is contained in:
Brennan 2019-06-27 10:21:07 -07:00 committed by GitHub
parent 2a890a978f
commit b39ec06467
5 changed files with 20 additions and 20 deletions

View File

@ -51,7 +51,7 @@ namespace Microsoft.JSInterop
return null;
}
return JsonSerializer.ToString(syncResult, JsonSerializerOptionsProvider.Options);
return JsonSerializer.Serialize(syncResult, JsonSerializerOptionsProvider.Options);
}
/// <summary>
@ -177,9 +177,9 @@ namespace Microsoft.JSInterop
var shouldDisposeJsonDocument = true;
try
{
if (jsonDocument.RootElement.Type != JsonValueType.Array)
if (jsonDocument.RootElement.ValueKind != JsonValueKind.Array)
{
throw new ArgumentException($"Expected a JSON array but got {jsonDocument.RootElement.Type}.");
throw new ArgumentException($"Expected a JSON array but got {jsonDocument.RootElement.ValueKind}.");
}
var suppliedArgsLength = jsonDocument.RootElement.GetArrayLength();
@ -211,7 +211,7 @@ namespace Microsoft.JSInterop
}
else
{
suppliedArgs[index] = JsonSerializer.Parse(item.GetRawText(), parameterType, JsonSerializerOptionsProvider.Options);
suppliedArgs[index] = JsonSerializer.Deserialize(item.GetRawText(), parameterType, JsonSerializerOptionsProvider.Options);
}
index++;
@ -236,7 +236,7 @@ namespace Microsoft.JSInterop
// Check for incorrect use of DotNetObjectRef<T> at the top level. We know it's
// an incorrect use if there's a object that looks like { '__dotNetObject': <some number> },
// but we aren't assigning to DotNetObjectRef{T}.
return item.Type == JsonValueType.Object &&
return item.ValueKind == JsonValueKind.Object &&
item.TryGetProperty(DotNetObjectRefKey, out _) &&
!typeof(IDotNetObjectRef).IsAssignableFrom(parameterType);
}

View File

@ -19,13 +19,13 @@ namespace Microsoft.JSInterop
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
public TValue Invoke<TValue>(string identifier, params object[] args)
{
var resultJson = InvokeJS(identifier, JsonSerializer.ToString(args, JsonSerializerOptionsProvider.Options));
var resultJson = InvokeJS(identifier, JsonSerializer.Serialize(args, JsonSerializerOptionsProvider.Options));
if (resultJson is null)
{
return default;
}
return JsonSerializer.Parse<TValue>(resultJson, JsonSerializerOptionsProvider.Options);
return JsonSerializer.Deserialize<TValue>(resultJson, JsonSerializerOptionsProvider.Options);
}
/// <summary>

View File

@ -42,7 +42,7 @@ namespace Microsoft.JSInterop
try
{
var argsJson = args?.Length > 0 ?
JsonSerializer.ToString(args, JsonSerializerOptionsProvider.Options) :
JsonSerializer.Serialize(args, JsonSerializerOptionsProvider.Options) :
null;
BeginInvokeJS(taskId, identifier, argsJson);
return tcs.Task;
@ -78,7 +78,7 @@ namespace Microsoft.JSInterop
// We pass 0 as the async handle because we don't want the JS-side code to
// send back any notification (we're just providing a result for an existing async call)
var args = JsonSerializer.ToString(new[] { callId, success, resultOrException }, JsonSerializerOptionsProvider.Options);
var args = JsonSerializer.Serialize(new[] { callId, success, resultOrException }, JsonSerializerOptionsProvider.Options);
BeginInvokeJS(0, "DotNet.jsCallDispatcher.endInvokeDotNetFromJS", args);
}
@ -97,7 +97,7 @@ namespace Microsoft.JSInterop
try
{
var result = asyncCallResult != null ?
JsonSerializer.Parse(asyncCallResult.JsonElement.GetRawText(), resultType, JsonSerializerOptionsProvider.Options) :
JsonSerializer.Deserialize(asyncCallResult.JsonElement.GetRawText(), resultType, JsonSerializerOptionsProvider.Options) :
null;
TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, result);
}

View File

@ -89,7 +89,7 @@ namespace Microsoft.JSInterop.Tests
{
// Arrange/Act
var resultJson = DotNetDispatcher.Invoke(thisAssemblyName, "InvocableStaticNonVoid", default, null);
var result = JsonSerializer.Parse<TestDTO>(resultJson, JsonSerializerOptionsProvider.Options);
var result = JsonSerializer.Deserialize<TestDTO>(resultJson, JsonSerializerOptionsProvider.Options);
// Assert
Assert.Equal("Test", result.StringVal);
@ -101,7 +101,7 @@ namespace Microsoft.JSInterop.Tests
{
// Arrange/Act
var resultJson = DotNetDispatcher.Invoke(thisAssemblyName, nameof(SomePublicType.InvokableMethodWithoutCustomIdentifier), default, null);
var result = JsonSerializer.Parse<TestDTO>(resultJson, JsonSerializerOptionsProvider.Options);
var result = JsonSerializer.Deserialize<TestDTO>(resultJson, JsonSerializerOptionsProvider.Options);
// Assert
Assert.Equal("InvokableMethodWithoutCustomIdentifier", result.StringVal);
@ -117,7 +117,7 @@ namespace Microsoft.JSInterop.Tests
jsRuntime.Invoke<object>("unimportant", objectRef);
// Arrange: Remaining args
var argsJson = JsonSerializer.ToString(new object[]
var argsJson = JsonSerializer.Serialize(new object[]
{
new TestDTO { StringVal = "Another string", IntVal = 456 },
new[] { 100, 200 },
@ -130,7 +130,7 @@ namespace Microsoft.JSInterop.Tests
var root = result.RootElement;
// Assert: First result value marshalled via JSON
var resultDto1 = JsonSerializer.Parse<TestDTO>(root[0].GetRawText(), JsonSerializerOptionsProvider.Options);
var resultDto1 = JsonSerializer.Deserialize<TestDTO>(root[0].GetRawText(), JsonSerializerOptionsProvider.Options);
Assert.Equal("ANOTHER STRING", resultDto1.StringVal);
Assert.Equal(756, resultDto1.IntVal);
@ -156,7 +156,7 @@ namespace Microsoft.JSInterop.Tests
jsRuntime.Invoke<object>("unimportant", objectRef);
// Arrange: Remaining args
var argsJson = JsonSerializer.ToString(new object[]
var argsJson = JsonSerializer.Serialize(new object[]
{
new TestDTO { StringVal = "Another string", IntVal = 456 },
new[] { 100, 200 },
@ -262,7 +262,7 @@ namespace Microsoft.JSInterop.Tests
public void CannotInvokeWithIncorrectNumberOfParams()
{
// Arrange
var argsJson = JsonSerializer.ToString(new object[] { 1, 2, 3, 4 }, JsonSerializerOptionsProvider.Options);
var argsJson = JsonSerializer.Serialize(new object[] { 1, 2, 3, 4 }, JsonSerializerOptionsProvider.Options);
// Act/Assert
var ex = Assert.Throws<ArgumentException>(() =>
@ -284,7 +284,7 @@ namespace Microsoft.JSInterop.Tests
jsRuntime.Invoke<object>("unimportant", arg1Ref, arg2Ref);
// Arrange: all args
var argsJson = JsonSerializer.ToString(new object[]
var argsJson = JsonSerializer.Serialize(new object[]
{
new TestDTO { IntVal = 1000, StringVal = "String via JSON" },
arg2Ref,
@ -306,12 +306,12 @@ namespace Microsoft.JSInterop.Tests
Assert.True(result[1].GetBoolean()); // Success flag
// Assert: First result value marshalled via JSON
var resultDto1 = JsonSerializer.Parse<TestDTO>(resultValue[0].GetRawText(), JsonSerializerOptionsProvider.Options);
var resultDto1 = JsonSerializer.Deserialize<TestDTO>(resultValue[0].GetRawText(), JsonSerializerOptionsProvider.Options);
Assert.Equal("STRING VIA JSON", resultDto1.StringVal);
Assert.Equal(2000, resultDto1.IntVal);
// Assert: Second result value marshalled by ref
var resultDto2Ref = JsonSerializer.Parse<DotNetObjectRef<TestDTO>>(resultValue[1].GetRawText(), JsonSerializerOptionsProvider.Options);
var resultDto2Ref = JsonSerializer.Deserialize<DotNetObjectRef<TestDTO>>(resultValue[1].GetRawText(), JsonSerializerOptionsProvider.Options);
var resultDto2 = resultDto2Ref.Value;
Assert.Equal("MY STRING", resultDto2.StringVal);
Assert.Equal(2468, resultDto2.IntVal);

View File

@ -111,7 +111,7 @@ namespace Microsoft.JSInterop.Tests
Assert.IsType<JsonException>(jsException.InnerException);
// Verify we've disposed the JsonDocument.
Assert.Throws<ObjectDisposedException>(() => jsonDocument.RootElement.Type);
Assert.Throws<ObjectDisposedException>(() => jsonDocument.RootElement.ValueKind);
}
[Fact]