Added test for Create method.

pull/112/head
Halil İbrahim Kalkan 8 years ago
parent 3fc49f02d1
commit e2d438b286

@ -1,5 +1,8 @@
namespace Volo.Abp.Identity
using System.ComponentModel.DataAnnotations;
namespace Volo.Abp.Identity
{
//TODO: Use different Dtos for Create & Update even if they are derived from a base Dto. Thus, clients will be backward compatible in a future change.
public class IdentityUserCreateOrUpdateDto
{
public string UserName { get; set; }
@ -8,10 +11,12 @@
public string PhoneNumber { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool TwoFactorEnabled { get; set; } //TODO: Optional?
public bool LockoutEnabled { get; set; }
public bool LockoutEnabled { get; set; } //TODO: Optional?
[Required]
[MaxLength(16)] //TODO: Create a shared dll of Identity and move consts to there for sharing!
public string Password { get; set; }
}
}

@ -41,7 +41,8 @@ namespace Volo.Abp.Identity
var user = new IdentityUser(GuidGenerator.Create(), input.UserName);
await UpdateUserProperties(input, user);
await _userManager.CreateAsync(user, input.Password);
await _userManager.AddPasswordAsync(user, input.Password);
await _userManager.CreateAsync(user);
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
@ -53,6 +54,7 @@ namespace Volo.Abp.Identity
await _userManager.SetUserNameAsync(user, input.UserName);
await UpdateUserProperties(input, user);
await _userManager.UpdateAsync(user);
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.TestBase;
using Volo.Abp.TestBase;
namespace Volo.Abp.Identity
{

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Application.Dtos;
@ -16,11 +17,34 @@ namespace Volo.Abp.Identity
}
[Fact]
public async Task GetList()
public async Task GetListAsync()
{
var result = await _identityUserAppService.GetListAsync(new PagedAndSortedResultRequestDto { MaxResultCount = 10 });
var result = await _identityUserAppService.GetListAsync(new PagedAndSortedResultRequestDto());
result.TotalCount.ShouldBeGreaterThan(0);
result.Items.Count.ShouldBeGreaterThan(0);
}
[Fact]
public async Task CreateAsync()
{
var input = new IdentityUserCreateOrUpdateDto
{
UserName = Guid.NewGuid().ToString(),
Email = Guid.NewGuid().ToString("N").Left(16) + "@abp.io",
LockoutEnabled = true,
PhoneNumber = RandomHelper.GetRandom(10000000,100000000).ToString(),
Password = "123qwe"
};
var result = await _identityUserAppService.CreateAsync(input);
result.Id.ShouldNotBe(Guid.Empty);
result.UserName.ShouldBe(input.UserName);
result.Email.ShouldBe(input.Email);
result.LockoutEnabled.ShouldBe(input.LockoutEnabled);
result.PhoneNumber.ShouldBe(input.PhoneNumber);
//TODO: Also check repository
}
}
}

@ -34,10 +34,7 @@ namespace Volo.Abp.MemoryDb.Repositories
_personRepository.Insert(new Person(Guid.NewGuid(), name, 42));
//Assert
WithUnitOfWork(() =>
{
_personRepository.FirstOrDefault(p => p.Name == name).ShouldNotBeNull();
});
_personRepository.FirstOrDefault(p => p.Name == name).ShouldNotBeNull();
}
}
}

Loading…
Cancel
Save