Exemplo n.º 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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }