Rename Json protocol to NewtonsoftJson (#4319)
This commit is contained in:
parent
d10205f309
commit
80ae51ead8
|
|
@ -17,7 +17,7 @@
|
|||
<!-- Assemblies required by the SignalR client. -->
|
||||
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.Http.Features" />
|
||||
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.SignalR.Common" />
|
||||
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.SignalR.Protocols.Json" />
|
||||
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" />
|
||||
|
||||
<!-- Assemblies produced by this repo that will move to aspnet/Extensions after repo refactoring is done -->
|
||||
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Identity.Core" />
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Client.Core" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Client" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Common" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Category="ship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.SignalR.Specification.Tests" Category="ship" />
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@
|
|||
<Dependency Include="Microsoft.AspNetCore.Session" Version="$(MicrosoftAspNetCoreSessionPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.SignalR.Common" Version="$(MicrosoftAspNetCoreSignalRCommonPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.SignalR.Core" Version="$(MicrosoftAspNetCoreSignalRCorePackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="$(MicrosoftAspNetCoreSignalRProtocolsJsonPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="$(MicrosoftAspNetCoreSignalRProtocolsNewtonsoftJsonPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.SignalR" Version="$(MicrosoftAspNetCoreSignalRPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.StaticFiles" Version="$(MicrosoftAspNetCoreStaticFilesPackageVersion)" />
|
||||
<Dependency Include="Microsoft.AspNetCore.WebSockets" Version="$(MicrosoftAspNetCoreWebSocketsPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27110.0
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28315.86
|
||||
MinimumVisualStudioVersion = 15.0.26730.03
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DA69F624-5398-4884-87E4-B816698CDE65}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
|
|
@ -77,7 +77,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Signal
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "clients\ts\FunctionalTests\FunctionalTests.csproj", "{D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Protocols.Json", "src\Microsoft.AspNetCore.SignalR.Protocols.Json\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj", "{896FA5EE-63A5-4EAC-9F09-346584BB4830}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson", "src\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj", "{896FA5EE-63A5-4EAC-9F09-346584BB4830}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkServer", "benchmarkapps\BenchmarkServer\BenchmarkServer.csproj", "{8C75AC94-C980-4FE1-9F79-6CED3C8665CE}"
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
|
||||
if (Protocol == "json")
|
||||
{
|
||||
protocol = new JsonHubProtocol();
|
||||
protocol = new NewtonsoftJsonHubProtocol();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
_groupNames = new List<string>();
|
||||
_userIdentifiers = new List<string>();
|
||||
|
||||
var jsonHubProtocol = new JsonHubProtocol();
|
||||
var jsonHubProtocol = new NewtonsoftJsonHubProtocol();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
var connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), _pipe, _pipe);
|
||||
_hubConnectionContext = new HubConnectionContext(connection, Timeout.InfiniteTimeSpan, NullLoggerFactory.Instance);
|
||||
|
||||
_successHubProtocolResolver = new TestHubProtocolResolver(new JsonHubProtocol());
|
||||
_successHubProtocolResolver = new TestHubProtocolResolver(new NewtonsoftJsonHubProtocol());
|
||||
_failureHubProtocolResolver = new TestHubProtocolResolver(null);
|
||||
_userIdProvider = new TestUserIdProvider();
|
||||
_supportedProtocols = new List<string> { "json" };
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
var hubConnectionBuilder = new HubConnectionBuilder();
|
||||
if (Protocol == "json")
|
||||
{
|
||||
hubProtocol = new JsonHubProtocol();
|
||||
hubProtocol = new NewtonsoftJsonHubProtocol();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -167,4 +167,4 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
await _waitTcs.Task.OrTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
_hubProtocol = new MessagePackHubProtocol();
|
||||
break;
|
||||
case Protocol.Json:
|
||||
_hubProtocol = new JsonHubProtocol();
|
||||
_hubProtocol = new NewtonsoftJsonHubProtocol();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
for (var i = 0; i < protocolCount; i++)
|
||||
{
|
||||
yield return ((i % 2) == 0)
|
||||
? new WrappedHubProtocol($"json_{i}", new JsonHubProtocol())
|
||||
? new WrappedHubProtocol($"json_{i}", new NewtonsoftJsonHubProtocol())
|
||||
: new WrappedHubProtocol($"messagepack_{i}", new MessagePackHubProtocol());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
|
||||
if (Protocol == "json")
|
||||
{
|
||||
protocol = new JsonHubProtocol();
|
||||
protocol = new NewtonsoftJsonHubProtocol();
|
||||
}
|
||||
else
|
||||
{
|
||||
// New line in result to trigger SSE formatting
|
||||
protocol = new JsonHubProtocol
|
||||
protocol = new NewtonsoftJsonHubProtocol
|
||||
{
|
||||
PayloadSerializer = { Formatting = Formatting.Indented }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
@ECHO OFF
|
||||
SET RepoRoot="%~dp0..\.."
|
||||
%RepoRoot%\build.cmd -LockFile %RepoRoot%\korebuild-lock.txt -Path %~dp0 %*
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
repo_root="$DIR/../.."
|
||||
"$repo_root/build.sh" --path "$DIR" --lockfile "$repo_root/korebuild-lock.txt" "$@"
|
||||
|
|
@ -34,7 +34,7 @@ namespace FunctionalTests
|
|||
{
|
||||
options.EnableDetailedErrors = true;
|
||||
})
|
||||
.AddJsonProtocol(options =>
|
||||
.AddNewtonsoftJsonProtocol(options =>
|
||||
{
|
||||
// we are running the same tests with JSON and MsgPack protocols and having
|
||||
// consistent casing makes it cleaner to verify results
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
Services = new ServiceCollection();
|
||||
Services.AddSingleton<HubConnection>();
|
||||
Services.AddLogging();
|
||||
this.AddJsonProtocol();
|
||||
this.AddNewtonsoftJsonProtocol();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Common\Microsoft.AspNetCore.SignalR.Common.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Protocols.Json\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Common\Microsoft.AspNetCore.SignalR.Common.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Protocols.Json\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
services.AddAuthorization();
|
||||
|
||||
var builder = new SignalRServerBuilder(services);
|
||||
builder.AddJsonProtocol();
|
||||
builder.AddNewtonsoftJsonProtocol();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Implements the SignalR Hub Protocol over JSON.</Description>
|
||||
<Description>Implements the SignalR Hub Protocol using Newtonsoft.Json.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<RootNamespace>Microsoft.AspNetCore.SignalR</RootNamespace>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
|
@ -7,13 +7,13 @@ using Newtonsoft.Json;
|
|||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
/// <summary>
|
||||
/// Options used to configure a <see cref="JsonHubProtocol"/> instance.
|
||||
/// Options used to configure a <see cref="NewtonsoftJsonHubProtocol"/> instance.
|
||||
/// </summary>
|
||||
public class JsonHubProtocolOptions
|
||||
public class NewtonsoftJsonHubProtocolOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the settings used to serialize invocation arguments and return values.
|
||||
/// </summary>
|
||||
public JsonSerializerSettings PayloadSerializerSettings { get; set; } = JsonHubProtocol.CreateDefaultSerializerSettings();
|
||||
public JsonSerializerSettings PayloadSerializerSettings { get; set; } = NewtonsoftJsonHubProtocol.CreateDefaultSerializerSettings();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
|
|
@ -9,7 +8,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
/// <summary>
|
||||
/// Extension methods for <see cref="ISignalRBuilder"/>.
|
||||
/// </summary>
|
||||
public static class JsonProtocolDependencyInjectionExtensions
|
||||
public static class NewtonsoftJsonProtocolDependencyInjectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables the JSON protocol for SignalR.
|
||||
|
|
@ -19,8 +18,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
/// </remarks>
|
||||
/// <param name="builder">The <see cref="ISignalRBuilder"/> representing the SignalR server to add JSON protocol support to.</param>
|
||||
/// <returns>The value of <paramref name="builder"/></returns>
|
||||
public static TBuilder AddJsonProtocol<TBuilder>(this TBuilder builder) where TBuilder : ISignalRBuilder
|
||||
=> AddJsonProtocol(builder, _ => { });
|
||||
public static TBuilder AddNewtonsoftJsonProtocol<TBuilder>(this TBuilder builder) where TBuilder : ISignalRBuilder
|
||||
=> AddNewtonsoftJsonProtocol(builder, _ => { });
|
||||
|
||||
/// <summary>
|
||||
/// Enables the JSON protocol for SignalR and allows options for the JSON protocol to be configured.
|
||||
|
|
@ -29,11 +28,11 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
/// Any options configured here will be applied, even if the JSON protocol has already been registered with the server.
|
||||
/// </remarks>
|
||||
/// <param name="builder">The <see cref="ISignalRBuilder"/> representing the SignalR server to add JSON protocol support to.</param>
|
||||
/// <param name="configure">A delegate that can be used to configure the <see cref="JsonHubProtocolOptions"/></param>
|
||||
/// <param name="configure">A delegate that can be used to configure the <see cref="NewtonsoftJsonHubProtocolOptions"/></param>
|
||||
/// <returns>The value of <paramref name="builder"/></returns>
|
||||
public static TBuilder AddJsonProtocol<TBuilder>(this TBuilder builder, Action<JsonHubProtocolOptions> configure) where TBuilder : ISignalRBuilder
|
||||
public static TBuilder AddNewtonsoftJsonProtocol<TBuilder>(this TBuilder builder, Action<NewtonsoftJsonHubProtocolOptions> configure) where TBuilder : ISignalRBuilder
|
||||
{
|
||||
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHubProtocol, JsonHubProtocol>());
|
||||
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHubProtocol, NewtonsoftJsonHubProtocol>());
|
||||
builder.Services.Configure(configure);
|
||||
return builder;
|
||||
}
|
||||
|
|
@ -17,9 +17,9 @@ using Newtonsoft.Json.Serialization;
|
|||
namespace Microsoft.AspNetCore.SignalR.Protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the SignalR Hub Protocol using JSON.
|
||||
/// Implements the SignalR Hub Protocol using Newtonsoft.Json.
|
||||
/// </summary>
|
||||
public class JsonHubProtocol : IHubProtocol
|
||||
public class NewtonsoftJsonHubProtocol : IHubProtocol
|
||||
{
|
||||
private const string ResultPropertyName = "result";
|
||||
private const string ItemPropertyName = "item";
|
||||
|
|
@ -41,17 +41,17 @@ namespace Microsoft.AspNetCore.SignalR.Protocol
|
|||
public JsonSerializer PayloadSerializer { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonHubProtocol"/> class.
|
||||
/// Initializes a new instance of the <see cref="NewtonsoftJsonHubProtocol"/> class.
|
||||
/// </summary>
|
||||
public JsonHubProtocol() : this(Options.Create(new JsonHubProtocolOptions()))
|
||||
public NewtonsoftJsonHubProtocol() : this(Options.Create(new NewtonsoftJsonHubProtocolOptions()))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonHubProtocol"/> class.
|
||||
/// Initializes a new instance of the <see cref="NewtonsoftJsonHubProtocol"/> class.
|
||||
/// </summary>
|
||||
/// <param name="options">The options used to initialize the protocol.</param>
|
||||
public JsonHubProtocol(IOptions<JsonHubProtocolOptions> options)
|
||||
public NewtonsoftJsonHubProtocol(IOptions<NewtonsoftJsonHubProtocolOptions> options)
|
||||
{
|
||||
PayloadSerializer = JsonSerializer.Create(options.Value.PayloadSerializerSettings);
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.SignalR.Protocols.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.Extensions.DependencyInjection.JsonProtocolDependencyInjectionExtensions",
|
||||
"Name": "Microsoft.Extensions.DependencyInjection.NewtonsoftJsonProtocolDependencyInjectionExtensions",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "AddJsonProtocol<T0>",
|
||||
"Name": "AddNewtonsoftJsonProtocol<T0>",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "builder",
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "AddJsonProtocol<T0>",
|
||||
"Name": "AddNewtonsoftJsonProtocol<T0>",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "builder",
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
},
|
||||
{
|
||||
"Name": "configure",
|
||||
"Type": "System.Action<Microsoft.AspNetCore.SignalR.JsonHubProtocolOptions>"
|
||||
"Type": "System.Action<Microsoft.AspNetCore.SignalR.NewtonsoftJsonHubProtocolOptions>"
|
||||
}
|
||||
],
|
||||
"ReturnType": "T0",
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.SignalR.JsonHubProtocolOptions",
|
||||
"Name": "Microsoft.AspNetCore.SignalR.NewtonsoftJsonHubProtocolOptions",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"ImplementedInterfaces": [],
|
||||
|
|
@ -101,7 +101,7 @@
|
|||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol",
|
||||
"Name": "Microsoft.AspNetCore.SignalR.Protocol.NewtonsoftJsonHubProtocol",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"ImplementedInterfaces": [
|
||||
|
|
@ -240,7 +240,7 @@
|
|||
"Parameters": [
|
||||
{
|
||||
"Name": "options",
|
||||
"Type": "Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.SignalR.JsonHubProtocolOptions>"
|
||||
"Type": "Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.SignalR.NewtonsoftJsonHubProtocolOptions>"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
|
|
@ -1116,7 +1116,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
public static Dictionary<string, IHubProtocol> HubProtocols =>
|
||||
new Dictionary<string, IHubProtocol>
|
||||
{
|
||||
{ "json", new JsonHubProtocol() },
|
||||
{ "json", new NewtonsoftJsonHubProtocol() },
|
||||
{ "messagepack", new MessagePackHubProtocol() },
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -14,12 +14,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
public class VersionedJsonHubProtocol : IHubProtocol
|
||||
{
|
||||
private readonly int _version;
|
||||
private readonly JsonHubProtocol _innerProtocol;
|
||||
private readonly NewtonsoftJsonHubProtocol _innerProtocol;
|
||||
|
||||
public VersionedJsonHubProtocol(int version)
|
||||
{
|
||||
_version = version;
|
||||
_innerProtocol = new JsonHubProtocol();
|
||||
_innerProtocol = new NewtonsoftJsonHubProtocol();
|
||||
}
|
||||
|
||||
public string Name => _innerProtocol.Name;
|
||||
|
|
@ -84,4 +84,4 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
return version <= _version;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,13 +101,13 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
public void AddJsonProtocolAddsProtocol()
|
||||
{
|
||||
var connectionBuilder = new HubConnectionBuilder();
|
||||
connectionBuilder.AddJsonProtocol();
|
||||
connectionBuilder.AddNewtonsoftJsonProtocol();
|
||||
|
||||
var serviceProvider = connectionBuilder.Services.BuildServiceProvider();
|
||||
|
||||
var resolvedHubProtocol = serviceProvider.GetService<IHubProtocol>();
|
||||
|
||||
Assert.IsType<JsonHubProtocol>(resolvedHubProtocol);
|
||||
Assert.IsType<NewtonsoftJsonHubProtocol>(resolvedHubProtocol);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -123,4 +123,4 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
Assert.IsType<MessagePackHubProtocol>(resolvedHubProtocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -27,16 +25,16 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
[Fact]
|
||||
public void AddJsonProtocolSetsHubProtocolToJsonWithDefaultOptions()
|
||||
{
|
||||
var serviceProvider = new HubConnectionBuilder().AddJsonProtocol().Services.BuildServiceProvider();
|
||||
var serviceProvider = new HubConnectionBuilder().AddNewtonsoftJsonProtocol().Services.BuildServiceProvider();
|
||||
|
||||
var actualProtocol = Assert.IsType<JsonHubProtocol>(serviceProvider.GetService<IHubProtocol>());
|
||||
var actualProtocol = Assert.IsType<NewtonsoftJsonHubProtocol>(serviceProvider.GetService<IHubProtocol>());
|
||||
Assert.IsType<CamelCasePropertyNamesContractResolver>(actualProtocol.PayloadSerializer.ContractResolver);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddJsonProtocolSetsHubProtocolToJsonWithProvidedOptions()
|
||||
{
|
||||
var serviceProvider = new HubConnectionBuilder().AddJsonProtocol(options =>
|
||||
var serviceProvider = new HubConnectionBuilder().AddNewtonsoftJsonProtocol(options =>
|
||||
{
|
||||
options.PayloadSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
|
|
@ -44,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
};
|
||||
}).Services.BuildServiceProvider();
|
||||
|
||||
var actualProtocol = Assert.IsType<JsonHubProtocol>(serviceProvider.GetService<IHubProtocol>());
|
||||
var actualProtocol = Assert.IsType<NewtonsoftJsonHubProtocol>(serviceProvider.GetService<IHubProtocol>());
|
||||
Assert.Equal("JUST A TEST", actualProtocol.PayloadSerializer.DateFormatString);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
|
||||
var expectedOutput = Frame(testData.Json);
|
||||
|
||||
var protocolOptions = new JsonHubProtocolOptions
|
||||
var protocolOptions = new NewtonsoftJsonHubProtocolOptions
|
||||
{
|
||||
PayloadSerializerSettings = new JsonSerializerSettings()
|
||||
{
|
||||
|
|
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
}
|
||||
};
|
||||
|
||||
var protocol = new JsonHubProtocol(Options.Create(protocolOptions));
|
||||
var protocol = new NewtonsoftJsonHubProtocol(Options.Create(protocolOptions));
|
||||
|
||||
var writer = MemoryBufferWriter.Get();
|
||||
try
|
||||
|
|
@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
|
||||
var input = Frame(testData.Json);
|
||||
|
||||
var protocolOptions = new JsonHubProtocolOptions
|
||||
var protocolOptions = new NewtonsoftJsonHubProtocolOptions
|
||||
{
|
||||
PayloadSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
|
|
@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
};
|
||||
|
||||
var binder = new TestBinder(testData.Message);
|
||||
var protocol = new JsonHubProtocol(Options.Create(protocolOptions));
|
||||
var protocol = new NewtonsoftJsonHubProtocol(Options.Create(protocolOptions));
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(input));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
input = Frame(input);
|
||||
|
||||
var binder = new TestBinder(Array.Empty<Type>(), typeof(object));
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(input));
|
||||
var ex = Assert.Throws<InvalidDataException>(() => protocol.TryParseMessage(ref data, binder, out var _));
|
||||
Assert.Equal(expectedMessage, ex.Message);
|
||||
|
|
@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
var input = Frame(testData.Json);
|
||||
|
||||
var binder = new TestBinder(testData.Message);
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(input));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
|
||||
|
|
@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
input = Frame(input);
|
||||
|
||||
var binder = new TestBinder(paramTypes: new[] { typeof(int), typeof(string) }, returnType: typeof(bool));
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(input));
|
||||
Assert.True(protocol.TryParseMessage(ref data, binder, out var message));
|
||||
Assert.NotNull(message);
|
||||
|
|
@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
input = Frame(input);
|
||||
|
||||
var binder = new TestBinder(paramTypes: new[] { typeof(int), typeof(string) }, returnType: typeof(bool));
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(input));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
var bindingFailure = Assert.IsType<InvocationBindingFailureMessage>(message);
|
||||
|
|
@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
public void DateTimeArgumentPreservesUtcKind(string input)
|
||||
{
|
||||
var binder = new TestBinder(new[] { typeof(DateTime) });
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(Frame(input)));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
var invocationMessage = Assert.IsType<InvocationMessage>(message);
|
||||
|
|
@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
public void DateTimeReturnValuePreservesUtcKind(string input)
|
||||
{
|
||||
var binder = new TestBinder(typeof(DateTime));
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(Frame(input)));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
var invocationMessage = Assert.IsType<CompletionMessage>(message);
|
||||
|
|
@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
|
|||
public void ReadToEndOfArgumentArrayOnError()
|
||||
{
|
||||
var binder = new TestBinder(new[] { typeof(string) });
|
||||
var protocol = new JsonHubProtocol();
|
||||
var protocol = new NewtonsoftJsonHubProtocol();
|
||||
var data = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(Frame("{'type':1,'invocationId':'42','target':'foo','arguments':[[],{'target':'foo2'}]}")));
|
||||
protocol.TryParseMessage(ref data, binder, out var message);
|
||||
var bindingFailure = Assert.IsType<InvocationBindingFailureMessage>(message);
|
||||
|
|
|
|||
|
|
@ -22,17 +22,17 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
|
|||
public string TestProperty { get; set; }
|
||||
}
|
||||
|
||||
private RedisHubLifetimeManager<MyHub> CreateLifetimeManager(TestRedisServer server, MessagePackHubProtocolOptions messagePackOptions = null, JsonHubProtocolOptions jsonOptions = null)
|
||||
private RedisHubLifetimeManager<MyHub> CreateLifetimeManager(TestRedisServer server, MessagePackHubProtocolOptions messagePackOptions = null, NewtonsoftJsonHubProtocolOptions jsonOptions = null)
|
||||
{
|
||||
var options = new RedisOptions() { ConnectionFactory = async (t) => await Task.FromResult(new TestConnectionMultiplexer(server)) };
|
||||
messagePackOptions = messagePackOptions ?? new MessagePackHubProtocolOptions();
|
||||
jsonOptions = jsonOptions ?? new JsonHubProtocolOptions();
|
||||
jsonOptions = jsonOptions ?? new NewtonsoftJsonHubProtocolOptions();
|
||||
return new RedisHubLifetimeManager<MyHub>(
|
||||
NullLogger<RedisHubLifetimeManager<MyHub>>.Instance,
|
||||
Options.Create(options),
|
||||
new DefaultHubProtocolResolver(new IHubProtocol[]
|
||||
{
|
||||
new JsonHubProtocol(Options.Create(jsonOptions)),
|
||||
new NewtonsoftJsonHubProtocol(Options.Create(jsonOptions)),
|
||||
new MessagePackHubProtocol(Options.Create(messagePackOptions)),
|
||||
}, NullLogger<DefaultHubProtocolResolver>.Instance));
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
|
|||
|
||||
var messagePackOptions = new MessagePackHubProtocolOptions();
|
||||
|
||||
var jsonOptions = new JsonHubProtocolOptions();
|
||||
var jsonOptions = new NewtonsoftJsonHubProtocolOptions();
|
||||
jsonOptions.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
||||
|
||||
using (var client1 = new TestClient())
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
return new HubConnectionContext(connection, TimeSpan.FromSeconds(15), NullLoggerFactory.Instance)
|
||||
{
|
||||
Protocol = protocol ?? new JsonHubProtocol(),
|
||||
Protocol = protocol ?? new NewtonsoftJsonHubProtocol(),
|
||||
UserIdentifier = userIdentifier,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -11,19 +11,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
public static class HubProtocolHelpers
|
||||
{
|
||||
private static readonly IHubProtocol JsonHubProtocol = new JsonHubProtocol();
|
||||
private static readonly IHubProtocol NewtonsoftJsonHubProtocol = new NewtonsoftJsonHubProtocol();
|
||||
|
||||
private static readonly IHubProtocol MessagePackHubProtocol = new MessagePackHubProtocol();
|
||||
|
||||
public static readonly List<string> AllProtocolNames = new List<string>
|
||||
{
|
||||
JsonHubProtocol.Name,
|
||||
NewtonsoftJsonHubProtocol.Name,
|
||||
MessagePackHubProtocol.Name
|
||||
};
|
||||
|
||||
public static readonly IList<IHubProtocol> AllProtocols = new List<IHubProtocol>()
|
||||
{
|
||||
JsonHubProtocol,
|
||||
NewtonsoftJsonHubProtocol,
|
||||
MessagePackHubProtocol
|
||||
};
|
||||
|
||||
|
|
@ -38,4 +38,4 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
return protocol;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
Connection.User = new ClaimsPrincipal(new ClaimsIdentity(claims));
|
||||
Connection.Items["ConnectedTask"] = new TaskCompletionSource<bool>();
|
||||
|
||||
_protocol = protocol ?? new JsonHubProtocol();
|
||||
_protocol = protocol ?? new NewtonsoftJsonHubProtocol();
|
||||
_invocationBinder = invocationBinder ?? new DefaultInvocationBinder();
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
|
|
|
|||
|
|
@ -1842,7 +1842,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client1 = new TestClient(protocol: new JsonHubProtocol()))
|
||||
using (var client1 = new TestClient(protocol: new NewtonsoftJsonHubProtocol()))
|
||||
using (var client2 = new TestClient(protocol: new MessagePackHubProtocol()))
|
||||
{
|
||||
var firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler);
|
||||
|
|
@ -1973,7 +1973,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
services
|
||||
.AddSignalR()
|
||||
.AddJsonProtocol(o =>
|
||||
.AddNewtonsoftJsonProtocol(o =>
|
||||
{
|
||||
o.PayloadSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
|
|
@ -2237,7 +2237,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
await client.Connected.OrTimeout();
|
||||
|
|
@ -2266,7 +2266,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
options.KeepAliveInterval = TimeSpan.FromMilliseconds(100)), LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
|
||||
|
|
@ -2310,7 +2310,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
options.KeepAliveInterval = TimeSpan.FromMilliseconds(100)), LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
await client.Connected.OrTimeout();
|
||||
|
|
@ -2371,7 +2371,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
options.ClientTimeoutInterval = TimeSpan.FromMilliseconds(100)), LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
await client.Connected.OrTimeout();
|
||||
|
|
@ -2397,7 +2397,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
options.ClientTimeoutInterval = TimeSpan.FromMilliseconds(100)), LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
await client.Connected.OrTimeout();
|
||||
|
|
@ -2424,7 +2424,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
options.ClientTimeoutInterval = TimeSpan.FromMilliseconds(300)), LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
await client.Connected.OrTimeout();
|
||||
|
|
@ -2450,7 +2450,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
|
||||
|
|
@ -2493,7 +2493,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}, LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<OnConnectedThrowsHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
|
||||
|
|
@ -2522,7 +2522,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<StreamingHub>>();
|
||||
|
||||
using (var client = new TestClient(new JsonHubProtocol()))
|
||||
using (var client = new TestClient(new NewtonsoftJsonHubProtocol()))
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler).OrTimeout();
|
||||
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ namespace Microsoft.AspNetCore.SignalR.Common.Protocol.Tests
|
|||
public void RegisteringMultipleHubProtocolsFails()
|
||||
{
|
||||
var exception = Assert.Throws<InvalidOperationException>(() => new DefaultHubProtocolResolver(new[] {
|
||||
new JsonHubProtocol(),
|
||||
new JsonHubProtocol()
|
||||
new NewtonsoftJsonHubProtocol(),
|
||||
new NewtonsoftJsonHubProtocol()
|
||||
}, NullLogger<DefaultHubProtocolResolver>.Instance));
|
||||
|
||||
Assert.Equal($"Multiple Hub Protocols with the name 'json' were registered.", exception.Message);
|
||||
|
|
|
|||
Loading…
Reference in New Issue