Пример #1
0
        public void InstrumentAdditionRequestsAreSentCorrectly()
        {
            var instrumentSourceMock = new Mock <IInstrumentSource>();

            using (var instrumentsServer = new InstrumentsServer(5555, instrumentSourceMock.Object)) {
                instrumentsServer.StartServer();

                var rtdBrokerMock = new Mock <IRealTimeDataBroker>();

                using (var rtdServer = new RealTimeDataServer(5554, 5553, rtdBrokerMock.Object)) {
                    rtdServer.StartServer();

                    _client.Connect();

                    var exchange = new Exchange {
                        ID = 1, Name = "NYSE", Sessions = new List <ExchangeSession>(), Timezone = "Eastern Standard Time"
                    };
                    var datasource = new Datasource {
                        ID = 1, Name = "Yahoo"
                    };
                    var instrument = new Instrument
                    {
                        Symbol           = "SPY",
                        UnderlyingSymbol = "SPY",
                        Type             = InstrumentType.Stock,
                        Currency         = "USD",
                        Exchange         = exchange,
                        Datasource       = datasource,
                        Multiplier       = 1
                    };

                    instrumentSourceMock.Setup(x => x.AddInstrument(It.IsAny <Instrument>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns(instrument);

                    var result = _client.AddInstrument(instrument);

                    Thread.Sleep(50);

                    Assert.IsTrue(result != null);

                    instrumentSourceMock.Verify(
                        x => x.AddInstrument(
                            It.Is <Instrument>(
                                y =>
                                y.Symbol == "SPY" &&
                                y.Exchange != null &&
                                y.Exchange.Name == "NYSE" &&
                                y.Datasource != null &&
                                y.Datasource.Name == "Yahoo" &&
                                y.Type == InstrumentType.Stock &&
                                y.Currency == "USD" &&
                                y.Multiplier == 1),
                            It.Is <bool>(y => y == false),
                            It.Is <bool>(y => y)));

                    rtdServer.StopServer();
                }

                instrumentsServer.StopServer();
            }
        }