Added Sockets.Common and connection level testing (#173)
*Moved IChannelConnection, ChannelConnection, Format and Message to the new Sockets.Common project. * Adding Connection level tests.
This commit is contained in:
parent
b32d3ad4e1
commit
5def499323
|
|
@ -57,6 +57,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Signal
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.SignalR.Client.FunctionalTests", "test\Microsoft.AspNetCore.SignalR.Client.FunctionalTests\Microsoft.AspNetCore.SignalR.Client.FunctionalTests.xproj", "{455B68D2-C5B6-4BF4-A685-964B07AFAAF8}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Sockets.Common", "src\Microsoft.AspNetCore.Sockets.Common\Microsoft.AspNetCore.Sockets.Common.xproj", "{F3EFFD9F-DD85-48A2-9B11-83A133ECC099}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -147,6 +149,10 @@ Global
|
|||
{455B68D2-C5B6-4BF4-A685-964B07AFAAF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{455B68D2-C5B6-4BF4-A685-964B07AFAAF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{455B68D2-C5B6-4BF4-A685-964B07AFAAF8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F3EFFD9F-DD85-48A2-9B11-83A133ECC099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F3EFFD9F-DD85-48A2-9B11-83A133ECC099}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3EFFD9F-DD85-48A2-9B11-83A133ECC099}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F3EFFD9F-DD85-48A2-9B11-83A133ECC099}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -173,5 +179,6 @@ Global
|
|||
{E37324FF-6BAF-4243-BA80-7C024CF5F29D} = {DA69F624-5398-4884-87E4-B816698CDE65}
|
||||
{354335AB-CEE9-4434-A641-78058F6EFE56} = {DA69F624-5398-4884-87E4-B816698CDE65}
|
||||
{455B68D2-C5B6-4BF4-A685-964B07AFAAF8} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
|
||||
{F3EFFD9F-DD85-48A2-9B11-83A133ECC099} = {DA69F624-5398-4884-87E4-B816698CDE65}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using System.Net.Http;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
||||
namespace ClientSample
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ using System;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Channels;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
// 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;
|
||||
using System.IO.Pipelines;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
public struct Message : IDisposable
|
||||
{
|
||||
public Format MessageFormat { get; }
|
||||
public PreservedBuffer Payload { get; }
|
||||
|
||||
public Message(PreservedBuffer payload, Format messageFormat)
|
||||
{
|
||||
MessageFormat = messageFormat;
|
||||
Payload = payload;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Payload.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,14 +18,7 @@
|
|||
"nowarn": [
|
||||
"CS1591"
|
||||
],
|
||||
"xmlDoc": true,
|
||||
"compile": {
|
||||
"include": [
|
||||
"../Microsoft.AspNetCore.Sockets/IChannelConnection.cs",
|
||||
"../Microsoft.AspNetCore.Sockets/Internal/ChannelConnection.cs",
|
||||
"../Microsoft.AspNetCore.Sockets/Format.cs"
|
||||
]
|
||||
}
|
||||
"xmlDoc": true
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
|
|
@ -33,6 +26,7 @@
|
|||
"System.IO.Pipelines": "0.1.0-*",
|
||||
"System.Threading.Tasks.Channels": "0.1.0-*",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.2.0-*",
|
||||
"Microsoft.AspNetCore.Sockets.Common": "1.0.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.2.0-*"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
// 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;
|
||||
using System.Threading.Tasks.Channels;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Internal
|
||||
|
|
@ -12,6 +12,12 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
public Format MessageFormat { get; }
|
||||
public PreservedBuffer Payload { get; }
|
||||
|
||||
public Message(PreservedBuffer payload, Format messageFormat)
|
||||
: this(payload, messageFormat, endOfMessage: true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Message(PreservedBuffer payload, Format messageFormat, bool endOfMessage)
|
||||
{
|
||||
MessageFormat = messageFormat;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>f3effd9f-dd85-48a2-9b11-83a133ecc099</ProjectGuid>
|
||||
<RootNamespace>Microsoft.AspNetCore.Sockets.Common</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// 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.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
[assembly: AssemblyMetadata("Serviceable", "True")]
|
||||
[assembly: NeutralResourcesLanguage("en-us")]
|
||||
[assembly: AssemblyCompany("Microsoft Corporation.")]
|
||||
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
|
||||
[assembly: AssemblyProduct("Microsoft ASP.NET Core")]
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Common primitives for Sockets clients and servers",
|
||||
"packOptions": {
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/aspnet/signalr"
|
||||
},
|
||||
"tags": [
|
||||
"aspnetcore",
|
||||
"signalr"
|
||||
]
|
||||
},
|
||||
"buildOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk",
|
||||
"nowarn": [
|
||||
"CS1591"
|
||||
],
|
||||
"xmlDoc": true
|
||||
},
|
||||
"dependencies": {
|
||||
"System.IO.Pipelines": "0.1.0-*",
|
||||
"NETStandard.Library": "1.6.2-*",
|
||||
"System.Threading.Tasks.Channels": "0.1.0-*"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.3": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,19 +20,18 @@
|
|||
"xmlDoc": true
|
||||
},
|
||||
"dependencies": {
|
||||
"System.Threading.Tasks.Channels": "0.1.0-*",
|
||||
|
||||
"System.Security.Claims": "4.4.0-*",
|
||||
"System.Reflection.TypeExtensions": "4.4.0-*",
|
||||
|
||||
"Microsoft.AspNetCore.Hosting.Abstractions": "1.2.0-*",
|
||||
"Microsoft.AspNetCore.Routing": "1.2.0-*",
|
||||
"Microsoft.AspNetCore.Sockets.Common": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.WebSockets.Internal": "0.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.2.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"NETStandard.Library": "1.6.2-*"
|
||||
"NETStandard.Library": "1.6.2-*",
|
||||
"System.Reflection.TypeExtensions": "4.4.0-*",
|
||||
"System.Security.Claims": "4.4.0-*",
|
||||
"System.Threading.Tasks.Channels": "0.1.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.3": {}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,20 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO.Pipelines;
|
||||
using System.Net.Http;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
|
||||
using ClientConnection = Microsoft.AspNetCore.Sockets.Client.Connection;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
[CollectionDefinition(Name)]
|
||||
|
|
@ -45,5 +52,44 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
await ws.CloseAsync(WebSocketCloseStatus.Empty, "", CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConnectionCanSendAndReceiveMessages()
|
||||
{
|
||||
const string message = "Major Key";
|
||||
var baseUrl = _serverFixture.BaseUrl;
|
||||
var loggerFactory = new LoggerFactory();
|
||||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
var transport = new LongPollingTransport(httpClient, loggerFactory);
|
||||
using (var connection = await ClientConnection.ConnectAsync(new Uri(baseUrl + "/echo"), transport, httpClient, loggerFactory))
|
||||
{
|
||||
await connection.Output.WriteAsync(new Message(
|
||||
ReadableBuffer.Create(Encoding.UTF8.GetBytes(message)).Preserve(),
|
||||
Format.Text));
|
||||
|
||||
var received = await ReceiveMessage(connection).OrTimeout();
|
||||
Assert.Equal(message, received);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string> ReceiveMessage(ClientConnection connection)
|
||||
{
|
||||
Message message;
|
||||
while (await connection.Input.WaitToReadAsync())
|
||||
{
|
||||
if (connection.Input.TryRead(out message))
|
||||
{
|
||||
using (message)
|
||||
{
|
||||
return Encoding.UTF8.GetString(message.Payload.Buffer.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
"Microsoft.AspNetCore.Hosting": "1.2.0-*",
|
||||
"Microsoft.AspNetCore.Sockets": "0.1.0-*",
|
||||
"Microsoft.AspNetCore.SignalR": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.SignalR.Client": "1.0.0-*",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.2.0-*",
|
||||
"Microsoft.Extensions.Logging": "1.2.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Channels;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Moq.Protected;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client.Tests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Sockets.Client": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Sockets.Common": "1.0.0-*",
|
||||
"Microsoft.Extensions.Logging": "1.2.0-*",
|
||||
"dotnet-test-xunit": "2.2.0-*",
|
||||
"Moq": "4.6.36-*",
|
||||
|
|
|
|||
Loading…
Reference in New Issue