public void Advance() { FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L)); Duration d = Duration.FromTicks(25); clock.Advance(d); Assert.AreEqual(125, clock.GetCurrentInstant().ToUnixTimeTicks()); }
public void Advance() { FakeClock clock = new FakeClock(new Instant(100L)); Duration d = new Duration(25); clock.Advance(d); Assert.AreEqual(125, clock.Now.Ticks); }
public void GetSession_RemovesSession_IfSessionIsExpired() { var session = _sut.NewSession(); _clock.Advance(Session.DefaultExpiryTime + Duration.FromSeconds(1)); var result = _sut.Get(session.Id); result.IsNone.Should().BeTrue(); _dbContext.Sessions.Find(session.Id).Should().BeNull(); }
public void AuthenticateCommand_AuthUser_SuccessAuth() { // ---- Arrange ---- const string email = "*****@*****.**"; const string name = "Test user"; const string password = "******"; var passwordHash = AuthUtils.GetMd5Hash(password); var clock = new FakeClock(SystemClock.Instance.GetCurrentInstant()); var testUser = new UserIdentityModel( Guid.NewGuid(), email, name, "user", passwordHash, clock.GetCurrentInstant()); _authRepositoryMock.Setup(r => r.GetUserIdentity(email)) .ReturnsAsync(() => testUser); var command = new AuthenticateUserCommand(email, password); var handler = new AuthenticateUserCommandHandler(_repositoryProviderMock.Object, _configuration) { Clock = clock }; AuthAccessModel result = null; var lifetime = DurationUtils.FromString( _configuration[$"{AuthUtils.Jwt.ConfigKeys.Section}:{AuthUtils.Jwt.ConfigKeys.LifetimeKey}"]); // ---- Act ---- Assert.DoesNotThrowAsync(async() => { result = await handler.Handle(command, CancellationToken.None); }); clock.Advance(lifetime); // for check expires token instant // ---- Assert ---- Assert.IsNotNull(result); Assert.AreEqual(testUser.Id, result.Id); Assert.AreEqual(testUser.Email, result.Email); Assert.AreEqual(clock.GetCurrentInstant(), result.ExpiresAt); Assert.AreEqual(clock.GetCurrentInstant(), result.ExpiresAt); Assert.AreEqual("user", testUser.Role); Assert.IsNotEmpty(result.Token); _authRepositoryMock.Verify(r => r.GetUserIdentity(email), Times.Once); }