Tests/Identity.Api.Tests/Controllers/UsersControllerTests.cs
/// <summary>
/// Given not null request
/// and identity service throws exception
/// When assigning role to user
/// Return server error
/// </summary>
Given not null request
and identity service throws exception
When assigning role to user
Return server error
Given not null request and identity service throws exception When assigning role to user Return server error
[Fact]
        public async Task AssignRoleToUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError()
        {
            UserRoleAssignmentRequest request = new UserRoleAssignmentRequest
            {
                Login = "niahahaw",
                RoleName = "bully"
            };
            _identityServiceMock.Setup(mock => mock.AssignRoleToUserAsync(request)).ThrowsAsync(new Exception());
            ObjectResult result = await _usersController.AssignRoleToUserAsync(request).ConfigureAwait(false)
                as ObjectResult;
            Assert.NotNull(result);
            Assert.Equal(500, result.StatusCode);
            ResultMessage resultObject = result.Value as ResultMessage;
            Assert.False(resultObject.OperationStatus);
            Assert.Equal(MessageResources.RoleAssignmentFailed,
                resultObject.ErrorMessages.First());
        }
[ Fact ] public async Task AssignRoleToUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError ( ) { UserRoleAssignmentRequest request = new UserRoleAssignmentRequest { Login = " " , RoleName = " " } ; _identityServiceMock . Setup ( mock => mock . AssignRoleToUserAsync ( request ) ) . ThrowsAsync ( new Exception ( ) ) ; ObjectResult result = await _usersController . AssignRoleToUserAsync ( request ) . ConfigureAwait ( false ) as ObjectResult ; Assert . NotNull ( result ) ; Assert . Equal ( 500 , result . StatusCode ) ; ResultMessage resultObject = result . Value as ResultMessage ; Assert . False ( resultObject . OperationStatus ) ; Assert . Equal ( MessageResources . RoleAssignmentFailed , resultObject . ErrorMessages . First ( ) ) ; }
Given not null request
and identity service throws exception
When assigning role to user
Return server error
Given not null request and identity service throws exception When assigning role to user Return server error
// Arrange // Act // Assert