public void GetTestableHttpServer_WithFullConfiguration_CreatesServer() { var server = AspNetCoreTestHelpers.GetTestableHttpServer( services => { services.AddScoped <FakeService>(); }, builder => { builder.ServerFeatures.Set(new FakeFeature()); }, configuration => { configuration.Build(); }); //server.Services.GetAllServiceDescriptors().Should().HaveCount(44); server.Features.Should().Contain(c => c.Key.Name == nameof(FakeFeature)); }
public async Task GetTestableHttpServer_CanGet() { var server = AspNetCoreTestHelpers.GetTestableHttpServer( services => { services.AddMvcCore(setup => setup.EnableEndpointRouting = false) .AddApplicationPart(typeof(HomeController).Assembly); }, builder => { builder.UseMvcWithDefaultRoute(); }); var client = server.CreateClient(); var response = await server.CreateRequest("/").GetAsync(); response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); content.Should().Be("Hello world!"); }
public void GetTestableHttpServer_WithoutConfiguration_ThrowsException() { Action configureService = () => { var server = AspNetCoreTestHelpers.GetTestableHttpServer(); }; configureService.Should().Throw <InvalidOperationException>(); }