![]() ![]() SagaTests.Should_Delay_Publish_Of_Scheduled_Event_Using_ActiveMq() line 187 SagaTests.Should_Delay_Publish_Of_Scheduled_Event_Using_ActiveMq() line 168 Checks to verify that the IScheduledSagaEvent has been published/consumedĪssert.That(saga.CurrentState, Is.EqualTo(nameof(MyStateMachine.ScheduledEventReceived))) Īssert.That(saga.ScheduledSagaEventTokenId, Is.Null) Wait long enough for the delayed IScheduledSagaEvent to get published and consumedĪwait Task.Delay(Config.scheduleDelayMillis * Config.testScheduleSleepFactor) Checks to verify that the IScheduledSagaEvent has been scheduled, but not published/consumed yetĪssert.That(saga.CurrentState, Is.EqualTo(nameof(MyStateMachine.AwaitingScheduledEvent))) // <- Line 166 that failsĪssert.That(saga.ScheduledSagaEventTokenId, Is.Not.Null) Must wait a little bit to give MassTransit a chance to publish and consume the IInitialSagaEvent using ActiveMqĪwait Task.Delay(Config.scheduleDelayMillis / Config.testScheduleSleepFactor) Īssert.That(sagaRepo.Count, Is.EqualTo(1)) Public interface IInitialSagaEvent : CorrelatedBy ) Public const int testScheduleSleepFactor = 5 Public const int scheduleDelayMillis = 2000 I don't need to test what happens after the publish at this level since it's an out of process operation, so this gets the registration job done to make my DI happy. So the in memory db doesn't seem like it has a way to register the IPublishEndpoint like it can for consumers: _provider = services.AddMassTransitInMemoryTestHarness(cfg =>īut what i was able to do was just use Moq to add a mock of it. _provider = services.BuildServiceProvider() Consumer Registration - Do Not Delete Comment So the below will work, but it won't let you test anything against the harness from a publishing perspective, which is obviously not ideal, if you set up your registration like so, it should fly now: services.AddMassTransitInMemoryTestHarness(cfg => I am thinking I could spin up a docker container with RMQ in it and just use that for my tests, but it would be nice if I could use the in memory harness for performance and simplicity.Īre there any thoughts on how I should be handling this? var bus = _provider.GetRequiredService() I've tried bringing in something like this with various flavors and no avail. RecipeCreated.Should().BeEquivalentTo(fakeRecipeOne, options =>īut when the MediatR command includes the MT publish, the tests fail: -> System.InvalidOperationException : Unable to resolve service for type 'MassTransit.IPublishEndpoint' while attempting to activate '.AddRecipe+Handler'.Īgain, this MediatR command works fine when running the actual app against RMQ, but it would seem that the in memory harnessĭoesn't bring in the bus to properly inject IPublishEndpoint RecipeReturned.Should().BeEquivalentTo(fakeRecipeOne, options => Var recipeCreated = await ExecuteDbContextAsync(db => db.Recipes.SingleOrDefaultAsync()) ![]() Var recipeReturned = await SendAsync(command) Var command = new AddRecipe.AddRecipeCommand(fakeRecipeOne) Var fakeRecipeOne = new FakeRecipeForCreationDto. Public async Task can_add_new_recipe_to_db() I have a test that looks like this and passed before injecting IPublishEndpoint: FirstOrDefaultAsync(r => r.Id = recipe.Id) ![]() Var recipe = _mapper.Map (request.RecipeToAdd) Public async Task Handle(AddRecipeCommand request, CancellationToken cancellationToken) Public Handler(RecipesDbContext db, IMapper mapper, IPublishEndpoint publishEndpoint) Private readonly IPublishEndpoint _publishEndpoint I also have a MediatR handlers that might look something like this: public class Handler : IRequestHandler _harness = _provider.GetRequiredService() _provider = services.AddMassTransitInMemoryTestHarness(cfg => MassTransit Setup - Do Not Delete Comment ![]() SetBasePath(Directory.GetCurrentDirectory()) Var dockerConnectionString = DockerDatabaseUtilities.GetSqlConnectionString(dockerDbPort.ToString()) Var dockerDbPort = await DockerDatabaseUtilities.EnsureDockerStartedAndGetPortPortAsync() I have an NUnit Test Fixture that sets up my in memory harness like so, just like the docs I am able to integrate it into my commands just fine, but I'm running into issues when testing with the InMemoryHarness during my integration tests. I am working on integrating MT into some of them to publish messages to RMQ for various purposes. So I have an existing web api that uses MediatR commands. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |