If you're creating a bug/problem report, please include followings:
Hi the problem I am encountering sounds like the same one Jesse (I am working on the same code as Jesse but he is no longer with the project) had in this post: https://support.abp.io/QA/Questions/1985/Volo-Modules-Unit-Tests-are-not-executing
I followed the link in that post to the duplicate, but the source that was posted with a fix/explanation is no longer available.
I downloaded the source for the Language Management module and am able to run the tests in that state, unfortunately, i am unable to get the unit tests to run in our modified version. I can confirm that the crash happens when getting the IDataSeeder service from the container. I have also tried to get each of the dependencies in the data seeder's ctor and the test host will crash when trying to fetch this service: DbContextOptions<LanguageManagementDbContext>>
I tested this by adding the following just before the call to the data seeder in the LanguageManagementTestBase
var dbo = context.ServiceProvider.GetService<DbContextOptions<LanguageManagementDbContext>>(); //crashes test host
I am unable to catch the exception that is being thrown, but assume it has something to do with constructing the above object.
We are using the in memory sqlite provider for the database.
I am using the xunit visual studio test runner (not jet-brains resharper). I can reproduce the same problem running on the command line (dotnet test ...
). I can provide the logs, but they are not very interesting.
Do you have any advice on how to find the problem?
thanks,
andre
Full text of the test base class
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.LanguageManagement
{
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpTestBaseModule),
typeof(AbpAuthorizationModule),
typeof(LanguageManagementDomainModule)
)]
public class LanguageManagementTestBaseModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAlwaysAllowAuthorization();
Configure<AbpLocalizationOptions>(options =>
{
options.Languages.Add(new LanguageInfo("en-US", "en", "English", "flag-icon flag-icon-gb"));
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe", "flag-icon flag-icon-tr"));
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
var dbo = context.ServiceProvider.GetService<DbContextOptions<LanguageManagementDbContext>>(); // test host crashes
AsyncHelper.RunSync(async () =>
{
using (var scope = context.ServiceProvider.CreateScope())
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>() // this is the original crash
.SeedAsync();
}
});
}
}
}