Tests/Identity.Api.Tests/Controllers/UsersControllerTests.cs
/// <summary>
/// Given not null request
/// and identity service throws exception
/// When unassigning user from a role
/// Return server error
/// </summary>
Given not null request
and identity service throws exception
When unassigning user from a role
Return server error
Given not null request and identity service throws exception When unassigning user from a role Return server error
[Fact]
        public async Task UnassignRoleToUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError()
        {
            UserRoleAssignmentRequest request = new UserRoleAssignmentRequest
            {
                Login = "niahahaw",
                RoleName = "bully"
            };
            _identityServiceMock.Setup(mock => mock.UnassignRoleToUserAsync(request)).ThrowsAsync(new Exception());
            ObjectResult result = await _usersController.UnassignRoleToUserAsync(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.RoleUnassignmentRequestFailed,
                resultObject.ErrorMessages.First());
        }
[ Fact ] public async Task UnassignRoleToUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError ( ) { UserRoleAssignmentRequest request = new UserRoleAssignmentRequest { Login = " " , RoleName = " " } ; _identityServiceMock . Setup ( mock => mock . UnassignRoleToUserAsync ( request ) ) . ThrowsAsync ( new Exception ( ) ) ; ObjectResult result = await _usersController . UnassignRoleToUserAsync ( 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 . RoleUnassignmentRequestFailed , resultObject . ErrorMessages . First ( ) ) ; }
Given not null request
and identity service throws exception
When unassigning user from a role
Return server error
Given not null request and identity service throws exception When unassigning user from a role Return server error
// Arrange // Act // Assert