- ABP Framework version: v9.0.0
- UI Type: Angular
- Database System: EF Core
- Tiered (for MVC) or Auth Server Separated (for Angular): no
- Exception message and full stack trace:
- Steps to reproduce the issue:
I created my project via Abp Studio. But SampleDomainTests not appear in my Test Explorer, so I cannot run unit test. I think Abp studio is generating the test code incorrectly.
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Xunit;
namespace Ekol.Abc.Samples;
/* This is just an example test class.
* Normally, you don't test code of the modules you are using
* (like IdentityUserManager here).
* Only test your own domain services.
*/
public abstract class SampleDomainTests<TStartupModule> : AbcDomainTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IIdentityUserRepository _identityUserRepository;
private readonly IdentityUserManager _identityUserManager;
protected SampleDomainTests()
{
_identityUserRepository = GetRequiredService<IIdentityUserRepository>();
_identityUserManager = GetRequiredService<IdentityUserManager>();
}
[Fact]
public async Task Should_Set_Email_Of_A_User()
{
IdentityUser adminUser;
/* Need to manually start Unit Of Work because
* FirstOrDefaultAsync should be executed while db connection / context is available.
*/
await WithUnitOfWorkAsync(async () =>
{
adminUser = await _identityUserRepository
.FindByNormalizedUserNameAsync("ADMIN");
await _identityUserManager.SetEmailAsync(adminUser, "newemail@abp.io");
await _identityUserRepository.UpdateAsync(adminUser);
});
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN");
adminUser.Email.ShouldBe("newemail@abp.io");
}
}
6 Answer(s)
-
0
Hi, I made the following changes but I still get another error
protected
->public
public abstract class SampleDomainTests : AbcDomainTestBase where TStartupModule : IAbpModule
->public class SampleDomainTests : AbcDomainTestBase<AbcDomainTestModule>
But this time I get this error:
---- Autofac.Core.DependencyResolutionException : An exception was thrown while activating Volo.Abp.PermissionManagement.PermissionDataSeedContributor -> Volo.Abp.Authorization.Permissions.PermissionDefinitionManager -> Volo.Abp.PermissionManagement.DynamicPermissionDefinitionStore. -------- Autofac.Core.DependencyResolutionException : None of the constructors found on type 'Volo.Abp.PermissionManagement.DynamicPermissionDefinitionStore' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.PermissionManagement.IPermissionGroupDefinitionRecordRepository permissionGroupRepository' of constructor 'Void .ctor(Volo.Abp.PermissionManagement.IPermissionGroupDefinitionRecordRepository, Volo.Abp.PermissionManagement.IPermissionDefinitionRecordRepository, Volo.Abp.PermissionManagement.IPermissionDefinitionSerializer, Volo.Abp.PermissionManagement.IDynamicPermissionDefinitionStoreInMemoryCache, Microsoft.Extensions.Caching.Distributed.IDistributedCache, Microsoft.Extensions.Options.IOptions`1[Volo.Abp.Caching.AbpDistributedCacheOptions], Microsoft.Extensions.Options.IOptions`1[Volo.Abp.PermissionManagement.PermissionManagementOptions], Volo.Abp.DistributedLocking.IAbpDistributedLock)'.```
-
0
Hi, I made the following changes but I still get another error
protected
->public
public abstract class SampleDomainTests : AbcDomainTestBase where TStartupModule : IAbpModule
->
public class SampleDomainTests : AbcDomainTestBase<AbcDomainTestModule>
But this time I get this error:
---- Autofac.Core.DependencyResolutionException : An exception was thrown while activating Volo.Abp.PermissionManagement.PermissionDataSeedContributor -> Volo.Abp.Authorization.Permissions.PermissionDefinitionManager -> Volo.Abp.PermissionManagement.DynamicPermissionDefinitionStore. -------- Autofac.Core.DependencyResolutionException : None of the constructors found on type 'Volo.Abp.PermissionManagement.DynamicPermissionDefinitionStore' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.PermissionManagement.IPermissionGroupDefinitionRecordRepository permissionGroupRepository' of constructor 'Void .ctor(Volo.Abp.PermissionManagement.IPermissionGroupDefinitionRecordRepository, Volo.Abp.PermissionManagement.IPermissionDefinitionRecordRepository, Volo.Abp.PermissionManagement.IPermissionDefinitionSerializer, Volo.Abp.PermissionManagement.IDynamicPermissionDefinitionStoreInMemoryCache, Microsoft.Extensions.Caching.Distributed.IDistributedCache, Microsoft.Extensions.Options.IOptions`1[Volo.Abp.Caching.AbpDistributedCacheOptions], Microsoft.Extensions.Options.IOptions`1[Volo.Abp.PermissionManagement.PermissionManagementOptions], Volo.Abp.DistributedLocking.IAbpDistributedLock)'.```
Hi, you don't need to make a change in the existing test projects (so, please revert your changes). With our new testing infrastructure, your tests will be shown in the Test Explorer (under the
*.EntityFrameworkCore.Tests
projects - within relevant sub-folders) as follows:We categorized tests with a folder-based approach, which gives you easier management.
-
0
Hi Engin Can, I had to create EfCoreAbcDomainTests class for my Entity. Abp Studio should automatically generate this class for each entity. When I run it I get the following error. I get the same error for SampleDomainTest:
---- Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while saving the entity changes. See the inner exception for details. -------- Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'FOREIGN KEY constraint failed'.
-
0
Hi Engin Can, I had to create EfCoreAbcDomainTests class for my Entity. Abp Studio should automatically generate this class for each entity. When I run it I get the following error. I get the same error for SampleDomainTest:
---- Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while saving the entity changes. See the inner exception for details. -------- Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'FOREIGN KEY constraint failed'.
Hi, it seems this is related to your own test case. If you share the complete steps, I can better assist you (also please share the test file). You can take the pre-defined sample tests for reference.
-
0
Hi Engin Can, Yes, I found the foreign key error, there is no problem at the moment. We need to get used to the new test framework structure, we would love for you to explain in detail why such a change was made with a blog post or a live broadcast. Because we are trying very hard to write test codes. For example, finding the foreign key error can be very difficult. Finally, when the entity is created, the EfCore[Entity]DomainTests class is not created, I had to create this class myself. I would be happy if an issue record is opened for this. Thank you for your support.
-
0
Hi Engin Can, Yes, I found the foreign key error, there is no problem at the moment. We need to get used to the new test framework structure, we would love for you to explain in detail why such a change was made with a blog post or a live broadcast. Because we are trying very hard to write test codes. For example, finding the foreign key error can be very difficult. Finally, when the entity is created, the EfCore[Entity]DomainTests class is not created, I had to create this class myself. I would be happy if an issue record is opened for this. Thank you for your support.
Thanks. @maliming created an article to explain why we made such a change. You can read from https://abp.io/community/articles/the-new-unit-test-structure-in-abp-application-4vvvp2oy
Regards.