예제 #1
0
        public void UpdateStopLossPriceToStableMinimumTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 200
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 150
            });

            AssertEmits(bus, () =>
            {
                processManager.Handle(new TenSecondsPassed {
                    Price = 200
                });
                processManager.Handle(new TenSecondsPassed {
                    Price = 150
                });
            }, new[]
            {
                new StopLossPriceUpdated {
                    NewStopLossPrice = (int)Math.Floor(ProcessManager.StopLossRatio * 150)
                }
            });
        }
예제 #2
0
        public void DoesNotEmitStopLossHitTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 89
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 90
            });

            AssertEmitsNothing(bus, () =>
            {
                processManager.Handle(new ThirteenSecondsPassed {
                    Price = 89
                });
                processManager.Handle(new ThirteenSecondsPassed {
                    Price = 90
                });
            });
        }
예제 #3
0
        public void DoesNotUpdateStopLossPriceIfSomeBelowCurrentTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 110
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 90
            });

            AssertEmitsNothing(bus, () =>
            {
                processManager.Handle(new TenSecondsPassed {
                    Price = 110
                });
                processManager.Handle(new TenSecondsPassed {
                    Price = 90
                });
            });
        }
예제 #4
0
        private static void AssertEmits(TestBus bus, Action action, IEnumerable <IMessage> expectedMessages)
        {
            bus.FiredMessages.Clear();
            action();
            var actual   = SerializeForComparison(bus.FiredMessages);
            var expected = SerializeForComparison(expectedMessages);

            Assert.That(actual, Is.EqualTo(expected));
        }
예제 #5
0
        public void EmitsStopLossPricesUpdatedTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            AssertEmits(
                bus,
                () => processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            }),
                new[]
            {
                new StopLossPriceUpdated {
                    NewStopLossPrice = 90
                }
            });
        }
예제 #6
0
        public void EmitStopLossHitTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            });
            processManager.Handle(new PriceUpdated {
                NewPricePerItem = 89
            });

            AssertEmits(bus, () => processManager.Handle(new ThirteenSecondsPassed {
                Price = 89
            }), new[]
            {
                new StopLossHitEvent(89)
            });
        }
예제 #7
0
        public void EmitsRemindersOnPriceUpdatedTest()
        {
            var bus            = new TestBus();
            var processManager = new ProcessManager(bus);

            processManager.Handle(new PositionAcquired {
                Amount = 1, PricePerItem = 100
            });

            AssertEmits(bus, () => processManager.Handle(new PriceUpdated {
                NewPricePerItem = 110
            }), new[]
            {
                new SendBackIn(TimeSpan.FromSeconds(10), new TenSecondsPassed {
                    Price = 110
                }),
                new SendBackIn(TimeSpan.FromSeconds(13), new ThirteenSecondsPassed {
                    Price = 110
                })
            });
        }
예제 #8
0
 private static void AssertEmitsNothing(TestBus bus, Action action)
 {
     AssertEmits(bus, action, Enumerable.Empty <IMessage>());
 }