aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Controllers
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-19 21:37:15 +0800
committer杨宇千 <crupest@outlook.com>2019-10-19 21:37:15 +0800
commitb00cfa30a4f6a1c6d896d46da7dd063abf632cd3 (patch)
treee6168234660307247111ee369a0b2123823614eb /Timeline.Tests/Controllers
parent2984abc9aa0429380459e5b5b6fda2d20058041b (diff)
downloadtimeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.tar.gz
timeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.tar.bz2
timeline-b00cfa30a4f6a1c6d896d46da7dd063abf632cd3.zip
...
Diffstat (limited to 'Timeline.Tests/Controllers')
-rw-r--r--Timeline.Tests/Controllers/TokenControllerTest.cs21
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
}
}