Exemple #1
0
 public void Cancel_AfterSimulation_DoesNothing()
 {
     var sut = new Simulator();
     sut.RunAsync(CreateSyncTickersStub(), new EmptyStrategy(), new SimulationSettings());
     sut.Wait();
     Assert.DoesNotThrow(() => sut.Cancel(false));
 }
Exemple #2
0
 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;
 }
Exemple #3
0
        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);
        }
Exemple #4
0
 public void Cancel_BeforeSimulation_DoesNothing()
 {
     var sut = new Simulator();
     Assert.DoesNotThrow(() => sut.Cancel(false));
 }
Exemple #5
0
        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;
        }
Exemple #6
0
 public void Wait_BeforeSimulation_DoesNothing()
 {
     var sut = new Simulator();
     Assert.DoesNotThrow(() => sut.Wait());
 }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 public void RunAsync_NullStrategy_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), null, new SimulationSettings()));
 }
Exemple #11
0
 public void RunAsync_NullSettings_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), new Mock<StrategyBase>().Object, null));
 }
Exemple #12
0
        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;
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
 public void RunAsync_NullTickers_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(null, new Mock<StrategyBase>().Object, new SimulationSettings()));
 }