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 GetPdf_Sync_ThrowsInvalidOperationException() { // Arrange var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") }; var uri = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn"; _webFactory.RegisterExceptionForUri <WebException>(uri); var iis = new TestInvoiceService(_configuration, _webFactory, null); // Act var ex = Assert.Throws <ApiCommunicationException>(() => iis.GetPdf(cf, _uid, null, "tn")); // Assert Assert.AreEqual(uri.ToLower(), ex.URI.AbsoluteUri.ToLower()); Assert.IsInstanceOf <InvalidOperationException>(ex.InnerException); }
public void TranslatesWebExceptionsWhenThrown() { // arrange var uri = "http://localhost/"; var factory = new TestWebRequestFactory(); factory.RegisterExceptionForUri <WebException>(uri); var handler = new TestBaseRequestHandler(factory); // act Assert.ThrowsAsync <ApiCommunicationException>(async() => await handler.MakeRequestAsync(uri)); // assert }
public void CallOnErrorIfError() { // arrange var uri = "http://localhost/"; var factory = new TestWebRequestFactory(); factory.RegisterExceptionForUri<WebException>(uri); var handler = new TestBaseRequestHandler(factory); // act var data = new object(); handler.MakeRequest(uri, null, (exuri, exception) => data = exception); // assert Assert.IsNotNull(data); }
public void GetNonWebExceptionsAreWrappedIfThrown() { // arrange var apiUri = ApiRequestHandler.ApiRequestUri; var factory = new TestWebRequestFactory(); var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, null); factory.RegisterExceptionForUri <InvalidOperationException>(apiUri.AbsoluteUri); // act var ex = Assert.Throws <ApiOperationException>(() => service.Get(apiUri)); // assert Assert.IsInstanceOf <InvalidOperationException>(ex.InnerException); }
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); }
public void CallOnErrorIfError() { // arrange var uri = "http://localhost/"; var factory = new TestWebRequestFactory(); factory.RegisterExceptionForUri <WebException>(uri); var handler = new TestBaseRequestHandler(factory); // act var data = new object(); handler.MakeRequest(uri, null, (exuri, exception) => data = exception); // assert Assert.IsNotNull(data); }
public void GetNonWebExceptionsAreWrappedIfThrown() { // arrange var apiUri = ApiRequestHandler.ApiRequestUri; var factory = new TestWebRequestFactory(); var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, null); factory.RegisterExceptionForUri<InvalidOperationException>(apiUri.AbsoluteUri); // act var ex = Assert.Throws<ApiOperationException>(() => service.Get(apiUri)); // assert Assert.IsInstanceOf<InvalidOperationException>(ex.InnerException); }
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 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); }