mirror of https://github.com/abpframework/abp
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							91 lines
						
					
					
						
							2.7 KiB
						
					
					
				
			
		
		
	
	
							91 lines
						
					
					
						
							2.7 KiB
						
					
					
				| using System;
 | |
| using System.Threading.Tasks;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using NSubstitute;
 | |
| using Shouldly;
 | |
| using Volo.Abp.Users;
 | |
| using Xunit;
 | |
| 
 | |
| namespace Volo.Abp.Identity
 | |
| {
 | |
|     public class ProfileAppService_Tests : AbpIdentityApplicationTestBase
 | |
|     {
 | |
|         private readonly IProfileAppService _profileAppService;
 | |
|         private readonly IdentityTestData _testData;
 | |
|         private ICurrentUser _currentUser;
 | |
| 
 | |
|         public ProfileAppService_Tests()
 | |
|         {
 | |
|             _profileAppService = GetRequiredService<IProfileAppService>();
 | |
|             _testData = GetRequiredService<IdentityTestData>();
 | |
|         }
 | |
| 
 | |
|         protected override void AfterAddApplication(IServiceCollection services)
 | |
|         {
 | |
|             _currentUser = Substitute.For<ICurrentUser>();
 | |
|             services.AddSingleton(_currentUser);
 | |
|         }
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task GetAsync()
 | |
|         {
 | |
|             //Arrange
 | |
|             _currentUser.Id.Returns(_testData.UserJohnId);
 | |
|             _currentUser.IsAuthenticated.Returns(true);
 | |
|             
 | |
|             //Act
 | |
|             var result = await _profileAppService.GetAsync();
 | |
| 
 | |
|             //Assert
 | |
|             var johnNash = GetUser("john.nash");
 | |
| 
 | |
|             result.UserName.ShouldBe(johnNash.UserName);
 | |
|             result.Email.ShouldBe(johnNash.Email);
 | |
|             result.PhoneNumber.ShouldBe(johnNash.PhoneNumber);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task UpdateAsync()
 | |
|         {
 | |
|             //Arrange
 | |
|             _currentUser.Id.Returns(_testData.UserJohnId);
 | |
|             _currentUser.IsAuthenticated.Returns(true);
 | |
|             
 | |
|             var input = new UpdateProfileDto
 | |
|             {
 | |
|                 UserName = CreateRandomString(),
 | |
|                 PhoneNumber = CreateRandomPhoneNumber(),
 | |
|                 Email = CreateRandomEmail(),
 | |
|                 Name = CreateRandomString(),
 | |
|                 Surname = CreateRandomString()
 | |
|             };
 | |
| 
 | |
|             //Act
 | |
|             var result = await _profileAppService.UpdateAsync(input);
 | |
| 
 | |
|             //Assert
 | |
|             result.UserName.ShouldBe(input.UserName);
 | |
|             result.Email.ShouldBe(input.Email);
 | |
|             result.PhoneNumber.ShouldBe(input.PhoneNumber);
 | |
|             result.Surname.ShouldBe(input.Surname);
 | |
|             result.Name.ShouldBe(input.Name);
 | |
|         }
 | |
| 
 | |
|         private static string CreateRandomEmail()
 | |
|         {
 | |
|             return CreateRandomString() + "@abp.io";
 | |
|         }
 | |
| 
 | |
|         private static string CreateRandomString()
 | |
|         {
 | |
|             return Guid.NewGuid().ToString("N").Left(16);
 | |
|         }
 | |
| 
 | |
|         private static string CreateRandomPhoneNumber()
 | |
|         {
 | |
|             return RandomHelper.GetRandom(10000000, 100000000).ToString();
 | |
|         }
 | |
|     }
 | |
| }
 |