Replies: 1 comment
-
I decided to solve this by the following:
The implementation of ICurrentUserService:
The modified configuration:
And code to set the User ID:
Thanks, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to modify the integration tests such that _currentUserId is no longer static. The main reason for this is so that I can safely run the tests in parallel.
I am struggling to figure out how to set up the ICurrentUserService so that it return the "current" user (as defined in the RunAsUserAsync() method in the Testing class).
(Note, as part of this change, most of the methods in Testing would be changed from static to instance methods.)
The current logic is the following:
This relies on the static method to get the User Id.
Instead, I'd like to have the service return the user ID for the current test, but I haven't been able to figure how to do this. Conceptually, it would like something like the following:
But of course there is no such "myCurrentTestClass" when the bulding the service.
I was hoping to somehow setup the HttpContextAccessor in the test such that the following would just work from the CurrentUserService:
public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
but I am not sure if that is possible and or recommended.
Any suggestions would be appreciated.
Thanks,
Eric
Beta Was this translation helpful? Give feedback.
All reactions