Skip to content

Commit

Permalink
Update to Unit Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Aug 25, 2015
1 parent 67ba2b7 commit 0b36f8c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
11 changes: 10 additions & 1 deletion Unosquare.Labs.EmbedIO.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Unosquare.Labs.EmbedIO.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@
<data name="ServerAddress" xml:space="preserve">
<value>http://localhost:7777/</value>
</data>
<data name="WsServerAddress" xml:space="preserve">
<value>ws://localhost:7778/</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 10 additions & 7 deletions Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@ public class WebSocketsModuleTest
[SetUp]
public void Init()
{
WebServer = new WebServer(Resources.ServerAddress, Logger).WithWebSocket(typeof (TestWebSocket).Assembly);
WebServer = new WebServer(Resources.WsServerAddress.Replace("ws", "http"), Logger).WithWebSocket(typeof (TestWebSocket).Assembly);
WebServer.RunAsync();
}

[Test]
public void TestWebSocket()
public async void TestConnectWebSocket()
{
Assert.IsNotNull(WebServer.Module<WebSocketsModule>(), "WebServer has WebSocketsModule");

Assert.AreEqual(WebServer.Module<WebSocketsModule>().Handlers.Count, 1, "WebSocketModule has one handler");
}

[Test]
public async void TestConnectWebSocket()
{
var clientSocket = new ClientWebSocket();
var ct = new CancellationTokenSource();
await clientSocket.ConnectAsync(new Uri(Resources.ServerAddress.Replace("http", "ws") + "/test"), ct.Token);
await clientSocket.ConnectAsync(new Uri(Resources.WsServerAddress + "/test"), ct.Token);

Assert.AreEqual(clientSocket.State, WebSocketState.Open, "Connection is open");

Expand All @@ -47,5 +43,12 @@ public async void TestConnectWebSocket()
Assert.IsTrue(result.EndOfMessage);
Assert.IsTrue(System.Text.Encoding.UTF8.GetString(buffer.Array).TrimEnd((char) 0) == "WELCOME");
}

[TearDown]
public void Kill()
{
Thread.Sleep(TimeSpan.FromSeconds(1));
WebServer.Dispose();
}
}
}

0 comments on commit 0b36f8c

Please sign in to comment.