Hi, I'm trying to set up a test project with aspnet core zero v. 3.2.0.0 and abp 1.5. A very very simple test on separate module project gives me the error: No component for supporting the service Abp.AspNetCore.Configuration.IAbpAspNetCoreConfiguration was found.
I've copied from Framework project test the file project.json, and I've created this simple classes:
public class AppTestBase : AbpIntegratedTestBase<MyTestModule>
{
}
public classMyTestModule : AbpModule
{
}
public class MyTests : AppTestBase
{
[Fact]
public void Shuold_Execute()
{
var myValue= 1;
myValue.ShouldBe(1);
}
}
Also your sample project SimpleTaskSystem-Core gives me the same error. What I'm missing ? Thanks
13 Answer(s)
-
0
Your test module should depend on the modules you are testing. For instance, see Test project in AspNet Zero: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/test/MyCompanyName.AbpZeroTemplate.Tests/AbpZeroTemplateTestModule.cs#L21">https://github.com/aspnetzero/aspnet-ze ... ule.cs#L21</a>
In addition, you may need to add Microsoft.DotNet.InternalAbstractions package to your test project.
-
0
BTW, I made unit tests working for the sample application: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/commit/7f1971e4cbe4453cf510c1b60eb637e8cab96171">https://github.com/aspnetboilerplate/as ... e8cab96171</a>
-
0
Yes sure. Sorry for my incorrect transcript. My test module depends correctly on [DependsOn( typeof(MyApplicationModule), typeof(MyEntityFrameworkModule), typeof(AbpTestBaseModule))] public class MyTestModule : AbpModule
I've just download the git repo of samples and now all Acme.SimpleTaskApp.Tests are green. I've copyed all reference to my tests, plus "Microsoft.DotNet.InternalAbstractions": "1.0.0", but I have still the same error. Note that I'm testing a plugin that has his own solution and works fine on production. Need I create some fake web site or similar ?
Thanks
-
0
You should also need to add dependency to AbpAspNetCoreTestBaseModule (<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/SimpleTaskSystem-Core/test/Acme.SimpleTaskApp.Web.Tests/SimpleTaskAppWebTestModule.cs#L10">https://github.com/aspnetboilerplate/as ... ule.cs#L10</a>) and your web module (because you are testing it).
You may also need to add such a code: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/SimpleTaskSystem-Core/test/Acme.SimpleTaskApp.Web.Tests/Startup.cs#L24">https://github.com/aspnetboilerplate/as ... tup.cs#L24</a> Because ASP.NET Core may not find your Controllers out of the test project. So, add their assemblies to the application part manager.
-
0
Thank you hikalkan. I saw your suggestions but all refer to web test project Acme.SimpleTaskApp.Web.Tests. I'm talking about the project Acme.SimpleTaskApp.Tests. This project doesn't import AbpAspNetCoreTestBaseModule or controller. I don't figure why an identical project with the only difference in referenced application projects doesn't work in a plugin solution. Or better: I'm using EF6, not EFCore
The bin folder of your test contains only those assembly of Abp: Abp.AutoMapper.dll, Abp.dll, Abp.EntityFramework.Common.dll, Abp.EntityFrameworkCore.dll, Abp.TestBase.dll
It may be possible to have a simple plugin project with App, Core, EF6 and tests as example? Or can I send you my project ?
Thanks
-
0
Since the title of this question leads me thinking that you are trying to test Asp.net Core infrastructure (e.g. a Controller) from unit tests.
If you want to just test your application layer, then it will be simpler. Acme.SimpleTaskApp.Tests is already working. But as you exception says "IAbpAspNetCoreConfiguration" not found, your project references Abp.AspNetCore package? Right? If you are not testing web layer, why it has a reference?
-
0
You are right. I'm using the name of the template as title. Sorry, my fault. I'm gone ahead: resolved the " Abp.AspNetCore.Configuration.IAbpAspNetCoreConfiguration" error. I found an unused Configuration.Modules.AbpAspNetCore().CreateControllersForAppServices(typeof(myApplicationModule) .Assembly);
Now I've this error: Value cannot be null. Parameter name: value in Abp.Zero.Configuration.AbpZeroEntityTypes.set_Tenant(Type value) in Abp.Zero.AbpZeroCoreModule.FillMissingEntityTypes()
I guess the framework needs that some table are prefilled before test and I guess that work is done on AppTestBase with
new InitialHostDbBuilder(context).Create();, new DefaultTenantBuilder(context).Create(); and so on. My plugin is unaware of security and has his own context. How can I provide the missing base data ?Thanks
-
0
News about this topic? Do you have some suggestion @hikalkan ?
-
0
Hi,
It's very hard for me to understand the problem. You have created new projects in your solution and want to write a unit test project to test those new projects (modules). Probably module dependencies or assembly dependencies are not correct. I can not understand it unless I have the solution.
-
0
You are right. I try to explain better. The scenario is:
- One solution with AbpZero template that runs as web host for all services. Nobody (developer) can touch this solution. The only edit is the configuration of plugin modules directory.
- Team A owns a solution with one plugin module like Reports.
- Team B owns a solution with one plugin module like Health.
Both solutions references only Abp and AbpZero nuget packages and there are Application,Core and EntityFramework projects.
So far so good. The plugins copyed on Web Host works good.
Now I want to implement unit and integration tests in Team A and Team B project. Following the steps to build a test project, I can't execute nothing related to database context. At startup I have the error mentioned in previous post : Value cannot be null. Parameter name: value in Abp.Zero.Configuration.AbpZeroEntityTypes.set_Tenant(Type value) in Abp.Zero.AbpZeroCoreModule.FillMissingEntityTypes()
The question is: how can I setup the environment needed by Abp (Host, Tenant, Seed, and so on), being in a different solution than template ?
If you need, I can create a simple module solution that replicate the problem.
Thanks.
-
0
The problem here is that: AbpTenant, AbpUser and AbpRole entities are abstract entities. Abp.Zero tries to find their implementation types (Tenant, User and Role) in your application when you run unit tests. However, since you don't have a reference to the main application's .Core module, it can not find them. That means your plugins can not work without the main application. Solution? You can reference and use the main application's modules from your module unit test projects. I mean referencing just for test projects, not for module projects.
-
0
Ok, I clear what you say but doesn't work yet. I restarted from scratch adding to your template a very simple module with one table, and one methods. The module works good, but I'm struggling with tests.
Has you know, tests are necessary for our definition of done, and also because test are necessary ! dot. :-)
How can I give you the elements in order to resolve my issues? Maybe I can send by email my project?
Thanks.
-
0
Hi @ivanosw1,
Please send your project to <a href="mailto:[email protected]">[email protected]</a>.
Thanks.