add unit test for repo throwing exception to characters controller tests
This commit is contained in:
@@ -3,6 +3,7 @@ using Moq;
|
|||||||
using server.Controllers.v1;
|
using server.Controllers.v1;
|
||||||
using server.Models;
|
using server.Models;
|
||||||
using server.Persistence.Repositories;
|
using server.Persistence.Repositories;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace tests.controllers
|
namespace tests.controllers
|
||||||
@@ -74,5 +75,23 @@ namespace tests.controllers
|
|||||||
Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)result.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)result.StatusCode);
|
||||||
Assert.Single(data);
|
Assert.Single(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetCharactersAsync_RepoThrowsException_Returns500StatusWithProblemDetail()
|
||||||
|
{
|
||||||
|
var filter = new CharacterFilter();
|
||||||
|
|
||||||
|
_mockRepo
|
||||||
|
.Setup(repo => repo.GetCharactersAsync(filter))
|
||||||
|
.Throws(new Exception());
|
||||||
|
|
||||||
|
var result = await _controller.GetCharactersAsync(filter) as ObjectResult;
|
||||||
|
var data = result.Value;
|
||||||
|
|
||||||
|
_mockRepo.Verify(repo => repo.GetCharactersAsync(It.IsAny<CharacterFilter>()), Times.Once());
|
||||||
|
Assert.IsType<ObjectResult>(result);
|
||||||
|
Assert.IsType<ProblemDetails>(data);
|
||||||
|
Assert.Equal(HttpStatusCode.InternalServerError, (HttpStatusCode)result.StatusCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user