public void UpdateLeaseTest() { var dateTimeProvider = new DebugDateTimeProvider(); var storedSessionManager = new StoredSessionManager(dateTimeProvider); var leaseLength = TimeSpan.FromSeconds(1); var leaseLengthHalf = new TimeSpan(leaseLength.Ticks / 2); var key = "mysession"; var updateTime = dateTimeProvider.CurrentTime + leaseLengthHalf; var leaseEndBeforeUpdate = dateTimeProvider.CurrentTime + leaseLength; var leaseEndAfterUpdate = updateTime + leaseLength; var storedSession = storedSessionManager.Begin(key, leaseEndBeforeUpdate); dateTimeProvider.CurrentTime = updateTime; // We update the lease after a half lease length storedSession = storedSessionManager.UpdateLease(storedSession, leaseEndAfterUpdate); // Our time is the end of the original lease, before the update dateTimeProvider.CurrentTime = leaseEndBeforeUpdate; Assert.IsFalse(storedSessionManager.IsEnded(storedSession)); // Our time is the end the updatd lease. The session should be ended now. dateTimeProvider.CurrentTime = leaseEndAfterUpdate; Assert.IsTrue(storedSessionManager.IsEnded(storedSession)); Assert.AreEqual(2, storedSession.StorageVersion); // This should be a nop storedSession = storedSessionManager.UpdateLease(storedSession, leaseEndAfterUpdate + leaseLength); Assert.IsTrue(storedSessionManager.IsEnded(storedSession)); Assert.AreEqual(2, storedSession.StorageVersion); }
public void DecreaseLeaseTest() { var dateTimeProvider = new DebugDateTimeProvider(); var storedSessionManager = new StoredSessionManager(dateTimeProvider); var leaseLength = TimeSpan.FromSeconds(1); var leaseLengthHalf = new TimeSpan(leaseLength.Ticks / 2); var key = "mysession"; var leaseEnd = dateTimeProvider.CurrentTime + leaseLength; var updateTime = dateTimeProvider.CurrentTime + leaseLengthHalf; var storedSession = storedSessionManager.Begin(key, leaseEnd); storedSession = storedSessionManager.UpdateLease(storedSession, updateTime); Assert.AreEqual(1, storedSession.StorageVersion); Assert.AreEqual(leaseEnd, storedSession.LeaseEnd); }