-
-
Save alistair/154653e12f313fbbf655 to your computer and use it in GitHub Desktop.
This file contains 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
public abstract class StartupBase | |
{ | |
public virtual void ConfigureService(IServiceCollection services) | |
{ | |
// Standard registrations | |
ConfigureEntityFramework(services); | |
} | |
public abstract void ConfigureEntityFramework(IServiceCollection services); | |
public IConfiguration Configuration { get; set; } | |
} | |
public class Startup : StartupBase | |
{ | |
public override void ConfigureEntityFramework(IServiceCollection services) | |
{ | |
services.AddEntityFramework() | |
.AddNpgsql() | |
.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(Configuration["Data:DefaultConnection:ConnectionString"])); | |
} | |
} | |
public class TestStartup : StartupBase | |
{ | |
public override void ConfigureEntityFramework(IServiceCollection services) | |
{ | |
services.AddEntityFramework() | |
.AddInMemoryDatabase() | |
.AddDbContext<ApplicationDbContext>(options => options.UseInMemoryDatabase()); | |
} | |
} |
This file contains 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
[Fact] | |
public async Task Can_Setup_Whole_Server() { | |
var server = new TestServer( | |
TestServer.CreateBuilder() | |
).UseStartup<TestStartup>()); | |
await Task.Yield(); | |
server.CreateClient().PostAsync("/api/children", | |
new System.Net.Http.StringContent("{ Name: 'Alistair', FamilyName: 'B', Sex: 'Male', DateOfBirth: '2015-01-01' }", | |
new System.Text.UTF8Encoding(), "application/json")).Wait(); | |
var response = await server.CreateClient().GetAsync("/api/children"); | |
var body = await response.Content.ReadAsStringAsync(); | |
body.Should().Contain("A"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment