public async Task LoginAync_WithValidCredentials_ShouldReturnToken()
        {
            // arrange
            var mockFactory            = new Mock <IHttpClientFactory>();
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();
            var mockContentResponse    = new CosyLoginResponse()
            {
                Token = "xyz"
            };

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(mockContentResponse), Encoding.UTF8, "application/json"),
            });


            var client = new HttpClient(mockHttpMessageHandler.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);
            var geoCosyClient = new GeoCosyClient(mockFactory.Object);

            // act
            var response = await geoCosyClient.LoginAsync("username", "password");

            // assert
            response.Data.ShouldNotBeNull();
            response.Data.Token.ShouldBe("xyz");
        }
        public async Task Login_WithInvalidCredentials_ReturnsErrorResponse()
        {
            // arrange
            var mockFactory            = new Mock <IHttpClientFactory>();
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.Unauthorized
            });


            var client = new HttpClient(mockHttpMessageHandler.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);
            var geoCosyClient = new GeoCosyClient(mockFactory.Object);

            // act
            var response = await geoCosyClient.LoginAsync("username", "password");

            // assert
            response.Data.ShouldBeNull();
            response.Errors.ShouldContain(x => x.ErrorCode == ErrorCode.AuthenticationFailed);
        }
        public async Task Login_WithSomeOtherException_ThrowsTheException()
        {
            // arrange
            var mockFactory            = new Mock <IHttpClientFactory>();
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.BadGateway
            });


            var client = new HttpClient(mockHttpMessageHandler.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);
            var geoCosyClient = new GeoCosyClient(mockFactory.Object);

            // act / assert
            Should.Throw <Exception>(async() => await geoCosyClient.LoginAsync("username", "password"));
        }