Tests/Identity.Api.Tests/Controllers/UsersControllerTests.cs
/// <summary>
/// Given not null request
/// and identity service throws exception
/// When updating user password
/// Return server error
/// </summary>
Given not null request
and identity service throws exception
When updating user password
Return server error
Given not null request and identity service throws exception When updating user password Return server error
[Fact]
        public async Task UpdateUserPasswordAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError()
        {
            PasswordInitializationRequest request = new PasswordInitializationRequest
            {
                Login = "elbarto",
                NewPassword = "skiner wienner",
                OldPassword = "skinner the old wienner"
            };
            _identityServiceMock.Setup(mock => mock.UpdateUserPasswordAsync(request)).ThrowsAsync(new Exception());
            ObjectResult result = await _usersController.UpdateUserPasswordAsync(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.PasswordUpdateFailed, resultObject.ErrorMessages.First());
        }
[ Fact ] public async Task UpdateUserPasswordAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError ( ) { PasswordInitializationRequest request = new PasswordInitializationRequest { Login = " " , NewPassword = " " , OldPassword = " " } ; _identityServiceMock . Setup ( mock => mock . UpdateUserPasswordAsync ( request ) ) . ThrowsAsync ( new Exception ( ) ) ; ObjectResult result = await _usersController . UpdateUserPasswordAsync ( 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 . PasswordUpdateFailed , resultObject . ErrorMessages . First ( ) ) ; }
Given not null request
and identity service throws exception
When updating user password
Return server error
Given not null request and identity service throws exception When updating user password Return server error
// Arrange // Act // Assert