Base solution for your next web application
Open Closed

Unit test error #9991


User avatar
0
wydeedev created
  • Product version: 10.0.0
  • Product type: MVC
  • Product framework type: .NET 5
  • Abp framework: 6.0.0

We created a new project within the solution in order to interact with a second database (which does not contain Identity). We've inherited the Abp framework in this project. The application works as normal when running it.

The problem comes when running the unit tests. The following exception occurs:

  • Castle.MicroKernel.ComponentNotFoundException : No component for supporting the service Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager was found

There is already a similar issue in this question but does not solve our problem.

What is causing this issue? Some package missing?


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wydeedev

    The reason for https://support.aspnetzero.com/QA/Questions/6813 is, Test project is referencing *CoreWebModule. Could check if your test project or test module directly or indirectly references WebModule ?

    Thanks,

  • User Avatar
    0
    wydeedev created

    hi @ismcagdas

    Our solution is with the same structure than it is provided when we download aspnetzero. This problem started when we added a new project to the solution. The goal of this project is to connect to another database (it is a class library). This project's module has the following dependencies: AbpEntityFrameworkCoreModule and AbpAspNetCoreModule

    We reference this project, on our .Application and .EntityFrameworkCore projects. The module on our .EntityFrameworkCore project depends on the module from our new project.

    We did not made any change to the test project neither to its module. If the test module depends on the EntityFrameworkCore module, which in turn, depends on our new project's module, is there something we are missing? Or this issue is not related with the new project?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wydeedev,

    Adding the below line into your new Module's PostInitialize method should fix the problem.

    IocManager.Resolve<ApplicationPartManager>()
                    .AddApplicationPartsIfNotAddedBefore(typeof(YourNewModule).Assembly);
    
  • User Avatar
    0
    wydeedev created

    Hi @ismcagdas

    The proposed solution did not worked and the same error keeps happening.

    This first piece of code is the module from the project we added to the solution.

    ` [DependsOn(typeof(AbpEntityFrameworkCoreModule), typeof(AbpAspNetCoreModule))]

    public class MyNewCoreModule : AbpModule
    {
    
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(MyNewCoreModule).GetAssembly());
        }
        
        public override void PostInitialize()
        {
           IocManager.Resolve<ApplicationPartManager>()
                .AddApplicationPartsIfNotAddedBefore(typeof(MyNewCoreModule).Assembly);
        }
    }`
    

    The Entity Framework Core project depends on this new module.

    [DependsOn( typeof(AbpZeroCoreEntityFrameworkCoreModule), typeof(MyProjectCoreModule), typeof(AbpZeroCoreIdentityServervNextEntityFrameworkCoreModule), typeof(MyNewCoreModule))] public class MyProjectEntityFrameworkCoreModule : AbpModule { }

    This last piece of code depends on the MyProjectEntityFrameworkCoreModule.

    [DependsOn( typeof(MyProjectApplicationModule), typeof(MyProjectEntityFrameworkCoreModule), typeof(AbpTestBaseModule))] public class MyProjectTestBaseModule : AbpModule { }

    What we found strange is that the application runs without any problem, this error only happens on the unit tests.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wydeedev

    Is it possible to share your project via email with [email protected] ? We can find the problem faster in this way.

    Thanks,