Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given not null request
/// and assignment operation has failed
/// when assigning a role to user
/// Return error message
/// </summary>
Given not null request
and assignment operation has failed
when assigning a role to user
Return error message
Given not null request and assignment operation has failed when assigning a role to user Return error message
[Fact]
        public async Task AssignRoleToUserAsync_RequestNotNull_FailingAssignment_ReturnErrorMessage()
        {
            UserRoleAssignmentRequest request = new UserRoleAssignmentRequest
            {
                Login = "nelson",
                RoleName = "bully"
            };
            User identityUser = new User
            {
                UserName = request.Login
            };
            string errorMessage = "haw-haw";
            _userManagerMock.Setup(mock => mock.FindByNameAsync(request.Login)).ReturnsAsync(identityUser);
            _userManagerMock.Setup(mock => mock.AddToRoleAsync(identityUser, request.RoleName)).ReturnsAsync(
                IdentityResult.Failed(new IdentityError { Description = errorMessage }));
            ResultMessage resultMessage = await _identityService.AssignRoleToUserAsync(request).ConfigureAwait(false);
            Assert.NotNull(resultMessage);
            Assert.False(resultMessage.OperationStatus);
            Assert.Equal(errorMessage, resultMessage.ErrorMessages.First());
        }
[ Fact ] public async Task AssignRoleToUserAsync_RequestNotNull_FailingAssignment_ReturnErrorMessage ( ) { UserRoleAssignmentRequest request = new UserRoleAssignmentRequest { Login = " " , RoleName = " " } ; User identityUser = new User { UserName = request . Login } ; string errorMessage = " " ; _userManagerMock . Setup ( mock => mock . FindByNameAsync ( request . Login ) ) . ReturnsAsync ( identityUser ) ; _userManagerMock . Setup ( mock => mock . AddToRoleAsync ( identityUser , request . RoleName ) ) . ReturnsAsync ( IdentityResult . Failed ( new IdentityError { Description = errorMessage } ) ) ; ResultMessage resultMessage = await _identityService . AssignRoleToUserAsync ( request ) . ConfigureAwait ( false ) ; Assert . NotNull ( resultMessage ) ; Assert . False ( resultMessage . OperationStatus ) ; Assert . Equal ( errorMessage , resultMessage . ErrorMessages . First ( ) ) ; }
Given not null request
and assignment operation has failed
when assigning a role to user
Return error message
Given not null request and assignment operation has failed when assigning a role to user Return error message
// Arrange // Act // Assert