/// <summary> /// Starts the stub server and starts listening to requests. /// </summary> /// <remarks> /// The stub is started on a randomly picked free port, so it will be accessible on an url like "http://localhost:51234". /// The exact address can be retrieved through the <see cref="Address" /> property. /// </remarks> public void Start() { if (state == ApiStubState.Started) { throw new InvalidOperationException("The api stub is already started."); } address = apiHost.StartHosting(); state = ApiStubState.Started; }
IExpectation IExpectationBuilder.Build() { var state = new ApiStubState(); var requestBuilder = new RequestBuilder(state); _requestConfig(requestBuilder); var requestCountBuilder = new RequestCountBuilder(state); _requestCountConfig(requestCountBuilder); return(new HttpRequestMockExpectation(state)); }
IAction IActionBuilder.Build() { var apiStubState = new ApiStubState(); var requestBuilder = new RequestBuilder(apiStubState); _requestConfig(requestBuilder); var responseBuilder = new ResponseBuilder(apiStubState); _responseConfig(responseBuilder); return(new MockHttpRequestAction(apiStubState)); }
public HttpRequestMockExpectation( ApiStubState state, int retryCount, TimeSpan retryInterval) { if (retryCount < 0) { throw new ArgumentOutOfRangeException(nameof(retryCount)); } _state = state ?? throw new ArgumentNullException(nameof(state)); _retryCount = retryCount; _retryInterval = retryInterval; }
/// <summary> /// Stops the stub server. /// </summary> /// <remarks> /// The stub needs to be disposed when it's not needed, so the TCP port used is freed up. /// </remarks> public void Dispose() { apiHost.Stop(); state = ApiStubState.Stopped; }