diff options
Diffstat (limited to 'Timeline.Tests')
-rw-r--r-- | Timeline.Tests/Helpers/ParameterInfoAssertions.cs | 3 | ||||
-rw-r--r-- | Timeline.Tests/Services/UserTokenManagerTest.cs | 52 |
2 files changed, 52 insertions, 3 deletions
diff --git a/Timeline.Tests/Helpers/ParameterInfoAssertions.cs b/Timeline.Tests/Helpers/ParameterInfoAssertions.cs index e3becee1..d3e5a41e 100644 --- a/Timeline.Tests/Helpers/ParameterInfoAssertions.cs +++ b/Timeline.Tests/Helpers/ParameterInfoAssertions.cs @@ -3,10 +3,7 @@ using FluentAssertions.Execution; using FluentAssertions.Formatting;
using FluentAssertions.Primitives;
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Reflection;
-using System.Threading.Tasks;
namespace Timeline.Tests.Helpers
{
diff --git a/Timeline.Tests/Services/UserTokenManagerTest.cs b/Timeline.Tests/Services/UserTokenManagerTest.cs new file mode 100644 index 00000000..86ad84b3 --- /dev/null +++ b/Timeline.Tests/Services/UserTokenManagerTest.cs @@ -0,0 +1,52 @@ +using FluentAssertions;
+using Microsoft.Extensions.Logging.Abstractions;
+using Moq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Timeline.Services;
+using Timeline.Tests.Helpers;
+using Xunit;
+
+namespace Timeline.Tests.Services
+{
+ public class UserTokenManagerTest
+ {
+ private readonly UserTokenManager _service;
+
+ private readonly Mock<IUserService> _mockUserService;
+ private readonly Mock<IUserTokenService> _mockUserTokenService;
+ private readonly TestClock _mockClock;
+
+ public UserTokenManagerTest()
+ {
+ _mockUserService = new Mock<IUserService>();
+ _mockUserTokenService = new Mock<IUserTokenService>();
+ _mockClock = new TestClock();
+
+ _service = new UserTokenManager(NullLogger<UserTokenManager>.Instance, _mockUserService.Object, _mockUserTokenService.Object, _mockClock);
+ }
+
+ [Theory]
+ [InlineData(null, "aaa", "username")]
+ [InlineData("aaa", null, "password")]
+ public void CreateToken_NullArgument(string username, string password, string paramName)
+ {
+ _service.Invoking(s => s.CreateToken(username, password)).Should().Throw<ArgumentNullException>()
+ .Which.ParamName.Should().Be(paramName);
+ }
+
+ [Theory]
+ [InlineData(typeof(UsernameBadFormatException))]
+ [InlineData(typeof(UserNotExistException))]
+ [InlineData(typeof(BadPasswordException))]
+ public async Task CreateToken_VerifyCredential_Throw(Type exceptionType)
+ {
+ const string username = "uuu";
+ const string password = "ppp";
+ _mockUserService.Setup(s => s.VerifyCredential(username, password)).ThrowsAsync((Exception)Activator.CreateInstance(exceptionType));
+ await _service.Awaiting(s => s.CreateToken(username, password)).Should().ThrowAsync(exceptionType);
+ }
+ }
+}
|