Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test firing events, so we don't miss them in the dependent applications. Affects #491
- Loading branch information
Showing
6 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...er.Connectors.WebsocketServer.Test/Buttplug.Server.Connectors.WebsocketServer.Test.csproj
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,99 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" /> | ||
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{9A3C4577-1EB0-4C7A-8B3B-490672AFB074}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Buttplug.Server.Connectors.WebsocketServer.Test</RootNamespace> | ||
<AssemblyName>Buttplug.Server.Connectors.WebsocketServer.Test</AssemblyName> | ||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="FluentAssertions, Version=5.4.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\FluentAssertions.5.4.2\lib\net47\FluentAssertions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="NJsonSchema, Version=9.11.0.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\NJsonSchema.9.11.0\lib\net45\NJsonSchema.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Net" /> | ||
<Reference Include="System.Runtime.Serialization" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="WebsocketServerTest.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Buttplug.Client.Connectors.WebsocketConnector\Buttplug.Client.Connectors.WebsocketConnector.csproj"> | ||
<Project>{0d71ed9e-7dd6-4b64-a7c9-be38759ac6ea}</Project> | ||
<Name>Buttplug.Client.Connectors.WebsocketConnector</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Buttplug.Client\Buttplug.Client.csproj"> | ||
<Project>{1592d845-8fe5-4f33-a665-d7675c9aaee4}</Project> | ||
<Name>Buttplug.Client</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Buttplug.Core\Buttplug.Core.csproj"> | ||
<Project>{fc4af8fe-8c21-4e07-8d24-7fb7791149d0}</Project> | ||
<Name>Buttplug.Core</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Buttplug.Server.Connectors.WebsocketServer\Buttplug.Server.Connectors.WebsocketServer.csproj"> | ||
<Project>{048d9ed5-6ad4-4bf7-a372-709f795d70fd}</Project> | ||
<Name>Buttplug.Server.Connectors.WebsocketServer</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Buttplug.Server\Buttplug.Server.csproj"> | ||
<Project>{23d9ec18-2dba-4149-a951-b84786d4bfa6}</Project> | ||
<Name>Buttplug.Server</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" /> | ||
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props'))" /> | ||
</Target> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
Buttplug.Server.Connectors.WebsocketServer.Test/Properties/AssemblyInfo.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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Buttplug.Server.Connectors.WebsocketServer.Test")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Buttplug.Server.Connectors.WebsocketServer.Test")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("9a3c4577-1eb0-4c7a-8b3b-490672afb074")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
80 changes: 80 additions & 0 deletions
80
Buttplug.Server.Connectors.WebsocketServer.Test/WebsocketServerTest.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,80 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Buttplug.Client; | ||
using Buttplug.Client.Connectors.WebsocketConnector; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Buttplug.Server.Connectors.WebsocketServer.Test | ||
{ | ||
[TestFixture] | ||
public class WebsocketServerTest | ||
{ | ||
private ButtplugClient _client; | ||
private ButtplugWebsocketConnector _connector; | ||
private ButtplugWebsocketServer _server; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_connector = new ButtplugWebsocketConnector(new Uri("ws://localhost:12345")); | ||
_client = new ButtplugClient("Test Client", _connector); | ||
_server = new ButtplugWebsocketServer(); | ||
} | ||
|
||
[TearDown] | ||
public async Task TearDown() | ||
{ | ||
await _server.StopServer(); | ||
} | ||
|
||
// Test that ConnectionAccepted is fired after client finished handshake. | ||
[Test] | ||
public async Task TestConnectionAcceptedEvent() | ||
{ | ||
// There's a good chance the server will fire ConnectionAccepted while we're calling | ||
// ConnectAsync(), but using a semaphor means we'll pass even if its out of sync. | ||
var sem = new SemaphoreSlim(0, 1); | ||
_server.ConnectionAccepted += (aObject, aEventArgs) => { sem.Release(); }; | ||
await _server.StartServer(() => new ButtplugServer("Test Server", 0)); | ||
sem.CurrentCount.Should().Be(0); | ||
await _client.ConnectAsync(); | ||
await sem.WaitAsync(); | ||
} | ||
|
||
// Test that ConnectionClosed is fired when client closes connection. | ||
[Test] | ||
public async Task TestConnectionClosedEvent() | ||
{ | ||
// We won't get ConnectionClosed until the websocket is completely closed, which | ||
// sometimes happens after DisconnectionAsync() completes. Use the semaphore here to wait | ||
// on that. | ||
var sem = new SemaphoreSlim(0, 1); | ||
_server.ConnectionClosed += (aObject, aEventArgs) => { sem.Release(); }; | ||
await _server.StartServer(() => new ButtplugServer("Test Server", 0)); | ||
await _client.ConnectAsync(); | ||
// Make sure nothing got fired after connect | ||
sem.CurrentCount.Should().Be(0); | ||
await _client.DisconnectAsync(); | ||
await sem.WaitAsync(); | ||
} | ||
|
||
/* | ||
// If a client does not respond with RequestServerInfo in a specified amount of time, a | ||
// connection should be dropped. | ||
[Test] | ||
public async Task TestDropConnectionOnRequestServerInfoTimeout() | ||
{ | ||
} | ||
// Test Ping Disconnect | ||
[Test] | ||
public async Task TestDropConnectionOnPingTimeout() | ||
{ | ||
} | ||
*/ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Buttplug.Server.Connectors.WebsocketServer.Test/app.config
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
8 changes: 8 additions & 0 deletions
8
Buttplug.Server.Connectors.WebsocketServer.Test/packages.config
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FluentAssertions" version="5.4.2" targetFramework="net47" /> | ||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net47" /> | ||
<package id="NJsonSchema" version="9.11.0" targetFramework="net47" /> | ||
<package id="NUnit" version="3.10.1" targetFramework="net47" /> | ||
<package id="NUnit3TestAdapter" version="3.10.0" targetFramework="net47" /> | ||
</packages> |
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