Unit Testing with more than one DbContext
Hi,
Is unit testing with 2 db contexts working? I am struggling in it and till now the test methods can not find the inserted data. I have used the help of this link https://github.com/abpframework/abp/issues/1153 to insert data. I found also some people complaining about it https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1437. The unit test code is not giving any error or log. Any help or steps would be appreciated.
Note: testing with 1 db-context is working properly
Thanks
Hi
- Your ABP Framework version.
- Exception message and stack trace if available (check the logs).
- Steps needed to reproduce the problem.
- Please provide a project if possible.
Sorry,
Your ABP Framework version --> 2.3.0 Exception message and stack trace if available (check the logs) --> No logs written and no exceptions either Steps needed to reproduce the problem --> Just make the file "EntityFrameworkCoreTestModule" like attached in project "ProjectName.EntityFrameworkCore.Tests" then access the services or repositories which are using the second context
hi Can you share a full source code of project?
Hi, The solution itself is too big, so I uploaded test projects only if they will help. You can use this test class as beginning "test\Linkdev.Inspection.Application.Tests\UnitTesting\InspectedEntityAppService_Tests" as some other code was for just trials but not used anymore.
hi @Wello86 You can use a template project. In this way I can easy debug it.
Hi @maliming, Ok will use a template project then send you
Hi @maliming, when I was making a new sample for you on the new version, I discovered the issue and fixed it. It was related to UnitOfWorkManager. This link https://github.com/abpframework/abp/issues/1153 helped me a lot. Now I will test the part of accessing 2 databases in same Fact so still do not know if this is going to work or not. so insert data be like in version 3.0.1
public Task SeedAsync(DataSeedContext context)
{
/* Seed additional test data... */
using (var uow = _unitOfWorkManager.Begin(requiresNew: true))
{
// insert data here
}
return Task.CompletedTask;
}
but in version 2.3.0 sometimes you need for this and "autoSave: true" and sometimes no. Not sure how this happens but anyway it is working now :)
Thanks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
maybe there is a advice. https://blog.csdn.net/qq_29621089/article/details/110229881