public void AsTimePasses_TheLoopAction_ShouldBePerformedMultipleTimes() { "Given a loop that increments a call counter every 5 ticks" ._(() => { var loop = new RxLoopCancellable(_testSchedulers, _action, TimeSpan.FromTicks(5)); _tokenSource = new CancellationTokenSource(); loop.StartLoop(_tokenSource.Token); }); "Given an initial call count of 0" ._(() => { _callCount.Should().Be(0); }); "Then the call count should be one after 4 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(4)); _callCount.Should().Be(1); }); "Then the call count should be 2 after 5 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(2)); _callCount.Should().Be(2); }); "Then the call count should be 3 after 10 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(5)); _callCount.Should().Be(3); }); "Then the call count should be 11 after 50 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(40)); _callCount.Should().Be(11); }); "Then let's cancel the loop" ._(() => { _tokenSource.Cancel(); }); "Then the call count should not change while time elapses" ._(() => { _testSchedulers.AdvanceAllBy(1000.Ticks()); _callCount.Should().Be(11); }); }
public void AsTimePasses_TheLoopAction_ShouldBePerformedMultipleTimes() { "Given a loop that increments a call counter every 5 ticks" ._(() => { var loop = new RxLoop(_testSchedulers, _action, TimeSpan.FromTicks(5)); loop.PrintDebugOutput = true; loop.StartLoop(); }); "Given an initial call count of 0" ._(() => { CallCount.Should().Be(0); }); "Then the call count should be zero after 4 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(4)); CallCount.Should().Be(0); }); "Then the call count should be 1 after 5 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(2)); CallCount.Should().Be(1); }); "Then the call count should be 2 after 10 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(5)); CallCount.Should().Be(2); }); "Then the call count should be 10 after 50 ticks" ._(() => { _testSchedulers.AdvanceAllBy(TimeSpan.FromTicks(40)); CallCount.Should().Be(10); }); }