Пример #1
0
        public async Task Should_ThrowException_When_OrderArgumentIsNull()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            //Act & Assert
            var order = new MobinTrader.OrderService(mocks);
            await Assert.ThrowsAsync <ArgumentNullException>(() => order.Create(null, "test"));
        }
Пример #2
0
        public async Task Should_ThrowException_When_UserUnauthorized()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            //Act & Assert
            var order = new MobinTrader.OrderService(mocks);
            await Assert.ThrowsAsync <UnauthorizedAccessException>(() => order.Create(new OrderData(), ""));
        }
Пример #3
0
        public async Task Should_SetGetMethodOnRequest()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            //Act
            var order  = new MobinTrader.OrderService(mocks);
            var result = await order.Find(new GetOrderData(), "Token");

            //Assert
            Assert.Equal(Method.GET, mocks.MockRequest.Object.Method);
            Assert.Equal("Order", mocks.MockRequest.Object.Resource);
        }
Пример #4
0
        public void Should_SetBaseUrl()
        {
            //Arrange
            var mocks = new MockServiceConfigurator();

            mocks.MockRestClient.SetupAllProperties();

            //Act
            var auth = new MobinTrader.OrderService(mocks);

            //Assert
            Assert.NotNull(mocks.MockRestClient.Object.BaseUrl);
            Assert.False(string.IsNullOrWhiteSpace(mocks.MockRestClient.Object.BaseUrl.ToString()));
        }
Пример #5
0
        public async Task Should_AddTheInputParameterToRequestBody()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            OrderData data = null;

            mocks.MockRequest.Setup(x => x.AddJsonBody(It.IsAny <OrderData>()))
            .Callback <Object>((arg) => { data = (OrderData)arg; });
            OrderData dataSent = new OrderData();
            //Act
            var order  = new MobinTrader.OrderService(mocks);
            var result = await order.Create(dataSent, "Token");

            //Assert
            Assert.Same(dataSent, data);
        }
Пример #6
0
        public async Task Should_SetTokenToRequestHead_When_UserAuthorized()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();
            string tokenString            = null;

            mocks.MockRequest.Setup(x =>
                                    x.AddHeader(It.Is <string>(a => a.Equals("Authorization")), It.IsAny <string>()))
            .Callback <string, string>((arg1, arg2) => { tokenString = arg2; });

            string token = "TheTokenIsHere";
            //Act
            var order  = new MobinTrader.OrderService(mocks);
            var result = await order.Create(new OrderData(), token);

            //Assert
            Assert.Equal($"Basic {token}", tokenString);
        }