amantinband / clean-architecture

The ultimate clean architecture template for .NET applications 💪
MIT License
1.4k stars 221 forks source link

[Question] Eventual Consistency in integration tests #34

Open Melethainiel opened 3 months ago

Melethainiel commented 3 months ago

Hey @amantinband ! First of all, thank you for this amazing template :+1:

I have a question on the EventualConsistencyMiddleware during integration testing. Due to the transaction being commit after the request has return ok200, when testing for duplication how do you handle that ?

Do you add a delay in the test like below ? Or do you do something else ? Thank you again ! Take care

   public async Task Register_RegisterIdentity_WhenEmailIsAlreadyUsed()
   {
      // Arrange
      var identity = _faker.Generate();
      await _identityRequest.RegisterAsync(identity);
      await Task.Delay(100); // Let the transaction being commited ?
      // Act
      var response = await _identityRequest.RegisterAsync(identity);

      // Assert
      response.IsSuccessStatusCode.Should().BeFalse();
      response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
      var problem = await response.Error!.GetContentAsAsync<ProblemDetails>();
      problem!.Detail.Should().Be(IdentityError.EmailAlreadyUsed(identity.Email).Description);
   }