public void GetOpenOrders_IfTraderIdIsProvided_RetrievedOrdersShouldBeDateTimeSortedAsDescending()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);
            Order            order      = OrderFactory.CreateOrder("100", "XBTUSD", "limit", "buy", 5, 10,
                                                                   new StubbedOrderIdGenerator());

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            Order order1 = OrderFactory.CreateOrder("100", "XBTUSD", "limit", "buy", 5, 10,
                                                    new StubbedOrderIdGenerator());

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            Order order2 = OrderFactory.CreateOrder("100", "XBTUSD", "limit", "buy", 5, 10,
                                                    new StubbedOrderIdGenerator());

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            OrderReadModel model = ReadModelAdapter.GetOrderReadModel(order);

            _persistanceRepository.SaveOrUpdate(model);
            OrderReadModel model1 = ReadModelAdapter.GetOrderReadModel(order1);

            _persistanceRepository.SaveOrUpdate(model1);
            OrderReadModel model2 = ReadModelAdapter.GetOrderReadModel(order2);

            _persistanceRepository.SaveOrUpdate(model2);
            IList <OrderReadModel> getReadModel = _orderRepository.GetOpenOrders("100");

            Assert.NotNull(getReadModel);
            Assert.AreEqual(getReadModel.Count, 3);
            Assert.True(getReadModel[0].DateTime > getReadModel[1].DateTime);
            Assert.True(getReadModel[1].DateTime > getReadModel[2].DateTime);
        }
        public void SaveOrderReadModel_IfStateIsAccepted_ClosingTimeShouldBeNull()
        {
            Order order = OrderFactory.CreateOrder("1234", "XBTUSD", "limit", "buy", 5, 10,
                                                   new StubbedOrderIdGenerator());
            string id = DateTime.Now.ToString();

            order.OrderState = OrderState.Accepted;
            OrderReadModel model = ReadModelAdapter.GetOrderReadModel(order);

            _persistanceRepository.SaveOrUpdate(model);
            OrderReadModel getReadModel = _orderRepository.GetOrderById(order.OrderId.Id.ToString());

            Assert.NotNull(getReadModel);
            AssertAreEqual(getReadModel, model);
            Assert.Null(getReadModel.ClosingDateTime);
        }
        public void SaveOrderReadModel_IfSaveOrUpdateMethodIsCalled_ItShouldGetSavedInTheDatabase()
        {
            Order order = OrderFactory.CreateOrder("1234", "XBTUSD", "limit", "buy", 5, 10,
                                                   new StubbedOrderIdGenerator());
            string id = DateTime.Now.ToString();

            order.OrderState = OrderState.Complete;
            OrderReadModel model = ReadModelAdapter.GetOrderReadModel(order);

            _persistanceRepository.SaveOrUpdate(model);
            OrderReadModel getReadModel = _orderRepository.GetOrderById(order.OrderId.Id.ToString());

            Assert.NotNull(getReadModel);
            AssertAreEqual(getReadModel, model);
            Assert.NotNull(getReadModel.ClosingDateTime);
        }
        public void GetClosedOrders_IfTraderIdIsProvided_ItShouldRetireveAllClosedOrdersOfTrader()
        {
            Order order = OrderFactory.CreateOrder("999", "XBTUSD", "limit", "buy", 5, 10,
                                                   new StubbedOrderIdGenerator());

            order.OrderState = OrderState.Complete;
            string         id    = DateTime.Now.ToString();
            OrderReadModel model = ReadModelAdapter.GetOrderReadModel(order);

            _persistanceRepository.SaveOrUpdate(model);
            IList <OrderReadModel> getReadModel = _orderRepository.GetClosedOrders("999");

            Assert.NotNull(getReadModel);
            Assert.AreEqual(getReadModel.Count, 1);
            AssertAreEqual(getReadModel[0], model);
        }