public void TriggeringEvictionStrategiesInThread() { var resetEvent = new AutoResetEvent(false); // non-signaled, all threads will block mockBeaconCache.When(c => c.RecordAdded += Arg.Any <EventHandler>()).Do(x => resetEvent.Set()); // also do reset event when executing mock strategy mockStrategyTwo.When(s => s.Execute()).Do(x => resetEvent.Set()); // first step start the eviction thread evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache, mockStrategyOne, mockStrategyTwo); evictor.Start(); resetEvent.WaitOne(); // wait until the evictor thread subscribed for (var i = 0; i < 10; i++) { mockBeaconCache.RecordAdded += Raise.Event(); resetEvent.WaitOne(); } // stop the thread var stopped = evictor.Stop(); // verify stop worked Assert.That(stopped, Is.True); Assert.That(evictor.IsAlive, Is.False); // ensure that the mocks were called accordingly mockStrategyOne.Received(10).Execute(); mockStrategyTwo.Received(10).Execute(); }
public void AfterStartingABeaconCacheEvictorItIsAlive() { // given evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache); // when var obtained = evictor.Start(); // then Assert.That(obtained, Is.True); Assert.That(evictor.IsAlive, Is.True); }
public void StoppingAnAliveBeaconCacheEvictor() { // given evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache); evictor.Start(); // when var obtained = evictor.Stop(); // then Assert.That(obtained, Is.True); Assert.That(evictor.IsAlive, Is.False); }