diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs index 0722866..1134ff0 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs @@ -172,5 +172,47 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers Assert.IsType(result); tokens.Verify(i => i.FindAsync(It.IsAny()), Times.Once); } + + [Fact] + public async Task Test_CheckToken_NotFound() + { + // Arrange + var mapper = TestUtils.GetMapper(); + var feedbackService = new Mock(); + var tokens = new Mock(); + var logger = new Mock>(); + tokens.Setup(i => i.FindAsync(It.IsAny())) + .ReturnsAsync(new List()); + + // Test + var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper); + var result = await controller.CheckToken("random"); + + // Assert + var checkResult = (CheckTokenDto) ((ObjectResult) result).Value; + Assert.IsType(result); + Assert.False(checkResult.IsValid); + } + + [Fact] + public async Task Test_CheckToken_Valid() + { + // Arrange + var mapper = TestUtils.GetMapper(); + var feedbackService = new Mock(); + var tokens = new Mock(); + var logger = new Mock>(); + tokens.Setup(i => i.FindAsync(It.IsAny())) + .ReturnsAsync(new List { new Token() }); + + // Test + var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper); + var result = await controller.CheckToken("random"); + + // Assert + var checkResult = (CheckTokenDto) ((ObjectResult) result).Value; + Assert.IsType(result); + Assert.True(checkResult.IsValid); + } } } \ No newline at end of file diff --git a/Retroactiune.WebAPI/Controllers/TokensController.cs b/Retroactiune.WebAPI/Controllers/TokensController.cs index 09e3cff..c128295 100644 --- a/Retroactiune.WebAPI/Controllers/TokensController.cs +++ b/Retroactiune.WebAPI/Controllers/TokensController.cs @@ -160,13 +160,12 @@ namespace Retroactiune.Controllers string guid ) { - // TODO: Unit test. - var response = await _tokensService.FindAsync(new TokenListFilters - { - Ids = new[] {guid} - }); try { + var response = await _tokensService.FindAsync(new TokenListFilters + { + Ids = new[] {guid} + }); var token = response.ElementAt(0); return Ok(new CheckTokenDto { @@ -180,7 +179,7 @@ namespace Retroactiune.Controllers { IsValid = false }); - } + } } } } \ No newline at end of file