diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-19 21:37:15 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-10-19 21:37:15 +0800 |
commit | b00cfa30a4f6a1c6d896d46da7dd063abf632cd3 (patch) | |
tree | e6168234660307247111ee369a0b2123823614eb /Timeline.Tests/Controllers/TokenControllerTest.cs | |
parent | 2984abc9aa0429380459e5b5b6fda2d20058041b (diff) | |
download | timeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.tar.gz timeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.tar.bz2 timeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.zip |
...
Diffstat (limited to 'Timeline.Tests/Controllers/TokenControllerTest.cs')
-rw-r--r-- | Timeline.Tests/Controllers/TokenControllerTest.cs | 21 |
1 files changed, 21 insertions, 0 deletions
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<object[]> 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<BadRequestObjectResult>()
+ .Which.Value.Should().BeAssignableTo<CommonResponse>()
+ .Which.Code.Should().Be(code);
+ }
+
// TODO! Verify unit tests
}
}
|