finished writing tests for getcharacterbyidasync
This commit is contained in:
@@ -24,7 +24,7 @@ namespace server.tests.unitTests
|
||||
{
|
||||
var filter = new CharacterFilter();
|
||||
|
||||
var characters = new List<Character> {new Character(), new Character()};
|
||||
var characters = new List<Character> { new Character(), new Character() };
|
||||
|
||||
_mockRepo
|
||||
.Setup(repo => repo.GetCharactersAsync(filter))
|
||||
@@ -32,9 +32,9 @@ namespace server.tests.unitTests
|
||||
|
||||
var response = await _controller.GetCharactersAsync(filter) as ObjectResult;
|
||||
var data = response.Value as List<Character>;
|
||||
|
||||
|
||||
_mockRepo.Verify(repo => repo.GetCharactersAsync(It.IsAny<CharacterFilter>()), Times.Once());
|
||||
|
||||
|
||||
response.Should().NotBeNull();
|
||||
response.Should().BeOfType<OkObjectResult>();
|
||||
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
|
||||
@@ -66,5 +66,51 @@ namespace server.tests.unitTests
|
||||
details.Should().NotBeNull();
|
||||
details.Should().BeOfType<ProblemDetails>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetCharacterByIdAsync_RepoThrowsException_Returns500StatusCodeWithProblemDetails()
|
||||
{
|
||||
var characterId = "62b7d5506c1b407771829926";
|
||||
|
||||
_mockRepo
|
||||
.Setup(repo => repo.GetCharacterByIdAsync(characterId))
|
||||
.Throws(new Exception());
|
||||
|
||||
var response = await _controller.GetCharacterByIdAsync(characterId) as ObjectResult;
|
||||
|
||||
var details = response.Value;
|
||||
|
||||
_mockRepo.Verify(repo => repo.GetCharacterByIdAsync(It.IsAny<string>()), Times.Once());
|
||||
|
||||
response.Should().NotBeNull();
|
||||
response.Should().BeOfType<ObjectResult>();
|
||||
response.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
|
||||
|
||||
details.Should().NotBeNull();
|
||||
details.Should().BeOfType<ProblemDetails>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetCharacterByIdAsync_ValidCharacterId_Returns200StatusCodeWithCharacter()
|
||||
{
|
||||
var characterId = "62b7d5506c1b407771829926";
|
||||
|
||||
_mockRepo
|
||||
.Setup(repo => repo.GetCharacterByIdAsync(characterId))
|
||||
.ReturnsAsync(new Character());
|
||||
|
||||
var response = await _controller.GetCharacterByIdAsync(characterId) as ObjectResult;
|
||||
|
||||
var character = response.Value;
|
||||
|
||||
_mockRepo.Verify(repo => repo.GetCharacterByIdAsync(It.IsAny<string>()), Times.Once());
|
||||
|
||||
response.Should().NotBeNull();
|
||||
response.Should().BeOfType<OkObjectResult>();
|
||||
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
|
||||
|
||||
character.Should().NotBeNull();
|
||||
character.Should().BeOfType<Character>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user