Ejemplo n.º 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));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public void Cancel_BeforeSimulation_DoesNothing()
 {
     var sut = new Simulator();
     Assert.DoesNotThrow(() => sut.Cancel(false));
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 6
0
 public void Wait_BeforeSimulation_DoesNothing()
 {
     var sut = new Simulator();
     Assert.DoesNotThrow(() => sut.Wait());
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
 public void RunAsync_NullStrategy_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), null, new SimulationSettings()));
 }
Ejemplo n.º 11
0
 public void RunAsync_NullSettings_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(CreateSyncTickersStub(), new Mock<StrategyBase>().Object, null));
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 18
0
 public void RunAsync_NullTickers_Throws()
 {
     var sut = new Simulator();
     Assert.Throws<ArgumentNullException>(() => sut.RunAsync(null, new Mock<StrategyBase>().Object, new SimulationSettings()));
 }