public void Setup() { _mockConnection = MockRepository.GenerateMock<Connection>("username", "password", "http://couldBeAnyUrl/TradingApi"); _mockOpenPositionsQuery = MockRepository.GenerateMock<OpenPositionsQuery>(_mockConnection); _mockOrderQuery = MockRepository.GenerateMock<OrderQuery>(_mockConnection); _mockStopLimitOrderHistoryQuery = MockRepository.GenerateMock<StopLimitOrderHistoryQuery>(_mockConnection); _mockNewStopLimitOrderPlacer = MockRepository.GenerateMock<NewStopLimitOrderPlacer>(_mockConnection); _mockNewTradeOrderPlacer = MockRepository.GenerateMock<NewTradeOrderPlacer>(_mockConnection); _mockCancelOrderPlacer = MockRepository.GenerateMock<CancelOrderPlacer>(_mockConnection); _mockActiveStopLimitOrderQuery = MockRepository.GenerateMock<ActiveStopLimitOrderQuery>(_mockConnection); _mockTradeHistoryQuery = MockRepository.GenerateMock<TradeHistoryQuery>(_mockConnection); _orderService = new OrderService(_mockOpenPositionsQuery, _mockOrderQuery, _mockStopLimitOrderHistoryQuery, _mockNewStopLimitOrderPlacer, _mockNewTradeOrderPlacer, _mockCancelOrderPlacer, _mockActiveStopLimitOrderQuery, _mockTradeHistoryQuery); }
public void OrderServicePropertyLazyLoadsTheServiceTheFirstTimeItsCalled() { // Arrange var expectedOrderServiceReturned = new OrderService( new OpenPositionsQuery(_mockApiConnection.CoreConnection), new OrderQuery(_mockApiConnection.CoreConnection), new StopLimitOrderHistoryQuery(_mockApiConnection.CoreConnection), new NewStopLimitOrderPlacer(_mockApiConnection.CoreConnection), new NewTradeOrderPlacer(_mockApiConnection.CoreConnection), new CancelOrderPlacer(_mockApiConnection.CoreConnection), new ActiveStopLimitOrderQuery(_mockApiConnection.CoreConnection), new TradeHistoryQuery(_mockApiConnection.CoreConnection)); _mockOrderServiceFactory.Expect(x => x.Create(_mockApiConnection)) .Return(expectedOrderServiceReturned) .Repeat.Once(); // Act var orderService = _serviceManager.OrderService; var orderServiceSecondCall = _serviceManager.OrderService; // Assert Assert.AreEqual(expectedOrderServiceReturned, orderService); Assert.AreEqual(orderService, orderServiceSecondCall); _mockOrderServiceFactory.VerifyAllExpectations(); }