-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from Azure/dev
Release 1.5.0
- Loading branch information
Showing
14 changed files
with
162 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
test/SignalRServiceExtension.Tests/Config/DependencyInjectionExtensionFacts.cs
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
test/SignalRServiceExtension.Tests/Config/SetNewtonsoftHubProtocolFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Microsoft.AspNetCore.SignalR.Protocol; | ||
using Microsoft.Azure.SignalR.Management; | ||
using Microsoft.Azure.SignalR.Tests.Common; | ||
using Microsoft.Azure.WebJobs.Extensions.SignalRService; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json.Serialization; | ||
using Xunit; | ||
|
||
namespace SignalRServiceExtension.Tests | ||
{ | ||
public class SetNewtonsoftHubProtocolFacts | ||
{ | ||
[Fact] | ||
public void EmptyHubProtocolSetting_DoNothing() | ||
{ | ||
var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); | ||
var services = new ServiceCollection() | ||
.SetHubProtocol(configuration); | ||
Assert.Empty(services); | ||
} | ||
|
||
#if NETCOREAPP2_1 | ||
|
||
[Fact] | ||
public void SetHubProtocol_Throw() | ||
{ | ||
var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); | ||
configuration[Constants.AzureSignalRHubProtocol] = HubProtocol.SystemTextJson.ToString(); | ||
var services = new ServiceCollection(); | ||
Assert.Throws<InvalidOperationException>(() => services.SetHubProtocol(configuration)); | ||
} | ||
|
||
#endif | ||
|
||
#if NETCOREAPP3_1 | ||
|
||
[Fact] | ||
public void SetSystemTextJson_DoNothing() | ||
{ | ||
var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); | ||
configuration[Constants.AzureSignalRHubProtocol] = HubProtocol.SystemTextJson.ToString(); | ||
var services = new ServiceCollection() | ||
.SetHubProtocol(configuration); | ||
Assert.Empty(services); | ||
} | ||
|
||
[Fact] | ||
public async Task SetNewtonsoftPersistent() | ||
{ | ||
var serviceManagerStore = CreateServiceManagerStore(out var configuration); | ||
configuration[Constants.ServiceTransportTypeName] = "Persistent"; | ||
var hubContext = await serviceManagerStore.GetOrAddByConnectionStringKey(Constants.AzureSignalRConnectionStringName).GetAsync("hub") as ServiceHubContextImpl; | ||
var hubProtocol = hubContext.ServiceProvider.GetRequiredService<IHubProtocol>(); | ||
Assert.IsType<NewtonsoftJsonHubProtocol>(hubProtocol); | ||
var newtonsoftOptions = hubContext.ServiceProvider.GetRequiredService<IOptions<NewtonsoftJsonHubProtocolOptions>>(); | ||
Assert.Null(newtonsoftOptions.Value.PayloadSerializerSettings.ContractResolver); | ||
} | ||
|
||
[Fact] | ||
public async Task SetNewtonsoftInTransientModeAsync() | ||
{ | ||
var serviceManagerStore = CreateServiceManagerStore(out var configuration); | ||
var hubContext = await serviceManagerStore.GetOrAddByConnectionStringKey(Constants.AzureSignalRConnectionStringName).GetAsync("hub") as ServiceHubContextImpl; | ||
|
||
var restHubProtocol = hubContext.ServiceProvider.GetRequiredService<IRestHubProtocol>(); | ||
Assert.IsType<NewtonsoftRestHubProtocol>(restHubProtocol); | ||
var newtonsoftOptions = hubContext.ServiceProvider.GetRequiredService<IOptions<NewtonsoftServiceHubProtocolOptions>>(); | ||
Assert.Null(newtonsoftOptions.Value.PayloadSerializerSettings.ContractResolver); | ||
} | ||
|
||
[Fact] | ||
public async Task SetNewtonsoftCamelCaseInTransientModeAsync() | ||
{ | ||
var serviceManagerStore = CreateServiceManagerStore(out var configuration); | ||
configuration["Azure:SignalR:HubProtocol:NewtonsoftJson:CamelCase"] = "true"; | ||
|
||
var hubContext = await serviceManagerStore.GetOrAddByConnectionStringKey(Constants.AzureSignalRConnectionStringName).GetAsync("hub") as ServiceHubContextImpl; | ||
var restHubProtocol = hubContext.ServiceProvider.GetRequiredService<IRestHubProtocol>(); | ||
Assert.IsType<NewtonsoftRestHubProtocol>(restHubProtocol); | ||
var newtonsoftOptions = hubContext.ServiceProvider.GetRequiredService<IOptions<NewtonsoftServiceHubProtocolOptions>>(); | ||
Assert.IsType<CamelCasePropertyNamesContractResolver>(newtonsoftOptions.Value.PayloadSerializerSettings.ContractResolver); | ||
} | ||
|
||
[Fact] | ||
public async Task SetNewtonsoftCamelCaseInPersistentModeAsync() | ||
{ | ||
var serviceManagerStore = CreateServiceManagerStore(out var configuration); | ||
configuration["Azure:SignalR:HubProtocol:NewtonsoftJson:CamelCase"] = "true"; | ||
configuration[Constants.ServiceTransportTypeName] = "Persistent"; | ||
|
||
var hubContext = await serviceManagerStore.GetOrAddByConnectionStringKey(Constants.AzureSignalRConnectionStringName).GetAsync("hub") as ServiceHubContextImpl; | ||
var hubProtocol = hubContext.ServiceProvider.GetRequiredService<IHubProtocol>(); | ||
Assert.IsType<NewtonsoftJsonHubProtocol>(hubProtocol); | ||
var newtonsoftOptions = hubContext.ServiceProvider.GetRequiredService<IOptions<NewtonsoftJsonHubProtocolOptions>>(); | ||
Assert.IsType<CamelCasePropertyNamesContractResolver>(newtonsoftOptions.Value.PayloadSerializerSettings.ContractResolver); | ||
} | ||
|
||
private ServiceManagerStore CreateServiceManagerStore(out IConfiguration configuration) | ||
{ | ||
configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); | ||
configuration[Constants.AzureSignalRHubProtocol] = HubProtocol.NewtonsoftJson.ToString(); | ||
configuration[Constants.AzureSignalRConnectionStringName] = FakeEndpointUtils.GetFakeConnectionString(1).Single(); | ||
|
||
return new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters