示例#1
0
        public async Task Should_SetGetRequestToRequest()
        {
            //Arrange
            MockServiceConfigurator mocks = new MockServiceConfigurator();

            mocks.MockRestClient.SetupAllProperties();
            mocks.MockRequest.SetupAllProperties();
            mocks.MockRestClient.Setup(x => x.
                                       ExecuteTaskAsync <LogoutResult>(It.IsAny <IRestRequest>()))
            .ReturnsAsync(new RestResponse <LogoutResult>()
            {
                Data = new LogoutResult()
                {
                    IsSuccessful = true
                }
            });

            //Act
            var auth   = new MobinTrader.AuthenticationService(mocks);
            var result = await auth.Logout();

            //Assert
            Assert.Equal(Method.GET, mocks.MockRequest.Object.Method);
            Assert.Equal("APIAUTHENTICATE/SignOut", mocks.MockRequest.Object.Resource);
        }
示例#2
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"));
        }
示例#3
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(), ""));
        }
示例#4
0
        public async Task Should_ThrowException_When_NoUserOrPassProvided()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            string user = "";
            string pass = "******";

            //Act and Assert
            var auth = new MobinTrader.AuthenticationService(mocks);
            await Assert.ThrowsAsync <UnauthorizedAccessException>(() => auth.Login(user, pass));
        }
示例#5
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);
        }
示例#6
0
        public async Task Should_SetPostMethodOnRequestObject_When_UserPassProvided()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            //Act
            var auth   = new MobinTrader.AuthenticationService(mocks);
            var result = await auth.Login("user1", "pass1");

            //Assert
            Assert.Equal(Method.POST, mocks.MockRequest.Object.Method);
            Assert.Equal("APIAUTHENTICATE", mocks.MockRequest.Object.Resource);
        }
示例#7
0
        public void Should_SetsABaseUrl()
        {
            //Arrange
            var mocks = new MockServiceConfigurator();

            mocks.MockRestClient.SetupAllProperties();

            //Act
            var auth = new AuthenticationService(mocks);

            //Assert
            Assert.NotNull(mocks.MockRestClient.Object.BaseUrl);
            Assert.False(string.IsNullOrWhiteSpace(mocks.MockRestClient.Object.BaseUrl.ToString()));
        }
示例#8
0
        private static MockServiceConfigurator SetupMock()
        {
            var mocks = new MockServiceConfigurator();

            mocks.MockRestClient.SetupAllProperties();
            mocks.MockRequest.SetupAllProperties();
            mocks.MockRestClient.Setup(x => x.
                                       ExecuteTaskAsync <OrderListResult>(It.IsAny <IRestRequest>()))
            .ReturnsAsync(new RestResponse <OrderListResult>()
            {
                Data = new OrderListResult()
                {
                    IsSuccessful = true
                }
            });
            return(mocks);
        }
示例#9
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);
        }
示例#10
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);
        }
        public void AddTwoIServiceConfiguration_ThrowsInvalidOperationException()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                MockServiceConfigurator serviceConfigurator = new MockServiceConfigurator();

                pluginManager.RegisterServiceConfigurator(serviceConfigurator);

                try
                {
                    pluginManager.RegisterServiceConfigurator(serviceConfigurator);
                }
                catch (InvalidOperationException ioe)
                {
                    Assert.AreEqual("Only one IServiceConfigurator can be loaded", ioe.Message);
                    throw;
                }
            }
        }
示例#12
0
        public async Task Should_AddUsernameAndPasswordToRequestBody_When_UserPassProvided()
        {
            //Arrange
            MockServiceConfigurator mocks = SetupMock();

            LoginData userObject = null;

            mocks.MockRequest.Setup(x => x.AddJsonBody(It.IsAny <LoginData>()))
            .Callback <Object>((arg) => { userObject = (LoginData)arg; });
            string user = "******";
            string pass = "******";

            //Act
            var auth   = new MobinTrader.AuthenticationService(mocks);
            var result = await auth.Login(user, pass);

            //Assert
            Assert.Equal(user, userObject.UserName);
            Assert.Equal(pass, userObject.Password);
        }
        public void ServiceConfigurationIsCalled_AfterServicesHaveBeenConfigured_ThrowsInvalidOperationException()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                MockServiceConfigurator serviceConfigurator = new MockServiceConfigurator();

                pluginManager.RegisterServiceConfigurator(serviceConfigurator);

                pluginManager.ConfigureServices();

                Assert.IsTrue(serviceConfigurator.RegisterServicesCalled);

                try
                {
                    pluginManager.RegisterServiceConfigurator(serviceConfigurator);
                }
                catch (InvalidOperationException ioe)
                {
                    Assert.AreEqual("The plugin manager has already configured its services", ioe.Message);
                    throw;
                }
            }
        }