Ejemplo n.º 1
0
            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);
            }
Ejemplo n.º 2
0
        public void CountDownTimerStopsAt0()
        {
            var inProgressTimer = _countDownTimer.Start();

            Now = Now.AddMinutes(_defaultTimerLength.Minutes + 5);
            Assert.Equal(TimeSpan.Zero, inProgressTimer.TimeLeft);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public void CountDownTimerCalculatesTimeLeft()
        {
            var startedTimer = _countDownTimer.Start();

            Now = Now.AddMinutes(5);
            Assert.Equal(TimeSpan.FromMinutes(10), startedTimer.TimeLeft);
            Assert.IsType <InProgressTimer>(startedTimer);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
            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);
            }
Ejemplo n.º 8
0
            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);
            }
Ejemplo n.º 9
0
            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);
            }
Ejemplo n.º 10
0
            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);
            }
Ejemplo n.º 11
0
            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);
            }
Ejemplo n.º 12
0
        public void ExpiryIsSetToOneWeekByDefault()
        {
            CachedCssResponse.WriteHeaders();

            HttpCache.Verify(c => c.SetExpires(Now.AddMinutes(DotlessConfiguration.DefaultHttpExpiryInMinutes)), Times.Once());
        }