Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am zbartl on github.
  • I am zbartl (https://keybase.io/zbartl) on keybase.
  • I have a public key whose fingerprint is 72AC C158 9B5D F9C4 2D8E 0748 23DF C192 DB7F 8740

To claim this, I am signing this object:

public class TestServerFixture
{
...
public TestServerFixture()
{
var builder = new WebHostBuilder()
.UseStartup(typeof(TestServerStartup));
...
}
}
@zbartl
zbartl / test2_0.cs
Last active June 6, 2017 20:55
aspnetcore integration test - test 2.0
[Fact]
public async Task Should_be_able_to_see_secret()
{
var data = new Dictionary<string, string>()
{
{ "email", "test@gmail.com" },
{ "secret", "shh!" }
};
var secretContent = new FormUrlEncodedContent(data);
@zbartl
zbartl / teststartup.cs
Created June 6, 2017 20:34
aspnetcore integration test - startup
public class Startup
{
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseIdentity();
@zbartl
zbartl / middleware.cs
Last active June 6, 2017 20:21
aspnetcore integration test - middleware
public class AuthenticatedTestRequestMiddleware
{
public const string TestingCookieAuthentication = "TestCookieAuthentication";
public const string TestingHeader = "X-Integration-Testing";
public const string TestingHeaderValue = "abcde-12345";
private readonly RequestDelegate _next;
public AuthenticatedTestRequestMiddleware(RequestDelegate next)
{
@zbartl
zbartl / testserverfixture.cs
Last active June 6, 2017 19:57
aspnetcore integration test - fixture
public class TestServerFixture
{
public TestServer Server { get; private set; }
public HttpClient Client { get; private set; }
public TestServerFixture()
{
var builder = new WebHostBuilder()
.UseStartup(typeof(Startup));
@zbartl
zbartl / test.cs
Last active June 6, 2017 20:55
aspnetcore integration testing - test
[Fact]
public async Task Should_be_able_to_see_secret()
{
var data = new Dictionary<string, string>()
{
{ "email", "test@gmail.com" },
{ "secret", "shh!" }
};
var secretContent = new FormUrlEncodedContent(data);
@zbartl
zbartl / controller.cs
Last active June 6, 2017 19:43
aspnetcore integration testing - controller action
[HttpPost]
[Authorize("Client")]
[Route("secret-thing")]
public async Task<IActionResult> SecretAction(SecretThing.Command command)
{
command.LoginId = _userManager.GetUserId(User);
await _mediator.Send(command);
return RedirectToAction("Classified");
}