-
-
Save jrgcubano/3f61fbdbbb98d795bfbf2adfb23ecb4c to your computer and use it in GitHub Desktop.
Sample Fixture for an owin test server
This file contains hidden or 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
using Microsoft.Owin.Testing; | |
using System; | |
using System.Linq; | |
using System.Net.Http; | |
using Xunit; | |
namespace {Your Project}.Tests.Fixtures { | |
[CollectionDefinition("Test Server")] | |
public class TestServerFixtureCollection : ICollectionFixture<TestServerFixture> { | |
// This class has no code, and is never created. Its purpose is simply | |
// to be the place to apply [CollectionDefinition] and all the | |
// ICollectionFixture<> interfaces. | |
} | |
public class TestServerFixture : IDisposable { | |
bool _disposed = false; | |
public TestServer Server { get; private set; } | |
public TestServerFixture() { | |
Server = TestServer.Create<{your owin startup class here}>(); | |
Server.BaseAddress = new Uri("https://localhost/"); | |
} | |
~TestServerFixture() { | |
Dispose(false); | |
} | |
public HttpClient CreateClient() { | |
return Server.HttpClient; | |
} | |
public void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
protected virtual void Dispose(bool disposing) { | |
if (!disposing || _disposed) { return; } | |
if (Server != null) { | |
Server.Dispose(); | |
Server = null; | |
} | |
_disposed = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment