Skip to content

Commit abfdf1e

Browse files
committed
Changed WebApp to TestServer (closes #210)
1 parent 21fc3af commit abfdf1e

File tree

6 files changed

+27
-41
lines changed

6 files changed

+27
-41
lines changed

src/MyWebApi.Tests/MyWebApi.Tests.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
3636
<Private>True</Private>
3737
</Reference>
38-
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39-
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
38+
<Reference Include="Microsoft.Owin.Hosting, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
42+
<Reference Include="Microsoft.Owin.Testing, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Microsoft.Owin.Testing.3.0.1\lib\net45\Microsoft.Owin.Testing.dll</HintPath>
4044
<Private>True</Private>
4145
</Reference>
4246
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

src/MyWebApi.Tests/packages.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<package id="Microsoft.AspNet.WebApi.Client" version="5.1.0" targetFramework="net45" />
44
<package id="Microsoft.AspNet.WebApi.Core" version="5.1.0" targetFramework="net45" />
55
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
6-
<package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net45" />
6+
<package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net45" />
7+
<package id="Microsoft.Owin.Testing" version="3.0.1" targetFramework="net45" />
78
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
89
<package id="NUnit" version="2.6.4" targetFramework="net45" />
910
<package id="Owin" version="1.0" targetFramework="net45" />

src/MyWebApi/Builders/Servers/Server.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace MyTested.WebApi.Builders.Servers
88
using System.Web.Http;
99
using Common.Servers;
1010
using Contracts.Servers;
11-
using Microsoft.Owin.Hosting;
1211
using Utilities.Validators;
1312

1413
/// <summary>
@@ -105,13 +104,12 @@ public IServerBuilder Working<TStartup>(int port = OwinTestServer.DefaultPort, s
105104
{
106105
var options = this.GetStartOptions(port, host);
107106
var server = OwinTestServer.CreateNewServer<TStartup>(options);
108-
return new ServerTestBuilder(OwinTestServer.CreateNewClient(options), disposeServer: true, server: server);
107+
return new ServerTestBuilder(server.HttpClient, disposeServer: true, server: server);
109108
}
110109

111-
private StartOptions GetStartOptions(int port, string host)
110+
private string GetStartOptions(int port, string host)
112111
{
113-
var hostWithPort = string.Format("{0}:{1}", host, port);
114-
return new StartOptions(hostWithPort);
112+
return string.Format("{0}:{1}", host, port);
115113
}
116114
}
117115
}

src/MyWebApi/Common/Servers/OwinTestServer.cs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@
55
namespace MyTested.WebApi.Common.Servers
66
{
77
using System;
8-
using System.Linq;
98
using System.Net.Http;
10-
using Microsoft.Owin.Hosting;
9+
using Microsoft.Owin.Testing;
1110

1211
/// <summary>
1312
/// Test server for full OWIN pipeline testing.
1413
/// </summary>
1514
public static class OwinTestServer
1615
{
1716
/// <summary>
18-
/// Default host on which the OWIN server will listen.
17+
/// Default host on which the OWIN server will listen - http://localhost.
1918
/// </summary>
2019
public const string DefaultHost = "http://localhost";
2120

2221
/// <summary>
23-
/// Default port on which the OWIN server will listen.
22+
/// Default port on which the OWIN server will listen - 80.
2423
/// </summary>
25-
public const int DefaultPort = 1234;
24+
public const int DefaultPort = 80;
2625

2726
/// <summary>
2827
/// Gets the global OWIN server used in the testing.
2928
/// </summary>
30-
/// <value>IDisposable instance.</value>
31-
public static IDisposable GlobalServer { get; private set; }
29+
/// <value>Test server instance.</value>
30+
public static TestServer GlobalServer { get; private set; }
3231

3332
/// <summary>
3433
/// Gets the global OWIN client used to send the request.
@@ -52,40 +51,29 @@ public static bool GlobalIsStarted
5251
/// Creates new OWIN server.
5352
/// </summary>
5453
/// <typeparam name="TStartup">OWIN startup class to use.</typeparam>
55-
/// <param name="options">Start options to use for the requests.</param>
56-
/// <returns>IDisposable OWIN server.</returns>
57-
public static IDisposable CreateNewServer<TStartup>(StartOptions options)
54+
/// <param name="baseAddress">Base address to use for the requests.</param>
55+
/// <returns>OWIN test server.</returns>
56+
public static TestServer CreateNewServer<TStartup>(string baseAddress)
5857
{
59-
return WebApp.Start<TStartup>(options);
60-
}
61-
62-
/// <summary>
63-
/// Creates new OWIN client for the server.
64-
/// </summary>
65-
/// <param name="options">Start options to use for the requests.</param>
66-
/// <returns>HttpClient instance.</returns>
67-
public static HttpClient CreateNewClient(StartOptions options)
68-
{
69-
return new HttpClient
70-
{
71-
BaseAddress = new Uri(options.Urls.First())
72-
};
58+
var server = TestServer.Create<TStartup>();
59+
server.BaseAddress = new Uri(baseAddress);
60+
return server;
7361
}
7462

7563
/// <summary>
7664
/// Starts singleton global instance of the OWIN server.
7765
/// </summary>
7866
/// <typeparam name="TStartup">OWIN startup class to use.</typeparam>
79-
/// <param name="options">Start options to use for the requests.</param>
80-
public static void StartGlobal<TStartup>(StartOptions options)
67+
/// <param name="baseAddress">Base address to use for the requests.</param>
68+
public static void StartGlobal<TStartup>(string baseAddress)
8169
{
8270
if (GlobalIsStarted)
8371
{
8472
StopGlobal();
8573
}
8674

87-
GlobalServer = CreateNewServer<TStartup>(options);
88-
GlobalClient = CreateNewClient(options);
75+
GlobalServer = CreateNewServer<TStartup>(baseAddress);
76+
GlobalClient = GlobalServer.HttpClient;
8977
}
9078

9179
/// <summary>

src/MyWebApi/MyWebApi.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
4343
<Private>True</Private>
4444
</Reference>
45-
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46-
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
47-
<Private>True</Private>
48-
</Reference>
4945
<Reference Include="Microsoft.Owin.Hosting, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5046
<HintPath>..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
5147
<Private>True</Private>

src/MyWebApi/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<package id="Microsoft.AspNet.WebApi.Client" version="5.1.0" targetFramework="net45" />
44
<package id="Microsoft.AspNet.WebApi.Core" version="5.1.0" targetFramework="net45" />
55
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
6-
<package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net45" />
76
<package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net45" />
87
<package id="Microsoft.Owin.Testing" version="3.0.1" targetFramework="net45" />
98
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />

0 commit comments

Comments
 (0)