public async Task WhenProjectionExpiresBeforeUpdateIsFinished_ExpiredDataIsStillAccessible() { // Reconfigure from setup _expiration = TimeSpan.FromSeconds(0.25); _updateDuration = TimeSpan.FromSeconds(0.5); _sut = Model.Create(_expiration, _projectionDataService, _sleeper); await _sut.GetLatestProjectionTime(); Thread.Sleep(_expiration.Add(TimeSpan.FromSeconds(0.25))); // Expire var query1 = await _sut.GetLatestProjectionTime(); // Trigger update Assert.That(query1, Is.Not.Null); Assert.That(_sut.State, Is.InstanceOf <UpdatingState <Department> >()); var query2 = await _sut.GetLatestProjectionTime(); Assert.That(query2, Is.Not.Null); Assert.That(query1, Is.EqualTo(query2), "The previous projection should be returned during the Updating state."); Thread.Sleep(_updateDuration); // Wait for update to finish Thread.Sleep(_expiration.Add(TimeSpan.FromSeconds(0.25))); // Expire Assert.That(_sut.State, Is.InstanceOf <ExpiredState <Department> >()); }
public async Task WhenInitialising_CreatesProjection_ThenReturnsCurrentItems() { var query1 = await _sut.GetLatestProjectionTime(); // Create projection var query2 = await _sut.GetLatestProjectionTime(); // Still in valid state Assert.That(query1, Is.EqualTo(query2), "The projection system should return the cached projection, when in Valid state."); }