Exemplo n.º 1
0
        public async Task Get()
        {
            //Arrange

            var tradesMock = new TradesResponseBuilder().Build();

            var dateConvert = new  Utils().ConverterTimestampToDatetime(tradesMock.FirstOrDefault().Date);

            _tradesServiceMock.Setup(x => x.Get(It.IsAny <service.TradesGetRequest>())).ReturnsAsync(tradesMock);

            var request = new TradesGetRequest
            {
                Coins = CoinsEnum.BTC
            };

            //Act
            var result = await _tradesController.Get(request);

            var okObjectResult = result as OkObjectResult;
            var resultObj      = okObjectResult.Value as List <Trades>;

            //Assert
            Assert.Equal(200, okObjectResult.StatusCode);
            Assert.NotNull(resultObj);
            Assert.Equal(5, resultObj.Count);

            Assert.Equal(dateConvert, resultObj.FirstOrDefault().Date);
            Assert.Equal(tradesMock.FirstOrDefault().Price, resultObj.FirstOrDefault().Price);
            Assert.Equal(tradesMock.FirstOrDefault().Amount, resultObj.FirstOrDefault().Amount);
            Assert.Equal(tradesMock.FirstOrDefault().Tid, resultObj.FirstOrDefault().Tid);
            Assert.Equal(tradesMock.FirstOrDefault().Type, resultObj.FirstOrDefault().Type);
        }
Exemplo n.º 2
0
        public void TestTraderGet()
        {
            // Test method that returns a string
            var controller = new TradesController();

            var response = controller.Get("fred");

            Assert.AreEqual("GET for trader fred", response);
        }
Exemplo n.º 3
0
        public async Task Get_statusOk()
        {
            //Arrange
            var httpResponseMessage = new HttpResponseMessageBuilder().StatusOk_Trades().Build();

            _httpRequestHandlerMock.Setup(p => p.Get(It.IsAny <string>())).ReturnsAsync(httpResponseMessage);

            TradesGetRequest tickerGetRequest = new TradesGetRequest()
            {
                Coins = CoinsEnum.BTC
            };

            //Act
            var result = await _tradesController.Get(tickerGetRequest);

            var okObjectResult = result as OkObjectResult;
            var resultList     = okObjectResult.Value as List <Trades>;

            //Assert
            Assert.Equal(200, okObjectResult.StatusCode);
            Assert.Equal(5, resultList.Count);
        }
Exemplo n.º 4
0
        public void TestResponse()
        {
            // Test a method that returns an IHttpActionResult
            var controller = new TradesController();

            // OkNegotiatedContentResult is used to handle a 200 OK with content
            var response = controller.Get(3);
            var result   = response as OkNegotiatedContentResult <Trade>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(1000, result.Content.Volume);
        }
        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 TestGetById()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new TradesController(context);

            // act
            var okResult = controller.Get(1) as OkObjectResult;
            var data     = (okResult.Value as Trade);

            // assert
            Assert.IsNotNull(data);
            Assert.AreEqual(1, data.Id);
        }
        public void TestGetSkip0Take1()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new TradesController(context);
            var p          = new TradeQueryParameter()
            {
                Skip = 0,
                Take = 1
            };

            // act
            var okResult = controller.Get(p) as OkObjectResult;
            var data     = (okResult.Value as IEnumerable <Trade>).ToArray();

            // assert
            Assert.AreEqual(1, data.Count());
            Assert.AreEqual(1, data[0].Id);
            Assert.AreEqual(1, data[0].AccountId);
        }
        public void TestGetAll()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new TradesController(context);

            // act
            var result = controller.Get(new Data.Models.TradeQueryParameter()
            {
            });
            var okResult = result as OkObjectResult;
            var data     = (okResult.Value as IEnumerable <Trade>).ToArray();

            // assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 2);
            Assert.AreEqual(1, data[0].Id);
        }
        public void TestUpdate()
        {
            // arrange
            var context    = CreateDbContext();
            var controller = new TradesController(context);

            var trade = ((controller.Get(2) as OkObjectResult).Value as Trade);

            trade.Quantity = 15;

            // act
            var result   = controller.Put(2, 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(2, trade.Id);
        }
        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);
        }