From 0b36f8c939f1333c766f964c627b03533f80d5cd Mon Sep 17 00:00:00 2001 From: Geo Date: Tue, 25 Aug 2015 13:58:28 -0500 Subject: [PATCH] Update to Unit Testing --- .../Properties/Resources.Designer.cs | 11 ++++++++++- .../Properties/Resources.resx | 3 +++ .../Unosquare.Labs.EmbedIO.Tests.csproj | 1 + .../WebSocketsModuleTest.cs | 17 ++++++++++------- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.Designer.cs b/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.Designer.cs index 587da108d..9891a1016 100644 --- a/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.Designer.cs +++ b/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -87,5 +87,14 @@ internal static string ServerAddress { return ResourceManager.GetString("ServerAddress", resourceCulture); } } + + /// + /// Looks up a localized string similar to ws://localhost:7778/. + /// + internal static string WsServerAddress { + get { + return ResourceManager.GetString("WsServerAddress", resourceCulture); + } + } } } diff --git a/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.resx b/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.resx index fc6d4bc90..c7eaf9757 100644 --- a/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.resx +++ b/Unosquare.Labs.EmbedIO.Tests/Properties/Resources.resx @@ -124,4 +124,7 @@ http://localhost:7777/ + + ws://localhost:7778/ + \ No newline at end of file diff --git a/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj b/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj index 991953c1b..26ebf4483 100644 --- a/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj +++ b/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj @@ -86,6 +86,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer diff --git a/Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs b/Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs index 791f51b73..e1239fc05 100644 --- a/Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs +++ b/Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs @@ -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(), "WebServer has WebSocketsModule"); Assert.AreEqual(WebServer.Module().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"); @@ -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(); + } } } \ No newline at end of file