public void GetErrorResponseHandlersTest() { var request = (Request) Request.CreateRequest( new MockClientService(), new MockClientServiceRequest { HttpMethod = "GET", MethodName = "TestMethod", RestPath = "https://example.com" }); // Confirm that there are no error response handlers by default. CollectionAssert.IsEmpty(request.GetErrorResponseHandlers()); // Confirm that a standard authenticator won't result in an error response handler. request.WithAuthentication(new MockAuthenticator()); CollectionAssert.IsEmpty(request.GetErrorResponseHandlers()); // Confirm that an error handling response handler will change the enumeration var auth = new MockErrorHandlingAuthenticator(); request.WithAuthentication(auth); CollectionAssert.AreEqual(new IErrorResponseHandler[] { auth }, request.GetErrorResponseHandlers()); }
public void TestRetrySystem() { var request = (Request) Request.CreateRequest( new MockService(), new MockMethod { HttpMethod = "GET", Name = "TestMethod", // Define an invalid URI which will cause a WebException to be thrown. RestPath = "https://localhost:12345/", Parameters = new Dictionary <string, IParameter>() }); var auth = new MockErrorHandlingAuthenticator(); Assert.IsFalse(auth.Called); request.WithAuthentication(auth); request.WithParameters(new Dictionary <string, string>()); // Execute the request. This will fail because we have defined an invalid rest URI. // The IErrorResponseHandler should kick in and try to resend the request. As this // will also fail we will receive a GoogleApiException over here. Assert.Throws <GoogleApiRequestException>(() => request.ExecuteRequest()); // Confirm that the IErrorResponseHandler has run and tried to resend/modify the request. Assert.IsTrue(auth.Called); }
public void GetErrorResponseHandlersTest() { var request = (Request) Request.CreateRequest( new MockService(), new MockMethod { HttpMethod = "GET", Name = "TestMethod", RestPath = "https://example.com" }); // Confirm that there are no error response handlers by default. CollectionAssert.IsEmpty(request.GetErrorResponseHandlers()); // Confirm that a standard authenticator won't result in an error response handler. request.WithAuthentication(new MockAuthenticator()); CollectionAssert.IsEmpty(request.GetErrorResponseHandlers()); // Confirm that an error handling response handler will change the enumeration var auth = new MockErrorHandlingAuthenticator(); request.WithAuthentication(auth); CollectionAssert.AreEqual(new IErrorResponseHandler[] { auth }, request.GetErrorResponseHandlers()); }
public void TestRetrySystem() { var request = (Request) Request.CreateRequest( new MockService(), new MockMethod { HttpMethod = "GET", Name = "TestMethod", // Define an invalid URI which will cause a WebException to be thrown. RestPath = "https://localhost:12345/", Parameters = new Dictionary<string, IParameter>() }); var auth = new MockErrorHandlingAuthenticator(); Assert.IsFalse(auth.Called); request.WithAuthentication(auth); request.WithParameters(new Dictionary<string, string>()); // Execute the request. This will fail because we have defined an invalid rest URI. // The IErrorResponseHandler should kick in and try to resend the request. As this // will also fail we will receive a GoogleApiException over here. Assert.Throws<GoogleApiRequestException>(() => request.ExecuteRequest()); // Confirm that the IErrorResponseHandler has run and tried to resend/modify the request. Assert.IsTrue(auth.Called); }