Tests/Identity.Api.Tests/Controllers/UsersControllerTests.cs
/// <summary>
/// Given not null request
/// and identity service throws exception
/// When creating user
/// Return server error
/// </summary>
Given not null request
and identity service throws exception
When creating user
Return server error
Given not null request and identity service throws exception When creating user Return server error
[Fact]
        public async Task CreateUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError()
        {
            UserCreationRequest request = new UserCreationRequest
            {
                Login = "niahahaw",
                Password = "mydummypassword",
                Email = "pig@gmail.com"
            };
            _identityServiceMock.Setup(mock => mock.CreateUserAsync(request)).ThrowsAsync(new Exception());
            ObjectResult result = await _usersController.CreateUserAsync(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.UserCreationFailed,
                resultObject.ErrorMessages.First());
        }
[ Fact ] public async Task CreateUserAsync_NotNullRequest_IdentityServiceThrowsException_ReturnServerError ( ) { UserCreationRequest request = new UserCreationRequest { Login = " " , Password = " " , Email = " " } ; _identityServiceMock . Setup ( mock => mock . CreateUserAsync ( request ) ) . ThrowsAsync ( new Exception ( ) ) ; ObjectResult result = await _usersController . CreateUserAsync ( 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 . UserCreationFailed , resultObject . ErrorMessages . First ( ) ) ; }
Given not null request
and identity service throws exception
When creating user
Return server error
Given not null request and identity service throws exception When creating user Return server error
// Arrange // Act // Assert