diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs new file mode 100644 index 0000000..21744f9 --- /dev/null +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using AutoFixture.Xunit2; +using Microsoft.AspNetCore.Mvc; +using Moq; +using Retroactiune.Controllers; +using Retroactiune.DataTransferObjects; +using Retroactiune.Models; +using Retroactiune.Services; +using Xunit; + +namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers +{ + public class TestTokensController + { + [Fact] + public async Task Test_GenerateTokens_InexistentFeedbackReceiver() + { + // Arrange + var feedbackService = new Mock(); + var tokens = new Mock(); + + // Test + var controller = new TokensController(feedbackService.Object, tokens.Object); + var result = await controller.GenerateTokens(new GenerateTokensDto()); + + // Assert + Assert.IsType(result); + } + + [Theory, AutoData] + public async Task Test_GenerateTokens_Success(FeedbackReceiver randFedFeedbackReceiver) + { + // Arrange + var feedbackService = new Mock(); + var tokens = new Mock(); + + feedbackService.Setup(i => i.FindAsync(It.IsAny>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(new[] {randFedFeedbackReceiver}); + + // Test + var controller = new TokensController(feedbackService.Object, tokens.Object); + var result = await controller.GenerateTokens(new GenerateTokensDto + { + NumberOfTokens = 2, + FeedbackReceiverId = "froid", + }); + + // Assert + Assert.IsType(result); + tokens.Verify(i => i.GenerateTokensAsync(2, "froid", null), Times.Once); + } + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/Controllers/TokensController.cs b/Retroactiune.WebAPI/Controllers/TokensController.cs index f15d1d7..c276f0f 100644 --- a/Retroactiune.WebAPI/Controllers/TokensController.cs +++ b/Retroactiune.WebAPI/Controllers/TokensController.cs @@ -23,7 +23,7 @@ namespace Retroactiune.Controllers _tokensService = tokensService; } - // TODO: Test unit & integrations. + // TODO: Test integration. /// /// Creates a new batch of tokens, the tokens are tied to a FeedbackReceiver and are used by the client /// when leaving Feedback. diff --git a/Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs b/Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs index e3ee189..4a3e59b 100644 --- a/Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs +++ b/Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs @@ -13,7 +13,6 @@ namespace Retroactiune.DataAnnotations /// True if the date is null or in the future, false otherwise. public override bool IsValid(object value) { - // TODO: Test var now = DateTime.UtcNow; var date = value as DateTime?; return !(date <= now);