public void OperationCorrectlyHandlesWebExceptionErrors([ValueSource("_operations")] Tuple<Action<TestServiceBase, Uri>, string, bool> operation) { if (operation.Item3 == false) { Assert.Inconclusive("Not applicable"); }; // arrange var apiUri = ApiRequestHandler.ApiRequestUri; var keyService = new SimpleOAuthKeyService() { OAuthResponse = new OAuthTokens() { AccessToken = "<<accesstoken>>", RefreshToken = "<<refreshtoken>>", ExpiresIn = 10 } }; var factory = new TestWebRequestFactory(); factory.RegisterResultForUri(OAuthRequestHandler.OAuthRequestUri.AbsoluteUri, new OAuthTokens() { AccessToken = "<<newaccesstoken>>" }.ToJson()); factory.RegisterExceptionForUri<WebException>(apiUri.AbsoluteUri); var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, keyService); // act var ex = Assert.Throws<ApiCommunicationException>(() => operation.Item1(service, apiUri)); // assert Assert.AreEqual(apiUri, ex.URI); }
public void OperationUpdatesKeyServiceWithNewTokensWhenCurrentTokensHaveExpired([ValueSource("_operations")] Tuple<Action<TestServiceBase, Uri>, string, bool> operation) { // arrange var apiUri = ApiRequestHandler.ApiRequestUri; var keyService = new SimpleOAuthKeyService() { OAuthResponse = new OAuthTokens() { AccessToken = "<<accesstoken>>", RefreshToken = "<<refreshtoken>>", ExpiresIn = 10 } }; var factory = new TestWebRequestFactory(); factory.RegisterResultForUri(OAuthRequestHandler.OAuthRequestUri.AbsoluteUri, new OAuthTokens() { AccessToken = "<<newaccesstoken>>" }.ToJson()); factory.RegisterResultForUri(apiUri.AbsoluteUri, operation.Item2); var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, keyService); // act operation.Item1(service, apiUri); // assert Assert.AreEqual("<<newaccesstoken>>", keyService.OAuthResponse.AccessToken); }