public async Task WhenContextIsValid_AndRefreshTokenFoundAndExpired_ItShouldCreateARefreshToken() { var context = new AuthenticationTokenCreateContext( new OwinContext(this.environment), this.secureDataFormat.Object, Ticket); context.OwinContext.Set <int>(Constants.TokenRefreshTokenLifeTimeKey, RefreshTokenLifetimeMinutes); this.tryGetRefreshToken.Setup(v => v.HandleAsync(new TryGetRefreshTokenQuery(new ClientId(ClientId), new Username(Username)))) .ReturnsAsync(new RefreshToken { ExpiresDate = Now }); SetRefreshTokenCommand command = null; this.createRefreshToken.Setup(v => v.HandleAsync(It.IsAny <SetRefreshTokenCommand>())) .Callback <SetRefreshTokenCommand>(v => command = v) .Returns(Task.FromResult(0)); await this.target.CreateAsync(context); Assert.IsNotNull(command); Assert.AreEqual(ClientId, command.ClientId.Value); Assert.AreEqual(Username, command.Username.Value); Assert.AreEqual(ProtectedTicket, command.ProtectedTicket); Assert.AreEqual(Now, command.IssuedDate); Assert.AreEqual(Now.AddMinutes(RefreshTokenLifetimeMinutes), command.ExpiresDate); Assert.IsNotNull(command.RefreshTokenId); Assert.AreEqual(context.Token, command.RefreshTokenId.Value); }
public void CountDownTimerStopsAt0() { var inProgressTimer = _countDownTimer.Start(); Now = Now.AddMinutes(_defaultTimerLength.Minutes + 5); Assert.Equal(TimeSpan.Zero, inProgressTimer.TimeLeft); }
public async Task <List <WeatherEntity> > GetLastMinutes(int locationId, int minutes = 60) { var lastTime = Now.AddMinutes(-minutes); var weather = await Db.Weathers.Where(x => x.LocationId == locationId && x.CreatedAt > lastTime).OrderByDescending(x => x.Id).ToListAsync(); return(weather); }
public void CountDownTimerCalculatesTimeLeft() { var startedTimer = _countDownTimer.Start(); Now = Now.AddMinutes(5); Assert.Equal(TimeSpan.FromMinutes(10), startedTimer.TimeLeft); Assert.IsType <InProgressTimer>(startedTimer); }
public void CustomExpiryCanBeSetThroughConfiguration() { const int expiryInMinutes = 5; CachedCssResponse = new CachedCssResponse(Http.Object, false, expiryInMinutes, Clock.Object); CachedCssResponse.WriteHeaders(); HttpCache.Verify(c => c.SetExpires(Now.AddMinutes(expiryInMinutes)), Times.Once()); }
public void CountDownTimerCanBeStopped() { var startedTimer = _countDownTimer.Start(); Now = Now.AddMinutes(5); var stoppedTimer = startedTimer.Stop(); Now = Now.AddMinutes(5); var fromMinutes = TimeSpan.FromMinutes(10); Assert.Equal(fromMinutes, stoppedTimer.TimeLeft); Assert.IsType <PausedTimer>(stoppedTimer); }
public async void PendingBeforeDeadline_NotRequested() { var service = new PushSyncService(MockPushSyncStore(new[] { new SyncAction() { Id = "locationSync", Deadline = Now.AddMinutes(15) } }).Object, MockDigitPushServiceCLient(), Mock.Of <IFocusStore>()); var res = await service.RequestLocationSync(userId, Now, Now.AddMinutes(30)); Assert.False(res.SyncRequested); Assert.Equal(Now.AddMinutes(15), res.SyncPendingFor); }
public async void Earlier_NotAdded() { var mockPushSyncStore = MockPushSyncStore(new[] { new SyncAction() { Id = "locationSync", Deadline = Now.AddMinutes(10) } }); var service = new PushSyncService(mockPushSyncStore.Object, MockDigitPushServiceCLient(), Mock.Of <IFocusStore>()); await service.SetLocationRequestedExternal(userId, Now.AddMinutes(25)); mockPushSyncStore.Verify(v => v.AddSyncAction(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTimeOffset>()), Times.Never); }
public async void None_Add() { var mockPushSyncStore = MockPushSyncStore(new[] { new SyncAction() { Id = "other", Deadline = Now.AddMinutes(10) } }); var service = new PushSyncService(mockPushSyncStore.Object, MockDigitPushServiceCLient(), Mock.Of <IFocusStore>()); await service.SetLocationRequestedExternal(userId, Now.AddMinutes(25)); mockPushSyncStore.Verify(v => v.AddSyncAction(userId, "locationSync", Now.AddMinutes(25)), Times.Once); }
public async void RequestPending_NotRequested() { var missedDeadline = Now.AddMinutes(-10); var service = new PushSyncService(MockPushSyncStore(new[] { new SyncAction() { Id = "test", Deadline = missedDeadline } }).Object, MockDigitPushServiceCLient(), Mock.Of <IFocusStore>()); var res = await service.RequestLocationSync(userId, Now, Now); Assert.False(res.SyncRequested); Assert.Equal(missedDeadline, res.SyncPendingFor); }
public async Task WhenAttributes_ItShouldReturnTimeSinceLastLeaseEndTime() { this.SetupAquireMocks(); await this.target.AcquireLeaseAsync(); this.blob.Setup(v => v.FetchAttributesAsync(this.cancellationToken)).Returns(Task.FromResult(0)).Verifiable(); var metadata = new Dictionary <string, string>(); metadata.Add(Azure.Constants.LeaseEndTimestampMetadataKey, Now.AddMinutes(-12).ToIso8601String()); this.blob.SetupGet(v => v.Metadata).Returns(metadata); var result = await this.target.GetTimeSinceLastLeaseAsync(); this.blob.Verify(); Assert.AreEqual(TimeSpan.FromMinutes(12), result); }
public void ExpiryIsSetToOneWeekByDefault() { CachedCssResponse.WriteHeaders(); HttpCache.Verify(c => c.SetExpires(Now.AddMinutes(DotlessConfiguration.DefaultHttpExpiryInMinutes)), Times.Once()); }