Exemplo n.º 1
0
        public void WhenAbsoluteShouldHandleAbsoluteTime()
        {
            var inOneSecond = _clock.UtcNow.AddSeconds(1);
            var cached      = 0;

            // each call after the specified datetime will be reevaluated
            Func <int> retrieve = ()
                                  => _cacheManager.Get("testItem",
                                                       ctx => {
                ctx.Monitor(_clock.WhenUtc(inOneSecond));
                return(++cached);
            });

            Assert.Equal(retrieve(), 1);

            for (var i = 0; i < 10; i++)
            {
                Assert.Equal(retrieve(), 1);
            }

            _clock.Advance(TimeSpan.FromSeconds(1));

            Assert.Equal(retrieve(), 2);
            Assert.Equal(retrieve(), 3);
            Assert.Equal(retrieve(), 4);
        }
Exemplo n.º 2
0
        public void UsersWhoHaveNeverLoggedOutCanBeAuthenticated()
        {
            var user = (UserPart)_membershipService.CreateUser(new CreateUserParams("a", "b", "c", null, null, true));

            user.LastLoginUtc = _clock.UtcNow;
            _clock.Advance(TimeSpan.FromMinutes(1));

            Assert.That(_membershipValidationService.CanAuthenticateWithCookie(user), Is.True);
        }
Exemplo n.º 3
0
        public void ExpiredLockShouldBeAvailable()
        {
            ILockFile lockFile = null;

            _lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);

            _clock.Advance(DefaultLockFileManager.Expiration);
            Assert.False(_lockFileManager.IsLocked("foo.txt.lock"));
            Assert.Equal(_appDataFolder.ListFiles("").Count(), 1);
        }
Exemplo n.º 4
0
        public void StubClockCanBeManuallyAdvanced()
        {
            var clock  = new StubClock();
            var before = clock.UtcNow;

            clock.Advance(TimeSpan.FromMilliseconds(2));
            var mark = clock.UtcNow;

            clock.Advance(TimeSpan.FromMilliseconds(2));
            var after = clock.UtcNow;

            Assert.That(mark.Kind, Is.EqualTo(DateTimeKind.Utc));
            Assert.That(mark, Is.InRange(before, after));
            Assert.That(after.Subtract(before), Is.EqualTo(TimeSpan.FromMilliseconds(4)));
        }
Exemplo n.º 5
0
        public void WhenAbsoluteShouldHandleAbsoluteTime()
        {
            var inOneSecond = _clock.UtcNow.AddSeconds(1);
            var cached      = 0;

            Func <int> retrieve = ()
                                  => _cacheManager.Get("testItem",
                                                       ctx =>
            {
                ctx.Monitor(_clock.WhenUtc(inOneSecond));
                return(++cached);
            });

            Assert.That(retrieve(), Is.EqualTo(1));

            for (var i = 0; i < 10; i++)
            {
                Assert.That(retrieve(), Is.EqualTo(1));
            }
            _clock.Advance(TimeSpan.FromSeconds(1));

            Assert.That(retrieve(), Is.EqualTo(2));
            Assert.That(retrieve(), Is.EqualTo(3));
            Assert.That(retrieve(), Is.EqualTo(4));
        }
Exemplo n.º 6
0
        public void ShouldNotProcessIfDelayHasNotExpired()
        {
            _settings.Urls      = @"/";
            _settings.Delay     = 90;
            _settings.Scheduled = true;

            _webDownloader
            .Setup(w => w.Download("http://orchardproject.net/"))
            .Returns(new DownloadResult {
                Content = "Foo", StatusCode = HttpStatusCode.OK
            });

            _webDownloader
            .Setup(w => w.Download("http://orchardproject.net/About"))
            .Returns(new DownloadResult {
                Content = "Bar", StatusCode = HttpStatusCode.OK
            });

            _warmupUpdater.Generate();

            var warmupContent = _appDataFolder.ReadFile(_warmupFilename);

            Assert.That(warmupContent, Is.EqualTo(XmlConvert.ToString(_clock.UtcNow, XmlDateTimeSerializationMode.Utc)));

            _settings.Urls = @" /
                                /About";
            _clock.Advance(TimeSpan.FromMinutes(89));
            _warmupUpdater.EnsureGenerate();

            var files = _appDataFolder.ListFiles(WarmupFolder).ToList();

            Assert.That(files, Has.None.Matches <string>(x => x == _appDataFolder.Combine(WarmupFolder, WarmupUtility.EncodeUrl("http://orchardproject.net/About"))));

            warmupContent = _appDataFolder.ReadFile(_warmupFilename);
            Assert.That(warmupContent, Is.Not.EqualTo(XmlConvert.ToString(_clock.UtcNow, XmlDateTimeSerializationMode.Utc)));
        }
Exemplo n.º 7
0
 public void Process(IDictionary <string, object> parameters)
 {
     _clock.Advance(_simulatedProcessingTime);
 }