From b00cfa30a4f6a1c6d896d46da7dd063abf632cd3 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sat, 19 Oct 2019 21:37:15 +0800 Subject: ... --- Timeline.Tests/Controllers/TokenControllerTest.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Timeline.Tests/Controllers/TokenControllerTest.cs') diff --git a/Timeline.Tests/Controllers/TokenControllerTest.cs b/Timeline.Tests/Controllers/TokenControllerTest.cs index 60ba75dc..8b1cf071 100644 --- a/Timeline.Tests/Controllers/TokenControllerTest.cs +++ b/Timeline.Tests/Controllers/TokenControllerTest.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging.Abstractions; using Moq; using System; +using System.Collections.Generic; using System.Threading.Tasks; using Timeline.Controllers; using Timeline.Models.Http; @@ -90,6 +91,26 @@ namespace Timeline.Tests.Controllers .Which.User.Should().BeEquivalentTo(MockUser.User.Info); } + public static IEnumerable Verify_BadRequest_Data() + { + yield return new object[] { new JwtTokenVerifyException(JwtTokenVerifyException.ErrorCodes.Expired), Verify.Expired }; + yield return new object[] { new JwtTokenVerifyException(JwtTokenVerifyException.ErrorCodes.IdClaimBadFormat), Verify.BadFormat }; + yield return new object[] { new BadTokenVersionException(), Verify.OldVersion }; + yield return new object[] { new UserNotExistException(), Verify.UserNotExist }; + } + + [Theory] + [MemberData(nameof(Verify_BadRequest_Data))] + public async Task Verify_BadRequest(Exception e, int code) + { + const string token = "aaaaaaaaaaaaaa"; + _mockUserService.Setup(s => s.VerifyToken(token)).ThrowsAsync(e); + var action = await _controller.Verify(new VerifyTokenRequest { Token = token }); + action.Should().BeAssignableTo() + .Which.Value.Should().BeAssignableTo() + .Which.Code.Should().Be(code); + } + // TODO! Verify unit tests } } -- cgit v1.2.3