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); }
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 }
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 }