Skip to content

Commit 6b99218

Browse files
committed
Converted tests to .netcoreapp1.1.
1 parent 7012215 commit 6b99218

File tree

10 files changed

+93
-100
lines changed

10 files changed

+93
-100
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/Dto/CreateTenantInput.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System.ComponentModel.DataAnnotations;
2+
using Abp.Authorization.Users;
23
using Abp.AutoMapper;
34
using Abp.MultiTenancy;
4-
using AbpCompanyName.AbpProjectName.Authorization.Users;
5-
using AbpCompanyName.AbpProjectName.Users;
65

76
namespace AbpCompanyName.AbpProjectName.MultiTenancy.Dto
87
{
@@ -19,7 +18,7 @@ public class CreateTenantInput
1918
public string Name { get; set; }
2019

2120
[Required]
22-
[StringLength(User.MaxEmailAddressLength)]
21+
[StringLength(AbpUserBase.MaxEmailAddressLength)]
2322
public string AdminEmailAddress { get; set; }
2423

2524
[MaxLength(AbpTenantBase.MaxConnectionStringLength)]

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/TenantAppService.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ public TenantAppService(
4242
public ListResultDto<TenantListDto> GetTenants()
4343
{
4444
return new ListResultDto<TenantListDto>(
45-
_tenantManager.Tenants
46-
.OrderBy(t => t.TenancyName)
47-
.ToList()
48-
.MapTo<List<TenantListDto>>()
49-
);
45+
ObjectMapper.Map<List<TenantListDto>>(
46+
_tenantManager.Tenants.OrderBy(t => t.TenancyName).ToList()
47+
)
48+
);
5049
}
5150

5251
public async Task CreateTenant(CreateTenantInput input)
5352
{
5453
//Create tenant
55-
var tenant = input.MapTo<Tenant>();
54+
var tenant = ObjectMapper.Map<Tenant>(input);
5655
tenant.ConnectionString = input.ConnectionString.IsNullOrEmpty()
5756
? null
5857
: SimpleStringCipher.Instance.Encrypt(input.ConnectionString);

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Sessions/SessionAppService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Threading.Tasks;
22
using Abp.Auditing;
3-
using Abp.Authorization;
43
using Abp.AutoMapper;
54
using AbpCompanyName.AbpProjectName.Sessions.Dto;
65

@@ -22,12 +21,12 @@ public async Task<GetCurrentLoginInformationsOutput> GetCurrentLoginInformations
2221

2322
if (AbpSession.TenantId.HasValue)
2423
{
25-
output.Tenant = (await GetCurrentTenantAsync()).MapTo<TenantLoginInfoDto>();
24+
output.Tenant = ObjectMapper.Map<TenantLoginInfoDto>(await GetCurrentTenantAsync());
2625
}
2726

2827
if (AbpSession.UserId.HasValue)
2928
{
30-
output.User = (await GetCurrentUserAsync()).MapTo<UserLoginInfoDto>();
29+
output.User = ObjectMapper.Map<UserLoginInfoDto>(await GetCurrentUserAsync());
3130
}
3231

3332
return output;

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Users/UserAppService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public async Task<ListResultDto<UserListDto>> GetUsers()
4949
var users = await _userRepository.GetAllListAsync();
5050

5151
return new ListResultDto<UserListDto>(
52-
users.MapTo<List<UserListDto>>()
52+
ObjectMapper.Map<List<UserListDto>>(users)
5353
);
5454
}
5555

5656
public async Task CreateUser(CreateUserInput input)
5757
{
58-
var user = input.MapTo<User>();
58+
var user = ObjectMapper.Map<User>(input);
5959

6060
user.TenantId = AbpSession.TenantId;
6161
user.Password = _passwordHasher.HashPassword(user, input.Password);

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Core/Controllers/TokenAuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task<AuthenticateResultModel> Authenticate([FromBody] AuthenticateM
7272
[HttpGet]
7373
public List<ExternalLoginProviderInfoModel> GetExternalAuthenticationProviders()
7474
{
75-
return _externalAuthConfiguration.Providers.MapTo<List<ExternalLoginProviderInfoModel>>();
75+
return ObjectMapper.Map<List<ExternalLoginProviderInfoModel>>(_externalAuthConfiguration.Providers);
7676
}
7777

7878
[HttpPost]

aspnet-core/test/AbpCompanyName.AbpProjectName.Tests/AbpCompanyName.AbpProjectName.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<VersionPrefix>1.0.0.0</VersionPrefix>
5-
<TargetFramework>net461</TargetFramework>
5+
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
66
<AssemblyName>AbpCompanyName.AbpProjectName.Tests</AssemblyName>
77
<PackageId>AbpCompanyName.AbpProjectName.Tests</PackageId>
88
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -13,17 +13,18 @@
1313

1414
<ItemGroup>
1515
<ProjectReference Include="..\..\src\AbpCompanyName.AbpProjectName.Application\AbpCompanyName.AbpProjectName.Application.csproj" />
16+
<ProjectReference Include="..\..\src\AbpCompanyName.AbpProjectName.EntityFrameworkCore\AbpCompanyName.AbpProjectName.EntityFrameworkCore.csproj" />
1617
</ItemGroup>
1718

1819
<ItemGroup>
1920
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2021
<PackageReference Include="NSubstitute" Version="2.0.2" />
2122
<PackageReference Include="Shouldly" Version="2.8.2" />
22-
<PackageReference Include="Effort.EF6" Version="1.3.0" />
2323
<PackageReference Include="xunit" Version="2.2.0" />
2424
<PackageReference Include="xunit.extensibility.execution" Version="2.2.0" />
2525
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
2626
<PackageReference Include="Abp.TestBase" Version="2.0.1" />
27+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
2728
</ItemGroup>
2829

2930
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">

aspnet-core/test/AbpCompanyName.AbpProjectName.Tests/AbpProjectNameTestBase.cs

Lines changed: 19 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,53 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Data.Common;
4-
using System.Data.Entity;
52
using System.Linq;
63
using System.Threading.Tasks;
74
using Abp;
8-
using Abp.Configuration.Startup;
9-
using Abp.Domain.Uow;
5+
using Abp.Authorization.Users;
6+
using Abp.Events.Bus;
7+
using Abp.Events.Bus.Entities;
108
using Abp.Runtime.Session;
119
using Abp.TestBase;
1210
using AbpCompanyName.AbpProjectName.Authorization.Users;
13-
using AbpCompanyName.AbpProjectName.EntityFramework;
14-
using AbpCompanyName.AbpProjectName.Migrations.SeedData;
11+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
12+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore.Seed.Host;
13+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore.Seed.Tenants;
1514
using AbpCompanyName.AbpProjectName.MultiTenancy;
16-
using Castle.MicroKernel.Registration;
17-
using Effort;
18-
using EntityFramework.DynamicFilters;
15+
using Microsoft.EntityFrameworkCore;
1916

2017

2118
namespace AbpCompanyName.AbpProjectName.Tests
2219
{
2320
public abstract class AbpProjectNameTestBase : AbpIntegratedTestBase<AbpProjectNameTestModule>
2421
{
25-
private DbConnection _hostDb;
26-
private Dictionary<int, DbConnection> _tenantDbs; //only used for db per tenant architecture
27-
2822
protected AbpProjectNameTestBase()
2923
{
24+
void NormalizeDbContext(AbpProjectNameDbContext context)
25+
{
26+
context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
27+
context.EventBus = NullEventBus.Instance;
28+
context.SuppressAutoSetTenantId = true;
29+
}
30+
3031
//Seed initial data for host
3132
AbpSession.TenantId = null;
3233
UsingDbContext(context =>
3334
{
35+
NormalizeDbContext(context);
3436
new InitialHostDbBuilder(context).Create();
35-
new DefaultTenantCreator(context).Create();
37+
new DefaultTenantBuilder(context).Create();
3638
});
3739

3840
//Seed initial data for default tenant
3941
AbpSession.TenantId = 1;
4042
UsingDbContext(context =>
4143
{
44+
NormalizeDbContext(context);
4245
new TenantRoleAndUserBuilder(context, 1).Create();
4346
});
4447

4548
LoginAsDefaultTenantAdmin();
4649
}
4750

48-
protected override void PreInitialize()
49-
{
50-
base.PreInitialize();
51-
52-
/* You can switch database architecture here: */
53-
UseSingleDatabase();
54-
//UseDatabasePerTenant();
55-
}
56-
57-
/* Uses single database for host and all tenants.
58-
*/
59-
private void UseSingleDatabase()
60-
{
61-
_hostDb = DbConnectionFactory.CreateTransient();
62-
63-
LocalIocManager.IocContainer.Register(
64-
Component.For<DbConnection>()
65-
.UsingFactoryMethod(() => _hostDb)
66-
.LifestyleSingleton()
67-
);
68-
}
69-
70-
/* Uses single database for host and Default tenant,
71-
* but dedicated databases for all other tenants.
72-
*/
73-
private void UseDatabasePerTenant()
74-
{
75-
_hostDb = DbConnectionFactory.CreateTransient();
76-
_tenantDbs = new Dictionary<int, DbConnection>();
77-
78-
LocalIocManager.IocContainer.Register(
79-
Component.For<DbConnection>()
80-
.UsingFactoryMethod((kernel) =>
81-
{
82-
lock (_tenantDbs)
83-
{
84-
var currentUow = kernel.Resolve<ICurrentUnitOfWorkProvider>().Current;
85-
var abpSession = kernel.Resolve<IAbpSession>();
86-
87-
var tenantId = currentUow != null ? currentUow.GetTenantId() : abpSession.TenantId;
88-
89-
if (tenantId == null || tenantId == 1) //host and default tenant are stored in host db
90-
{
91-
return _hostDb;
92-
}
93-
94-
if (!_tenantDbs.ContainsKey(tenantId.Value))
95-
{
96-
_tenantDbs[tenantId.Value] = DbConnectionFactory.CreateTransient();
97-
}
98-
99-
return _tenantDbs[tenantId.Value];
100-
}
101-
}, true)
102-
.LifestyleTransient()
103-
);
104-
}
105-
10651
#region UsingDbContext
10752

10853
protected IDisposable UsingTenantId(int? tenantId)
@@ -138,7 +83,6 @@ protected void UsingDbContext(int? tenantId, Action<AbpProjectNameDbContext> act
13883
{
13984
using (var context = LocalIocManager.Resolve<AbpProjectNameDbContext>())
14085
{
141-
context.DisableAllFilters();
14286
action(context);
14387
context.SaveChanges();
14488
}
@@ -151,7 +95,6 @@ protected async Task UsingDbContextAsync(int? tenantId, Func<AbpProjectNameDbCon
15195
{
15296
using (var context = LocalIocManager.Resolve<AbpProjectNameDbContext>())
15397
{
154-
context.DisableAllFilters();
15598
await action(context);
15699
await context.SaveChangesAsync();
157100
}
@@ -166,7 +109,6 @@ protected T UsingDbContext<T>(int? tenantId, Func<AbpProjectNameDbContext, T> fu
166109
{
167110
using (var context = LocalIocManager.Resolve<AbpProjectNameDbContext>())
168111
{
169-
context.DisableAllFilters();
170112
result = func(context);
171113
context.SaveChanges();
172114
}
@@ -183,7 +125,6 @@ protected async Task<T> UsingDbContextAsync<T>(int? tenantId, Func<AbpProjectNam
183125
{
184126
using (var context = LocalIocManager.Resolve<AbpProjectNameDbContext>())
185127
{
186-
context.DisableAllFilters();
187128
result = await func(context);
188129
await context.SaveChangesAsync();
189130
}
@@ -198,12 +139,12 @@ protected async Task<T> UsingDbContextAsync<T>(int? tenantId, Func<AbpProjectNam
198139

199140
protected void LoginAsHostAdmin()
200141
{
201-
LoginAsHost(User.AdminUserName);
142+
LoginAsHost(AbpUserBase.AdminUserName);
202143
}
203144

204145
protected void LoginAsDefaultTenantAdmin()
205146
{
206-
LoginAsTenant(Tenant.DefaultTenantName, User.AdminUserName);
147+
LoginAsTenant(Tenant.DefaultTenantName, AbpUserBase.AdminUserName);
207148
}
208149

209150
protected void LoginAsHost(string userName)

aspnet-core/test/AbpCompanyName.AbpProjectName.Tests/AbpProjectNameTestModule.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
2+
using Abp.AutoMapper;
3+
using Abp.Dependency;
24
using Abp.Modules;
3-
using Abp.MultiTenancy;
5+
using Abp.Configuration.Startup;
6+
using Abp.Net.Mail;
47
using Abp.TestBase;
58
using Abp.Zero.Configuration;
6-
using AbpCompanyName.AbpProjectName.EntityFramework;
9+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
10+
using AbpCompanyName.AbpProjectName.Tests.DependencyInjection;
711
using Castle.MicroKernel.Registration;
812
using NSubstitute;
913

@@ -16,16 +20,31 @@ namespace AbpCompanyName.AbpProjectName.Tests
1620
)]
1721
public class AbpProjectNameTestModule : AbpModule
1822
{
23+
public AbpProjectNameTestModule(AbpProjectNameEntityFrameworkModule abpProjectNameEntityFrameworkModule)
24+
{
25+
abpProjectNameEntityFrameworkModule.SkipDbContextRegistration = true;
26+
}
27+
1928
public override void PreInitialize()
2029
{
2130
Configuration.UnitOfWork.Timeout = TimeSpan.FromMinutes(30);
2231

32+
//Disable static mapper usage since it breaks unit tests (see https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2052)
33+
Configuration.Modules.AbpAutoMapper().UseStaticMapper = false;
34+
2335
Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
2436

2537
//Use database for language management
2638
Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization();
2739

28-
RegisterFakeService<IAbpZeroDbMigrator>();
40+
RegisterFakeService<AbpZeroDbMigrator>();
41+
42+
Configuration.ReplaceService<IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient);
43+
}
44+
45+
public override void Initialize()
46+
{
47+
ServiceCollectionRegistrar.Register(IocManager);
2948
}
3049

3150
private void RegisterFakeService<TService>() where TService : class
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using Abp.Dependency;
3+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
4+
using AbpCompanyName.AbpProjectName.Identity;
5+
using Castle.MicroKernel.Registration;
6+
using Castle.Windsor.MsDependencyInjection;
7+
using Microsoft.EntityFrameworkCore;
8+
using Microsoft.Extensions.DependencyInjection;
9+
10+
namespace AbpCompanyName.AbpProjectName.Tests.DependencyInjection
11+
{
12+
public static class ServiceCollectionRegistrar
13+
{
14+
public static void Register(IIocManager iocManager)
15+
{
16+
var services = new ServiceCollection();
17+
18+
IdentityRegistrar.Register(services);
19+
20+
services.AddEntityFrameworkInMemoryDatabase();
21+
22+
var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services);
23+
24+
var builder = new DbContextOptionsBuilder<AbpProjectNameDbContext>();
25+
builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);
26+
27+
iocManager.IocContainer.Register(
28+
Component
29+
.For<DbContextOptions<AbpProjectNameDbContext>>()
30+
.Instance(builder.Options)
31+
.LifestyleSingleton()
32+
);
33+
}
34+
}
35+
}

aspnet-core/test/AbpCompanyName.AbpProjectName.Tests/Users/UserAppService_Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Data.Entity;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using AbpCompanyName.AbpProjectName.Users;
43
using AbpCompanyName.AbpProjectName.Users.Dto;
4+
using Microsoft.EntityFrameworkCore;
55
using Shouldly;
66
using Xunit;
77

0 commit comments

Comments
 (0)