mirror of https://github.com/abpframework/abp.git
committed by
GitHub
12 changed files with 178 additions and 81 deletions
@ -0,0 +1,53 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Entities.Auditing; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Users |
||||
|
{ |
||||
|
/* This entity shares the same table/collection ("AbpUsers" by default) with the |
||||
|
* IdentityUser entity of the Identity module. |
||||
|
* |
||||
|
* - You can define your custom properties into this class. |
||||
|
* - You never create or delete this entity, becase it is Identity module's job. |
||||
|
* - You can query users from database with this entity. |
||||
|
* - You can update values of your custom properties. |
||||
|
*/ |
||||
|
public class AppUser : FullAuditedAggregateRoot<Guid>, IUser |
||||
|
{ |
||||
|
#region Base properties
|
||||
|
|
||||
|
/* These properties are shared with the IdentityUser entity of the Identity module. |
||||
|
* Do not change these properties through this class. Instead, use Identity module |
||||
|
* services (like IdentityUserManager) to change them. |
||||
|
* So, this properties are designed as read only! |
||||
|
*/ |
||||
|
|
||||
|
public virtual Guid? TenantId { get; private set; } |
||||
|
|
||||
|
public virtual string UserName { get; private set; } |
||||
|
|
||||
|
public virtual string Name { get; private set; } |
||||
|
|
||||
|
public virtual string Surname { get; private set; } |
||||
|
|
||||
|
public virtual string Email { get; private set; } |
||||
|
|
||||
|
public virtual bool EmailConfirmed { get; private set; } |
||||
|
|
||||
|
public virtual string PhoneNumber { get; private set; } |
||||
|
|
||||
|
public virtual bool PhoneNumberConfirmed { get; private set; } |
||||
|
|
||||
|
#endregion
|
||||
|
|
||||
|
/* Add your own properties here. Example: |
||||
|
* |
||||
|
* public virtual string MyProperty { get; set; } |
||||
|
*/ |
||||
|
|
||||
|
private AppUser() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,29 +0,0 @@ |
|||||
using System.IO; |
|
||||
using Microsoft.EntityFrameworkCore; |
|
||||
using Microsoft.EntityFrameworkCore.Design; |
|
||||
using Microsoft.Extensions.Configuration; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.EntityFrameworkCore |
|
||||
{ |
|
||||
public class MyProjectNameDbContextFactory : IDesignTimeDbContextFactory<MyProjectNameDbContext> |
|
||||
{ |
|
||||
public MyProjectNameDbContext CreateDbContext(string[] args) |
|
||||
{ |
|
||||
var configuration = BuildConfiguration(); |
|
||||
|
|
||||
var builder = new DbContextOptionsBuilder<MyProjectNameDbContext>() |
|
||||
.UseSqlServer(configuration.GetConnectionString("Default")); |
|
||||
|
|
||||
return new MyProjectNameDbContext(builder.Options); |
|
||||
} |
|
||||
|
|
||||
private static IConfigurationRoot BuildConfiguration() |
|
||||
{ |
|
||||
var builder = new ConfigurationBuilder() |
|
||||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../MyCompanyName.MyProjectName.Web/")) |
|
||||
.AddJsonFile("appsettings.json", optional: false); |
|
||||
|
|
||||
return builder.Build(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Shouldly; |
|
||||
using Volo.Abp.Identity; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Samples |
|
||||
{ |
|
||||
public class SampleTest : MyProjectNameApplicationTestBase |
|
||||
{ |
|
||||
private readonly IIdentityUserAppService _userAppService; |
|
||||
|
|
||||
public SampleTest() |
|
||||
{ |
|
||||
_userAppService = ServiceProvider.GetRequiredService<IIdentityUserAppService>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task Initial_Data_Should_Contain_Admin_User() |
|
||||
{ |
|
||||
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput()); |
|
||||
result.TotalCount.ShouldBeGreaterThan(0); |
|
||||
result.Items.ShouldContain(u => u.UserName == "admin"); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,59 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using MyCompanyName.MyProjectName.Users; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Samples |
||||
|
{ |
||||
|
public class SampleTests : MyProjectNameApplicationTestBase |
||||
|
{ |
||||
|
private readonly IIdentityUserAppService _userAppService; |
||||
|
private readonly IRepository<AppUser, Guid> _appUserRepository; |
||||
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
||||
|
|
||||
|
public SampleTests() |
||||
|
{ |
||||
|
_userAppService = ServiceProvider.GetRequiredService<IIdentityUserAppService>(); |
||||
|
_appUserRepository = ServiceProvider.GetRequiredService<IRepository<AppUser, Guid>>(); |
||||
|
_unitOfWorkManager = ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Initial_Data_Should_Contain_Admin_User() |
||||
|
{ |
||||
|
//Act
|
||||
|
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput()); |
||||
|
|
||||
|
//Assert
|
||||
|
result.TotalCount.ShouldBeGreaterThan(0); |
||||
|
result.Items.ShouldContain(u => u.UserName == "admin"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Query_AppUser() |
||||
|
{ |
||||
|
/* Need to manually start Unit Of Work because |
||||
|
* FirstOrDefaultAsync should be executed while db connection / context is available. |
||||
|
*/ |
||||
|
using (var uow = _unitOfWorkManager.Begin()) |
||||
|
{ |
||||
|
//Act
|
||||
|
var adminUser = await _appUserRepository |
||||
|
.Where(u => u.UserName == "admin") |
||||
|
.FirstOrDefaultAsync(); |
||||
|
|
||||
|
//Assert
|
||||
|
adminUser.ShouldNotBeNull(); |
||||
|
|
||||
|
await uow.CompleteAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue