public void Setup() { TestHostBuilder.ConfigureServices(services => { services.AddScoped <FakeService>(); services.AddMvcCore(setup => setup.EnableEndpointRouting = false) .AddApplicationPart(typeof(HomeController).Assembly); }); TestHostBuilder.Configure(builder => { builder.UseMvcWithDefaultRoute(); builder.UseResponseCaching(); // adds a middleware that will return a custom response from a designated request path builder.Use(async(context, next) => { await next.Invoke(); if (context.Request.Path.Value.StartsWith("/dummy")) { context.Response.Clear(); await context.Response.WriteAsync("Hello from the dummy middleware!"); } }); }); TestSetup(); }
public async Task UnsignedRequestShouldGetUnauthorized() { using var host = await TestHostBuilder.BuildAsync().ConfigureAwait(false); var client = host.GetTestClient(); var response = await client.GetAsync(new Uri("https://example.com/Test/Authorized")).ConfigureAwait(false); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); Assert.Contains(HawkConstants.AuthenticationScheme, response.Headers.WwwAuthenticate.ToString(), StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// /// </summary> /// <typeparam name="TMessageHandler"></typeparam> /// <param name="configSectionName"></param> /// <param name="httpHandlerMode"></param> public void AssemblySetup <TMessageHandler>(string configSectionName, HttpHandlerMode httpHandlerMode) where TMessageHandler : DelegatingHandler { TestHostBuilder.AddBlazorEssentials <TConfiguration, TAppState, TMessageHandler>(configSectionName, httpHandlerMode); TestHostBuilder.ConfigureServices((builder, services) => { services.AddSingleton <NavigationManager, TestableNavigationManager>(); }); base.AssemblySetup(); }
/// <summary> /// /// </summary> /// <typeparam name="TMessageHandler"></typeparam> /// <param name="configSectionName"></param> /// <param name="httpHandlerMode"></param> public void AssemblySetup <TMessageHandler>(string configSectionName, HttpHandlerMode httpHandlerMode) where TMessageHandler : DelegatingHandler { TestHostBuilder.ConfigureServices((builder, services) => { var config = services.AddConfigurationBase <TConfiguration>(builder.Configuration, configSectionName); services.AddAppStateBase <TAppState>(); services.AddHttpClients <TMessageHandler>(config, httpHandlerMode); services.AddSingleton <NavigationManager, TestableNavigationManager>(); }); base.AssemblySetup(); }
public When_a_document_is_activated() { Given(async() => { UseThe(new MemoryEventSource()); SetThe <IDocumentStore>().To(new RavenDocumentStoreBuilder().Build()); countryCode = Guid.NewGuid(); using (var session = The <IDocumentStore>().OpenAsyncSession()) { await session.StoreAsync(new CountryLookupBuilder() .IdentifiedBy(countryCode) .Named("Netherlands") .Build()); await session.StoreAsync(new DocumentCountProjectionBuilder() .WithNumber("123") .InCountry(countryCode) .OfKind("Filming") .Build()); await session.SaveChangesAsync(); } var modules = new ModuleRegistry(new StatisticsModule()); var host = new TestHostBuilder() .Using(The <IDocumentStore>()) .Using(The <MemoryEventSource>()) .WithModules(modules) .Build(); UseThe(host); }); When(async() => { await The <MemoryEventSource>().Write(new StateTransitionedEvent { DocumentNumber = "123", State = "Active" }); }); }
public AuthenticatedGitHubClientTest(ITestOutputHelper outputHelper) { host = TestHostBuilder.CreateHostBuidler() .ConfigureLogging(logging => logging.AddXUnit(outputHelper)) .ConfigureServices((context, services) => { services.AddOctokitCredentials(); }) .Build(); host.Start(); serviceProvider = host.Services; client = new GitHubClient( AssemblyProductHeaderValue.Instance, serviceProvider.GetRequiredService <ICredentialStore>() ); }
protected Given_a_http_controller_talking_to_an_in_memory_event_store() { Given(() => { UseThe(new MemoryEventSource()); SetThe <IDocumentStore>().To(new RavenDocumentStoreBuilder().Build()); var modules = new ModuleRegistry(new StatisticsModule()); var host = new TestHostBuilder() .Using(The <IDocumentStore>()) .Using(The <MemoryEventSource>()) .WithModules(modules) .Build(); UseThe(host); }); }
protected IHost SetupTestHost(bool withInterceptor, EventuateKafkaConsumerConfigurationProperties consumerConfigProperties) { var host = new TestHostBuilder() .SetConnectionString(TestSettings.ConnectionStrings.EventuateTramDbConnection) .SetEventuateDatabaseSchemaName(EventuateDatabaseSchemaName) .SetKafkaBootstrapServers(TestSettings.KafkaBootstrapServers) .SetSubscriberId(_subscriberId) .SetDomainEventHandlersFactory( provider => { var consumer = provider.GetRequiredService <TestEventConsumer>(); return(consumer.DomainEventHandlers(AggregateType12, AggregateType34)); }) .SetConsumerConfigProperties(consumerConfigProperties) .Build <TestEventConsumer>(withInterceptor); host.StartAsync().Wait(); return(host); }
protected Given_a_raven_projector_with_an_in_memory_event_source() { Given(async() => { UseThe(new MemoryEventSource()); SetThe <IDocumentStore>().To(new RavenDocumentStoreBuilder().Build()); var modules = new ModuleRegistry(new StatisticsModule()); var host = new TestHostBuilder() .Using(The <IDocumentStore>()) .Using(The <MemoryEventSource>()) .WithModules(modules) .Build(); UseThe(host); }); }
public async Task SignedGetRequestShouldGetOkResponse() { var signer = new HawkRequestSigner(MockCredentialProvider.Credential); using var host = await TestHostBuilder.BuildAsync().ConfigureAwait(false); var client = host.GetTestClient(); using var message = new HttpRequestMessage { RequestUri = new Uri("https://example.com/Test/Authorized"), Method = HttpMethod.Get }; await signer.SignAsync(message).ConfigureAwait(false); var response = await client.SendAsync(message).ConfigureAwait(false); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Hello World!", await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
public void BlazorBreakdanceTestBase_GetServices_ReturnsServiceOnlyInTestContext() { //RWM: We're not *quite* setting this up properly, because we want to test the state both before and after calling TestSetup(); TestHost.Should().BeNull(); BUnitTestContext.Should().BeNull(); RegisterServices.Should().BeNull(); TestHostBuilder.ConfigureServices((context, services) => services.AddSingleton <DummyService>()); TestSetup(); TestHost.Should().NotBeNull(); BUnitTestContext.Should().NotBeNull(); RegisterServices.Should().BeNull(); BUnitTestContext.Services.Should().HaveCount(13); BUnitTestContext.Services.GetService <DummyService>().Should().BeNull(); #if NET6_0_OR_GREATER TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(34); #endif #if NET5_0 TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(33); #endif TestHost.Services.GetService <DummyService>().Should().NotBeNull(); GetService <DummyService>().Should().NotBeNull(); }
/// <summary> /// Creates a new <see cref="AspNetCoreBreakdanceTestBase"/> instance. /// </summary> /// <remarks>The call to .Configure() with no content is required to get a minimal, empty <see cref="IWebHost"/>.</remarks> public AspNetCoreBreakdanceTestBase() : base() { TestHostBuilder.UseStartup <TStartup>(); }
public void Build() { TestHost = TestHostBuilder.Build(); }