示例#1
0
        public async Task TokenQueryHandler_Get_ShouldReturnValidResult()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.PostJson <Credentials, TokenResponse>(It.IsAny <string>(), It.IsAny <Credentials>())).ReturnsAsync(new TokenResponse {
                Token = "token"
            });

            var tokenHandler = new TokenQueryHandler(mockClient.Object);

            // act
            var result = await tokenHandler.Get(
                new TokenQuery
            {
                Payload = new Credentials
                {
                    Username = "******",
                    Password = "******"
                }
            });

            // assert
            Assert.AreEqual("token", result.Token);
        }
示例#2
0
        public async Task TokenQueryHandler_Get_QueryPayloadIsNull_ShouldThrowArgumentNullException()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.PostJson <Credentials, TokenResponse>(It.IsAny <string>(), It.IsAny <Credentials>())).ReturnsAsync(new TokenResponse {
                Token = "token"
            });

            var tokenHandler = new TokenQueryHandler(mockClient.Object);

            // act
            var result = await tokenHandler.Get(new TokenQuery());

            // assert ExpectedException
        }
示例#3
0
        public async Task TokenQueryHandler_Get_OnException_ShouldThrowTokenQueryException()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.PostJson <Credentials, TokenResponse>(It.IsAny <string>(), It.IsAny <Credentials>())).ThrowsAsync(new ClientException("some error"));

            var tokenHandler = new TokenQueryHandler(mockClient.Object);

            // act
            var result = await tokenHandler.Get(
                new TokenQuery {
                Payload = new Credentials
                {
                    Username = "******",
                    Password = "******"
                }
            });

            // assert ExpectedException
        }