Ejemplo n.º 1
0
        public void InstantiateClient_SimplifiedParameters_ShouldNotBeNullAndShouldAuthorize()
        {
            //Assemble
            OAuth2Token token = TestHelper.GetTestAuthToken();
            Mock <IAsyncHttpClientHelper> httpClient = TestHelper.CreateMockHttpAuthorization(token);

            // Act
            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake,
                                                       TestHelper.Username_Fake, TestHelper.ApiKey_Fake, TestHelper.ApiKey_Fake);

            // Assert
            client.ShouldNotBeNull();
            client.ValidateLastGoodTokenIsEqual(token).ShouldBeTrue("last good token does not match expected result");
        }
Ejemplo n.º 2
0
        public void TrackViaClient_Authorize_ShouldDeserializeJsonAndReturnToken()
        {
            // Assemble
            OAuth2Token token = TestHelper.GetTestAuthToken();

            Mock <IAsyncHttpClientHelper> httpClient = TestHelper.CreateMockHttpAuthorization(token);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake,
                                                       TestHelper.Username_Fake, TestHelper.ApiKey_Fake, TestHelper.ApiKey_Fake);

            // Act
            client.Authorize(TestHelper.Username_Fake, TestHelper.Password_Fake);

            // Assert
            client.ValidateLastGoodTokenIsEqual(token).ShouldBeTrue("last good token does not match expected result");
        }
Ejemplo n.º 3
0
        public void TrackViaClient_RefreshAccessToken_ShouldReturnNewToken()
        {
            // Assemble
            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            // Authorization Token
            OAuth2Token token = TestHelper.GetTestAuthToken();
            TaskCompletionSource <HttpClientResponse> asyncAuthorizeTaskResult = new TaskCompletionSource <HttpClientResponse>();

            asyncAuthorizeTaskResult.SetResult(new HttpClientResponse()
            {
                Content     = JsonConvert.SerializeObject(token),
                ContentType = HttpClientResponseTypes.json,
                StatusCode  = HttpStatusCode.OK
            });
            httpClient.Setup(x => x
                             .SendGetRequestAsync(It.Is <string>(s => s.Contains("grant_type=password"))))
            .Returns(asyncAuthorizeTaskResult.Task);

            // Refresh Token
            OAuth2Token refreshToken = TestHelper.GetTestRefreshToken();
            TaskCompletionSource <HttpClientResponse> asyncRefreshTaskResult = new TaskCompletionSource <HttpClientResponse>();

            asyncRefreshTaskResult.SetResult(new HttpClientResponse()
            {
                Content     = JsonConvert.SerializeObject(refreshToken),
                ContentType = HttpClientResponseTypes.json,
                StatusCode  = HttpStatusCode.OK
            });
            httpClient.Setup(x => x
                             .SendGetRequestAsync(It.Is <string>(s => s.Contains("grant_type=refresh_token"))))
            .Returns(asyncRefreshTaskResult.Task);

            // Act
            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake,
                                                       TestHelper.Username_Fake, TestHelper.ApiKey_Fake, TestHelper.ApiKey_Fake);

            client.Authorize(TestHelper.Username_Fake, TestHelper.Password_Fake);
            client.RefreshAccessToken();

            // Assert
            client.ValidateLastGoodTokenIsEqual(refreshToken).ShouldBeTrue("last good token does not match expected result");
        }