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 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.º 3
0
 public void Wait_BeforeSimulation_DoesNothing()
 {
     var sut = new Simulator();
     Assert.DoesNotThrow(() => sut.Wait());
 }
Ejemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 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);
        }