public void HttpImposter_WithDefaultRequest_SetsDefaultRequest() { var defaultResponse = new HttpResponseFields(); var imposter = Client.CreateHttpsImposter(123, "service", defaultResponse: defaultResponse); Assert.IsNotNull(imposter.DefaultResponse); Assert.AreEqual(defaultResponse, imposter.DefaultResponse); }
public HttpsImposter(int?port, string name, string key, string cert, bool mutualAuthRequired, bool recordRequests = false, HttpResponseFields defaultResponse = null) : base(port, Enums.Protocol.Https, name, recordRequests) { Cert = cert; Key = key; MutualAuthRequired = mutualAuthRequired; Stubs = new List <HttpStub>(); DefaultResponse = defaultResponse; }
/// <summary> /// Adds a response to the stub that will return the specified HTTP status code. /// </summary> /// <param name="statusCode">The status code to be returned</param> /// <returns>The stub that the response was added to</returns> public HttpStub ReturnsStatus(HttpStatusCode statusCode) { var fields = new HttpResponseFields { StatusCode = statusCode }; var response = new IsResponse <HttpResponseFields>(fields); return(Returns(response)); }
public async Task DeepEqualsPredicateExample() { var imposter = _client.CreateHttpImposter(4556, "DeepEqualsPredicateExample"); // First stub var predicateFields = new HttpPredicateFields { QueryParameters = new Dictionary <string, object>() }; var responseFields = new HttpResponseFields { ResponseObject = "first" }; imposter.AddStub().On(new DeepEqualsPredicate <HttpPredicateFields>(predicateFields)) .Returns(new IsResponse <HttpResponseFields>(responseFields)); // Second stub predicateFields = new HttpPredicateFields { QueryParameters = new Dictionary <string, object> { { "first", "1" } } }; responseFields = new HttpResponseFields { ResponseObject = "second" }; imposter.AddStub().On(new DeepEqualsPredicate <HttpPredicateFields>(predicateFields)) .Returns(new IsResponse <HttpResponseFields>(responseFields)); // Third stub predicateFields = new HttpPredicateFields { QueryParameters = new Dictionary <string, object> { { "first", "1" }, { "second", "2" } } }; responseFields = new HttpResponseFields { ResponseObject = "third" }; imposter.AddStub().On(new DeepEqualsPredicate <HttpPredicateFields>(predicateFields)) .Returns(new IsResponse <HttpResponseFields>(responseFields)); await _client.SubmitAsync(imposter); }
/// <summary> /// Adds a response to the stub with the specified content type /// </summary> /// <param name="statusCode">The status code to be returned</param> /// <param name="headers">The headers for the response</param> /// <param name="responseObject">The response object that will be returned as the specified content type</param> /// <returns></returns> public HttpStub Returns(HttpStatusCode statusCode, IDictionary <string, string> headers, object responseObject) { var fields = new HttpResponseFields { StatusCode = statusCode, ResponseObject = responseObject, Headers = headers }; var response = new IsResponse <HttpResponseFields>(fields); return(Returns(response)); }
/// <summary> /// Creates a new imposter on the specified port with the HTTPS protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// /// The key and cert parameters MUST be valid PEM-formatted strings. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="key">The private key the imposter will use, MUST be a PEM-formatted string</param> /// <param name="cert">The public certificate the imposer will use, MUST be a PEM-formatted string</param> /// <param name="mutualAuthRequired">Whether or not the server will require mutual auth</param> /// <param name="recordRequests"> /// Enables recording requests to use the imposter as a mock. See /// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank /// verification. /// </param> /// <param name="defaultResponse">The default response to send if no predicate matches</param> /// <returns>The newly created imposter</returns> public HttpsImposter CreateHttpsImposter(int?port = null, string name = null, string key = null, string cert = null, bool mutualAuthRequired = false, bool recordRequests = false, HttpResponseFields defaultResponse = null) { if (key != null && !IsPEMFormatted(key)) { throw new InvalidOperationException("Provided key must be PEM-formatted"); } if (cert != null && !IsPEMFormatted(cert)) { throw new InvalidOperationException("Provided certificate must be PEM-formatted"); } return(new HttpsImposter(port, name, key, cert, mutualAuthRequired, recordRequests, defaultResponse)); }
/// <summary> /// Adds a response to the stub with the specified content type /// </summary> /// <param name="statusCode">The status code to be returned</param> /// <param name="headers">The headers for the response</param> /// <param name="responseObject">The response object that will be returned as the specified content type</param> /// <param name="mode">Response mode: text of binary. Text mode is default</param> /// <param name="latencyInMilliseconds">The number of milliseconds to be waiting before response will be returned</param> /// <returns>The stub that the response was added to</returns> public HttpStub Returns(HttpStatusCode statusCode, IDictionary <string, object> headers, object responseObject, string mode = "text", int?latencyInMilliseconds = null) { var fields = new HttpResponseFields { StatusCode = statusCode, ResponseObject = responseObject, Headers = headers, Mode = mode }; var behavior = latencyInMilliseconds.HasValue ? new Behavior { LatencyInMilliseconds = latencyInMilliseconds } : null; var response = new IsResponse <HttpResponseFields>(fields, behavior); return(Returns(response)); }
public HttpsImposter(int?port, string name, bool recordRequests = false, HttpResponseFields defaultResponse = null) : this(port, name, null, null, false, recordRequests, defaultResponse) { }
public HttpImposter(int?port, string name, bool recordRequests = false, HttpResponseFields defaultResponse = null) : base(port, Enums.Protocol.Http, name, recordRequests) { Stubs = new List <HttpStub>(); DefaultResponse = defaultResponse; }
/// <summary> /// Creates a new imposter on the specified port with the HTTP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="recordRequests"> /// Enables recording requests to use the imposter as a mock. See /// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank /// verification. /// </param> /// <param name="defaultResponse">The default response to send if no predicate matches</param> /// <returns>The newly created imposter</returns> public HttpImposter CreateHttpImposter(int?port = null, string name = null, bool recordRequests = false, HttpResponseFields defaultResponse = null) { return(new HttpImposter(port, name, recordRequests, defaultResponse)); }