/// <summary> /// Create an <see cref="HttpMessageHandler"/>. /// </summary> /// <param name="resources">Instance where faked responses are stored</param> /// <param name="callbacks"></param> /// <returns>A <see cref="HttpMessageHandler"/> appropriate for the current <see cref="Mode"/></returns> /// <exception cref="ArgumentNullException"/> public static HttpMessageHandler CreateMessageHandler(IResources resources, IResponseCallbacks callbacks) { if (resources == null) { throw new ArgumentNullException("resources"); } if (callbacks == null) { throw new ArgumentNullException("callbacks"); } var store = new ResponseStore(resources, callbacks); // fake has a different base class than capture and automatic // so thats why this is up here if (Mode == MessageHandlerMode.Fake) { return(new FakeHttpMessageHandler(store)); } var clientHandler = Mode == MessageHandlerMode.Capture ? new CapturingHttpClientHandler(store) : Mode == MessageHandlerMode.Automatic ? new AutomaticHttpClientHandler(store) : new HttpClientHandler(); if (clientHandler.SupportsAutomaticDecompression) { clientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } return(clientHandler); }
/// <summary> /// /// </summary> /// <param name="resources">An instance that manages the underlying storage of response resources</param> /// <param name="callbacks">Object used to allow client code to modify responses during load and storage</param> /// <exception cref="ArgumentNullException"/> public ReadOnlyResponseStore(IReadOnlyResources resources, IResponseCallbacks callbacks) { _resources = resources ?? throw new ArgumentNullException("loader"); _formatter = new MessageFormatter(callbacks); }
/// <summary> /// ctor /// </summary> /// <param name="callbacks">object used to allow client code to modify responses during load and storage</param> public MessageFormatter(IResponseCallbacks callbacks) { _callbacks = callbacks ?? throw new ArgumentNullException("callbacks"); }
/// <summary> /// Create an <see cref="HttpMessageHandler"/>. /// </summary> /// <param name="resources">Instance where faked responses are stored</param> /// <param name="callbacks"></param> /// <returns>A <see cref="HttpMessageHandler"/> appropriate for the current <see cref="Mode"/></returns> /// <exception cref="InvalidOperationException">If <see cref="Mode"/> is <see cref="MessageHandlerMode.Capture"/> /// or <see cref="MessageHandlerMode.Automatic"/></exception> /// <exception cref="ArgumentNullException"/> public static HttpMessageHandler CreateMessageHandler(IReadOnlyResources resources, IResponseCallbacks callbacks) { if (resources == null) { throw new ArgumentNullException("resources"); } if (callbacks == null) { throw new ArgumentNullException("callbacks"); } if (Mode == MessageHandlerMode.Fake) { return(new FakeHttpMessageHandler(new ReadOnlyResponseStore(resources, callbacks))); } if (Mode == MessageHandlerMode.Capture || Mode == MessageHandlerMode.Automatic) { throw new InvalidOperationException("Cannot use Capture or Automatic mode with an IReadOnlyResources"); } // else online var clientHandler = new HttpClientHandler(); if (clientHandler.SupportsAutomaticDecompression) { clientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } return(clientHandler); }
/// <summary> /// /// </summary> /// <param name="resources">An instance that can read and write to the underlying storage of response resources</param> /// <param name="callbacks">Object to manage and modify responses at runtime</param> /// <exception cref="ArgumentNullException"/> public ResponseStore(IResources resources, IResponseCallbacks callbacks) : base(resources, callbacks) { _resources = resources; }