C
C#17mo ago
no >> body

❔ Localization behavior in tests

I've been facing an issue with xUnit integration tests for my ASP.NET Core application and I'm struggling to find a solution. We use localization in our app for translating various responses. Everything works perfectly fine when I run the tests on my local machine. However, when I try to run them in our CI/CD pipeline on GitLab, the tests fail. Initially, I encountered a System.Globalization.CultureNotFoundException with a message about the invariant culture being the only supported one in globalization-invariant mode. I managed to solve this issue by adding <InvariantGlobalization>false</InvariantGlobalization> to my test project file. The current problem I'm facing is a System.ArgumentException in a method where we use IStringLocalizer. The error message states: A message must be specified when calling WithMessage. Here is a code where this error happens:
LocalizedString enumRangeErrorMessage = errorMessagesLocalizer[$"{ErrorMessageIdentifiers.ValidatorSection}:{ErrorMessageIdentifiers.EnumRange}"];
RuleFor(x => x.OrderBy)
.Must(x => EnumHelper.TryParseWithMemberName<PaymentSystemAccountOrderBy>(x, out _))
.WithMessage(enumRangeErrorMessage)
.When(x => !string.IsNullOrEmpty(x.OrderBy));
LocalizedString enumRangeErrorMessage = errorMessagesLocalizer[$"{ErrorMessageIdentifiers.ValidatorSection}:{ErrorMessageIdentifiers.EnumRange}"];
RuleFor(x => x.OrderBy)
.Must(x => EnumHelper.TryParseWithMemberName<PaymentSystemAccountOrderBy>(x, out _))
.WithMessage(enumRangeErrorMessage)
.When(x => !string.IsNullOrEmpty(x.OrderBy));
Where errorMessagesLocalizer is just IStringLocalizer. The odd part is that this exception only occurs in the pipeline. The tests run successfully on my local machine. I've checked that the paths to my resources are correct and that they are included in the build output. I've tried replicating the CI/CD environment locally to debug the issue, but I can't reproduce it. I'm running out of ideas here. Does anyone have any suggestions on what could be going wrong or what else I could try?
1 Reply
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server