public virtual void SetUp()
 {
     _projectionSystem      = _projectionSystem.Fake();
     _projectionDataService = _projectionDataService.Fake();
     _syncLockFactory       = _syncLockFactory.Fake();
     _sut = new CreatingState <Department>(_projectionSystem, _projectionDataService, _syncLockFactory);
 }
        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 virtual void SetUp()
 {
     _projectionSystem      = _projectionSystem.Fake();
     _projectionDataService = _projectionDataService.Fake();
     _syncLockFactory       = _syncLockFactory.Fake();
     _taskScheduler         = new DeterministicTaskScheduler();
     _sut = new UpdatingState <Department>(_projectionSystem, _projectionDataService, _syncLockFactory, _taskScheduler);
 }
예제 #4
0
 public IState <TItem> Create(IProjectionSystem <TItem> projectionSystem)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     return(new UpdatingState <TItem>(projectionSystem, _projectionDataService, _syncLockFactory, _taskScheduler));
 }
예제 #5
0
 public IState <TItem> Create(IProjectionSystem <TItem> projectionSystem)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     return(new ExpiredState <TItem>(projectionSystem));
 }
예제 #6
0
 public virtual void SetUp()
 {
     _projectionSystem = _projectionSystem.Fake();
     _timeout          = TimeSpan.FromMilliseconds(200);
     _sleeper          = _sleeper.Fake();
     _taskScheduler    = new DeterministicTaskScheduler();
     _sut = new ValidState <Department>(_projectionSystem, _timeout, _sleeper, _taskScheduler);
 }
예제 #7
0
 public ExpiredState(IProjectionSystem <TItem> projectionSystem)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     _projectionSystem = projectionSystem;
 }
 public void SetUp()
 {
     _expiration            = TimeSpan.FromSeconds(0.5);
     _updateDuration        = TimeSpan.FromSeconds(0.25);
     _projectionDataService = new Model.ProjectionDataServiceForTest(_updateDuration);
     _sleeper = new RealSleeper();
     _sut     = Model.Create(_expiration, _projectionDataService, _sleeper);
 }
        public IState <TItem> Create(IProjectionSystem <TItem> projectionSystem)
        {
            if (projectionSystem == null)
            {
                throw new ArgumentNullException(nameof(projectionSystem));
            }
            var timeout = _validStateTimeoutProvider.ProvideTimeout();

            return(new ValidState <TItem>(projectionSystem, timeout, _sleeper, _taskScheduler));
        }
예제 #10
0
 public CreatingState(IProjectionSystem <TItem> projectionSystem, IProjectionDataService <TItem> projectionDataService, ISyncLockFactory syncLockFactory)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     if (projectionDataService == null)
     {
         throw new ArgumentNullException(nameof(projectionDataService));
     }
     if (syncLockFactory == null)
     {
         throw new ArgumentNullException(nameof(syncLockFactory));
     }
     _projectionSystem      = projectionSystem;
     _projectionDataService = projectionDataService;
     _syncLockFactory       = syncLockFactory;
 }
예제 #11
0
 public ValidState(IProjectionSystem <TItem> projectionSystem, TimeSpan timeout, ISleeper sleeper, TaskScheduler taskScheduler)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     if (sleeper == null)
     {
         throw new ArgumentNullException(nameof(sleeper));
     }
     if (taskScheduler == null)
     {
         throw new ArgumentNullException(nameof(taskScheduler));
     }
     if (timeout <= TimeSpan.Zero)
     {
         throw new ArgumentException("An invalid projection timeout has been specified.", nameof(timeout));
     }
     _projectionSystem = projectionSystem;
     _timeout          = timeout;
     _sleeper          = sleeper;
     _taskScheduler    = taskScheduler;
 }
 public UpdatingState(IProjectionSystem <TItem> projectionSystem, IProjectionDataService <TItem> projectionDataService, ISyncLockFactory syncLockFactory, TaskScheduler taskScheduler)
 {
     if (projectionSystem == null)
     {
         throw new ArgumentNullException(nameof(projectionSystem));
     }
     if (projectionDataService == null)
     {
         throw new ArgumentNullException(nameof(projectionDataService));
     }
     if (syncLockFactory == null)
     {
         throw new ArgumentNullException(nameof(syncLockFactory));
     }
     if (taskScheduler == null)
     {
         throw new ArgumentNullException(nameof(taskScheduler));
     }
     _projectionSystem      = projectionSystem;
     _projectionDataService = projectionDataService;
     _syncLockFactory       = syncLockFactory;
     _taskScheduler         = taskScheduler;
 }
 public static async Task <DateTimeOffset?> GetLatestProjectionTime(this IProjectionSystem <Department> projectionSystem)
 {
     return(projectionSystem == null
 ? new DateTimeOffset?()
 : (await projectionSystem.GetProjection().ConfigureAwait(false)).Max(dep => dep.ProjectionTime));
 }
 public override void SetUp()
 {
     base.SetUp();
     _projectionSystem = _projectionSystem.Fake();
 }
예제 #15
0
 public virtual void SetUp()
 {
     _projectionSystem = _projectionSystem.Fake();
     _sut = new ExpiredState <Department>(_projectionSystem);
 }