Protected override void ConfigureWebHost(IWebHostBuilder builder) public class CustomWebApplicationFactory : WebApplicationFactory Services.AddSingleton(provider => provider.GetRequiredService()) Ī MassTransit config defined during Startup could be replaced with a new configuration with custom WebApplicationFactory by removing services from MassTransit namespace, e.g. Add the hosted service that starts and stops the BusControl. HostConfig.Heartbeat(rabbitMQConfig.Heartbeat) HostConfig.Password(rabbitMQConfig.Password) HostConfig.Username(rabbitMQConfig.Username) Var rabbitMQConfig = rabbitMqConfig.GetSection(ServiceBusOptionsKey).Get() Get the json configuration and use it to setup connection to RabbitMQ. AddJsonFile("/app/configs/service-bus.json", optional: false, reloadOnChange: true) Var rabbitMqConfig = new ConfigurationBuilder() Public static IServiceCollection AddServiceBus(this IServiceCollection services, Action configurator) Not sure how to use them together and what they do.īy the way, in my ASP.NET Core app, I have a reusable extension method setup like the code below to hook me up to RabbitMQ on startup. Not sure if InMemoryTestFixture, BusTestFixture, or BusTestHarness is the solution to my problem. However, I am wondering if there's already a better way to register the IBus into my container without mocking it inside my test. WebHostBuilder.ConfigureTestServices(services =>īut there are gaps in RawRabbit right now that made me decide to move over to MassTransit. Public static IWebHostBuilder ConfigureTestServiceBus(this IWebHostBuilder webHostBuilder) ![]() ![]() Within the WebApplicationFactory.CreateWebHostBuilder() I call this extension method to add my mocked IBusClient instance like so /// I used RawRabbit before and it was easy enough for me to mock the IBusClient and add it to the DI container as a singleton. I have an ASP.NET Core web app and test setup using WebApplicationFactory to test my controller actions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |