From 3fc49f02d1342f98ac17168e1a1ee8440e5bc32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 19 Sep 2017 21:39:34 +0300 Subject: [PATCH] Added first unit test for Abp.Identity.Application layer. --- Volo.Abp.sln | 9 +++- ...Volo.Abp.Identity.Application.Tests.csproj | 30 ++++++++++++ .../AbpIdentityApplicationTestBase.cs | 13 ++++++ .../AbpIdentityApplicationTestModule.cs | 46 +++++++++++++++++++ .../Identity/AbpIdentityTestDataBuilder.cs | 24 ++++++++++ .../Identity/IdentityUserAppService_Tests.cs | 26 +++++++++++ 6 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 test/Volo.Abp.Identity.Application.Tests/Volo.Abp.Identity.Application.Tests.csproj create mode 100644 test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestBase.cs create mode 100644 test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestModule.cs create mode 100644 test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs create mode 100644 test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs diff --git a/Volo.Abp.sln b/Volo.Abp.sln index 4c62a97e82..f095b5a44f 100644 --- a/Volo.Abp.sln +++ b/Volo.Abp.sln @@ -130,10 +130,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.TestApp.Tests", "t EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http", "src\Volo.Abp.Http\Volo.Abp.Http.csproj", "{01A70034-D353-4BF9-821D-F2B6F7641532}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client", "src\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj", "{D5E2FB37-0194-480A-B952-5FFECC1200EB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http.Client", "src\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj", "{D5E2FB37-0194-480A-B952-5FFECC1200EB}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http.Client.Tests", "test\Volo.Abp.Http.Client.Tests\Volo.Abp.Http.Client.Tests.csproj", "{703BD43C-02B9-413F-854C-9CBA0C963196}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Identity.Application.Tests", "test\Volo.Abp.Identity.Application.Tests\Volo.Abp.Identity.Application.Tests.csproj", "{40E21A35-1C66-4E89-A16E-0475011F7EFD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -336,6 +338,10 @@ Global {703BD43C-02B9-413F-854C-9CBA0C963196}.Debug|Any CPU.Build.0 = Debug|Any CPU {703BD43C-02B9-413F-854C-9CBA0C963196}.Release|Any CPU.ActiveCfg = Release|Any CPU {703BD43C-02B9-413F-854C-9CBA0C963196}.Release|Any CPU.Build.0 = Release|Any CPU + {40E21A35-1C66-4E89-A16E-0475011F7EFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40E21A35-1C66-4E89-A16E-0475011F7EFD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40E21A35-1C66-4E89-A16E-0475011F7EFD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40E21A35-1C66-4E89-A16E-0475011F7EFD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -399,6 +405,7 @@ Global {01A70034-D353-4BF9-821D-F2B6F7641532} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} {D5E2FB37-0194-480A-B952-5FFECC1200EB} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} {703BD43C-02B9-413F-854C-9CBA0C963196} = {37087D1B-3693-4E96-983D-A69F210BDE53} + {40E21A35-1C66-4E89-A16E-0475011F7EFD} = {146F561E-C7B8-4166-9383-47E1BC1A2E62} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo.Abp.Identity.Application.Tests.csproj b/test/Volo.Abp.Identity.Application.Tests/Volo.Abp.Identity.Application.Tests.csproj new file mode 100644 index 0000000000..0b2843a169 --- /dev/null +++ b/test/Volo.Abp.Identity.Application.Tests/Volo.Abp.Identity.Application.Tests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp2.0 + Volo.Abp.Identity.Application.Tests + Volo.Abp.Identity.Application.Tests + true + false + false + false + + + + + + + + + + + + + + + + + + + + diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestBase.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestBase.cs new file mode 100644 index 0000000000..59e1a1161c --- /dev/null +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestBase.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.TestBase; + +namespace Volo.Abp.Identity +{ + public class AbpIdentityApplicationTestBase : AbpIntegratedTest + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestModule.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestModule.cs new file mode 100644 index 0000000000..6c3e5cd2e8 --- /dev/null +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityApplicationTestModule.cs @@ -0,0 +1,46 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Autofac; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Identity.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Identity +{ + [DependsOn(typeof(AbpIdentityApplicationModule), typeof(AbpIdentityEntityFrameworkCoreModule), typeof(AbpAutofacModule))] + public class AbpIdentityApplicationTestModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAssemblyOf(); + + services.AddEntityFrameworkInMemoryDatabase(); + + var databaseName = Guid.NewGuid().ToString(); + + services.Configure(options => + { + options.Configure(context => + { + context.DbContextOptions.UseInMemoryDatabase(databaseName); + }); + }); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + SeedTestData(context); + } + + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) + { + scope.ServiceProvider + .GetRequiredService() + .Build(); + } + } + } +} diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs new file mode 100644 index 0000000000..6cfbd655be --- /dev/null +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs @@ -0,0 +1,24 @@ +using Volo.Abp.DependencyInjection; +using Volo.Abp.Guids; + +namespace Volo.Abp.Identity +{ + public class AbpIdentityTestDataBuilder : ITransientDependency + { + private readonly IGuidGenerator _guidGenerator; + private readonly IIdentityUserRepository _userRepository; + + public AbpIdentityTestDataBuilder( + IGuidGenerator guidGenerator, + IIdentityUserRepository userRepository) + { + _guidGenerator = guidGenerator; + _userRepository = userRepository; + } + + public void Build() + { + _userRepository.Insert(new IdentityUser(_guidGenerator.Create(), "john.nash")); + } + } +} \ No newline at end of file diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs new file mode 100644 index 0000000000..aee0f15889 --- /dev/null +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Application.Dtos; +using Xunit; + +namespace Volo.Abp.Identity +{ + public class IdentityUserAppService_Tests : AbpIdentityApplicationTestBase + { + private readonly IIdentityUserAppService _identityUserAppService; + + public IdentityUserAppService_Tests() + { + _identityUserAppService = ServiceProvider.GetRequiredService(); + } + + [Fact] + public async Task GetList() + { + var result = await _identityUserAppService.GetListAsync(new PagedAndSortedResultRequestDto { MaxResultCount = 10 }); + result.TotalCount.ShouldBeGreaterThan(0); + result.Items.Count.ShouldBeGreaterThan(0); + } + } +}