aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Services/UserTokenManagerTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-24 19:49:57 +0800
committercrupest <crupest@outlook.com>2020-01-24 19:49:57 +0800
commit21588701f25860145847c0740299867d9285d872 (patch)
tree86b5da6c2134034e66b149330606522fb4d81150 /Timeline.Tests/Services/UserTokenManagerTest.cs
parent6829ad0903aa3310ad29b74fc435611442569d5c (diff)
downloadtimeline-21588701f25860145847c0740299867d9285d872.tar.gz
timeline-21588701f25860145847c0740299867d9285d872.tar.bz2
timeline-21588701f25860145847c0740299867d9285d872.zip
Upgrade library version.
Diffstat (limited to 'Timeline.Tests/Services/UserTokenManagerTest.cs')
-rw-r--r--Timeline.Tests/Services/UserTokenManagerTest.cs32
1 files changed, 32 insertions, 0 deletions
diff --git a/Timeline.Tests/Services/UserTokenManagerTest.cs b/Timeline.Tests/Services/UserTokenManagerTest.cs
index 86ad84b3..a8ace778 100644
--- a/Timeline.Tests/Services/UserTokenManagerTest.cs
+++ b/Timeline.Tests/Services/UserTokenManagerTest.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Timeline.Models;
using Timeline.Services;
using Timeline.Tests.Helpers;
using Xunit;
@@ -48,5 +49,36 @@ namespace Timeline.Tests.Services
_mockUserService.Setup(s => s.VerifyCredential(username, password)).ThrowsAsync((Exception)Activator.CreateInstance(exceptionType));
await _service.Awaiting(s => s.CreateToken(username, password)).Should().ThrowAsync(exceptionType);
}
+
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public async Task CreateToken_Success(bool setExpireTime)
+ {
+ const string username = "uuu";
+ const string password = "ppp";
+ var mockExpireTime = setExpireTime ? (DateTime?)DateTime.Now : null;
+ var mockUserInfo = new UserInfo
+ {
+ Id = 1,
+ Username = username,
+ Administrator = false,
+ Version = 1
+ };
+ const string mockToken = "mocktokenaaaaaaa";
+
+ _mockUserService.Setup(s => s.VerifyCredential(username, password)).ReturnsAsync(mockUserInfo);
+ _mockUserTokenService.Setup(s => s.GenerateToken(
+ It.Is<UserTokenInfo>(userTokenInfo =>
+ userTokenInfo.Id == mockUserInfo.Id &&
+ userTokenInfo.Version == mockUserInfo.Version &&
+ userTokenInfo.ExpireAt == mockExpireTime))).Returns(mockToken);
+ (await _service.CreateToken(username, password, mockExpireTime))
+ .Should().BeEquivalentTo(new UserTokenCreateResult
+ {
+ Token = mockToken,
+ User = mockUserInfo
+ });
+ }
}
}