public void WhenIRenewTokensDelegateIReceiveDeserializedTokens() { var uriOauth = OAuthRequestHandler.OAuthRequestUri; var factory = new TestWebRequestFactory(); factory.RegisterResultForUri(uriOauth.AbsoluteUri, "{\"access_token\": \"<<token>>\"}"); var service = new OAuthService(_configuration, factory); OAuthTokens received = null; service.RenewTokens(new OAuthTokens(), (code, tokens) => { received = tokens; }, (uri, exception) => { Assert.Fail(); }); Assert.IsNotNull(received); Assert.AreEqual("<<token>>", received.AccessToken); }
public void WhenIRenewTokensSyncIReceiveDeserializedTokens() { var uriOauth = OAuthRequestHandler.OAuthRequestUri; var factory = new TestWebRequestFactory(); factory.RegisterResultForUri(uriOauth.AbsoluteUri, "{\"access_token\": \"<<token>>\"}"); var service = new OAuthService(_configuration, factory); OAuthTokens received = service.RenewTokens(new OAuthTokens()); Assert.IsNotNull(received); Assert.AreEqual("<<token>>", received.AccessToken); }
public void RenewTokensCorrectlyHandlesWebExceptionErrors() { // arrange var apiUri = ApiRequestHandler.ApiRequestUri; var factory = new TestWebRequestFactory(); factory.RegisterExceptionForUri<WebException>(OAuthRequestHandler.OAuthRequestUri.AbsoluteUri); var service = new OAuthService(_configuration, factory); // act var ex = Assert.Throws<ApiCommunicationException>(() => service.RenewTokens(new OAuthTokens())); // assert Assert.AreEqual(OAuthRequestHandler.OAuthRequestUri, ex.URI); }