public void Cancel_AfterSimulation_DoesNothing() { var sut = new Simulator(); sut.RunAsync(CreateSyncTickersStub(), new EmptyStrategy(), new SimulationSettings()); sut.Wait(); Assert.DoesNotThrow(() => sut.Cancel(false)); }
public SimulationRunner(SimulationInput input) { this.input = input; this.simulator = new Simulator(); this.simulator.ProgressChanged += (s, e) => ReportProgress(new SimulationProgressStatus("Simulating", e.Current, e.Max)); this.simulator.SimulationEnded += (s, e) => EndSimulation(e); this.dispatcher = Dispatcher.CurrentDispatcher; }
public void EndInfo_IsRefEqualToEndEventArgs() { SimulationEndEventArgs endInfo = null; var sut = new Simulator(); sut.SimulationEnded += (s, e) => endInfo = e; var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(); Assert.Same(sut.EndInfo, endInfo); }
public void Cancel_BeforeSimulation_DoesNothing() { var sut = new Simulator(); Assert.DoesNotThrow(() => sut.Cancel(false)); }
public void Wait_WaitsSpecifiedTimeForSimulationCompletion() { bool executionHolder = true; var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Callback(() => { while (executionHolder);}).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(100); Assert.True(sut.IsBusy); executionHolder = false; }
public void Wait_BeforeSimulation_DoesNothing() { var sut = new Simulator(); Assert.DoesNotThrow(() => sut.Wait()); }
public void SyncTickers_InEndInfo_AreEqualToThosePassedToRunAsync() { var sut = new Simulator(); var syncTickers = CreateSyncTickersStub(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(syncTickers, strategyStub.Object, settings); sut.Wait(); Assert.Same(syncTickers, sut.EndInfo.Result.SyncTickers); }
public void SimulationEnded_AfterSimulation_Fires() { int endEvent_FireCount = 0; var sut = new Simulator(); sut.SimulationEnded += delegate { endEvent_FireCount++; }; var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(Timeout.Infinite); Assert.Equal<int>(1, endEvent_FireCount); }
public void EndResult_AfterSimulation_Completion() { var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(Timeout.Infinite); Assert.Equal<SimulationEndReason>(SimulationEndReason.Completion, sut.EndInfo.EndReason); }
public void RunAsync_NullStrategy_Throws() { var sut = new Simulator(); Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), null, new SimulationSettings())); }
public void RunAsync_NullSettings_Throws() { var sut = new Simulator(); Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), new Mock<StrategyBase>().Object, null)); }
public void RunAsync_IsBusyIsTrue_Thows() { bool executionHolder = true; var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Callback(() => { while (executionHolder); }).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); Assert.Throws<InvalidOperationException>(() => sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings)); executionHolder = false; }
public void ProgressChanged_DuringSimulation_Fires() { int changedEvent_FireCount = 0; var sut = new Simulator(); sut.ProgressChanged += delegate { changedEvent_FireCount++; }; var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(Timeout.Infinite); Assert.True(changedEvent_FireCount > 1); }
public void IsBusyProperty_DuringSimulation_IsTrue() { bool executionHolder = true; var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Callback(() => { while (executionHolder); }).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); bool isBusy = sut.IsBusy; executionHolder = false; Assert.True(isBusy); }
public void IsBusyProperty_AfterSimulation_IsFalse() { var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Wait(Timeout.Infinite); Assert.False(sut.IsBusy); }
public void InfinitiveSimulation_CanBeCanceled() { bool executionHolder = true; var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Callback(() => { while (executionHolder);}).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Cancel(); Assert.False(sut.IsBusy); }
public void EndResult_AfterCancelation_Cancelation() { bool executionHolder = true; var sut = new Simulator(); var strategyStub = new Mock<StrategyBase>(); strategyStub.Setup(x => x.Initialize()).Returns(true); strategyStub.Setup(x => x.Run()).Callback(() => { while (executionHolder);}).Returns(true); var settings = new SimulationSettingsImmutableDecorator(new SimulationSettings()); sut.RunAsync(CreateSyncTickersStub(), strategyStub.Object, settings); sut.Cancel(); Assert.Equal<SimulationEndReason>(SimulationEndReason.Cancellation, sut.EndInfo.EndReason); }
public void RunAsync_NullTickers_Throws() { var sut = new Simulator(); Assert.Throws<ArgumentNullException>(() => sut.RunAsync(null, new Mock<StrategyBase>().Object, new SimulationSettings())); }