public void TestToCheckErrorIsReturnedWhenNoTradeCanBeExecutedOnAStock()
        {
            var tradesController = new TradesController();

            var trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 50,
                Price    = 100
            };
            var submitTradeResponse = tradesController.Post(trade).Result;

            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 100,
                Price    = 101
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 150,
                Price    = 100
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            var executionResponse = tradesController.Get("GOOGL").Result;

            Assert.IsNotNull(executionResponse);
            Assert.IsNotNull(executionResponse.Error);
            Assert.AreEqual(executionResponse.Status, "Failure");
            Assert.AreEqual(executionResponse.TradeExecutions.Count, 0);
        }
        public void TestAdd()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new TradesController(context);

            var trade = new Trade()
            {
                Id        = 4,
                AccountId = 1,
                Action    = TradeActions.Buy,
                Quantity  = 1,
                Symbol    = "MSFT"
            };

            // act
            var result   = controller.Post(trade);
            var okResult = result as OkObjectResult;
            var data     = (okResult.Value as Trade);

            // assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsNotNull(data);
            Assert.AreEqual(4, trade.Id);
        }
        public void TestToCheckErrorIsReturnedWhenTradeTypeIsInvalid()
        {
            var tradesController = new TradesController();

            var trade = new Trade()
            {
                Name     = "APPL",
                Type     = "HOLD",
                Quantity = 50,
                Price    = 100
            };
            var submitTradeResponse = tradesController.Post(trade).Result;

            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNotNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Failure");
            Assert.IsNull(submitTradeResponse.TradeId);
        }
        public void TestToCheckWhetherAStockIsSuccessFullyAddedInTheTradingQueue()
        {
            var tradesController = new TradesController();

            var trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 50,
                Price    = 100
            };
            var submitTradeResponse = tradesController.Post(trade).Result;

            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);
        }
        public void TestToGetTradeExecutionsOnAStockWhenThereAreValidTradeRequests()
        {
            // Arrange
            var tradesController = new TradesController();

            var trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 50,
                Price    = 100
            };
            var submitTradeResponse = tradesController.Post(trade).Result;

            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 100,
                Price    = 101
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "BUY",
                Quantity = 150,
                Price    = 100
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "SELL",
                Quantity = 100,
                Price    = 102
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            trade = new Trade()
            {
                Name     = "GOOGL",
                Type     = "SELL",
                Quantity = 200,
                Price    = 100
            };
            submitTradeResponse = tradesController.Post(trade).Result;
            Assert.IsNotNull(submitTradeResponse);
            Assert.IsNull(submitTradeResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(submitTradeResponse.TradeId);

            var executionResponse = tradesController.Get("GOOGL").Result;

            Assert.IsNotNull(executionResponse);
            Assert.IsNull(executionResponse.Error);
            Assert.AreEqual(submitTradeResponse.Status, "Success");
            Assert.IsNotNull(executionResponse.TradeExecutions);
            Assert.IsTrue(executionResponse.TradeExecutions.Count > 0);
        }