public void Clone_InvokesCloneOnDecorated()
 {
     var settingsMock = new Mock<ISimulationSettings>();
     settingsMock.Setup(x => x.Clone()).Returns(settingsMock.Object);
     var sut = new SimulationSettingsImmutableDecorator(settingsMock.Object);
     sut.Clone();
     settingsMock.Verify(x => x.Clone(), Times.Once());
 }
 public void CannotModifySetting()
 {
     var sut = new SimulationSettingsImmutableDecorator(new SimulationSettings());
     var setting = sut.Get<CloseAllOnLastBarSetting>();
     bool defaultValue = setting.Value;
     setting.Value = !setting.Value;
     Assert.Equal<bool>(defaultValue, sut.Get<CloseAllOnLastBarSetting>().Value);
 }
Beispiel #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);
        }
Beispiel #4
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);
        }
Beispiel #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;
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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;
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }