/// <summary> /// Performs a request against the host application using the specified HTTP method. /// </summary> /// <param name="method">The HTTP method that should be used.</param> /// <param name="path">The path that is being requested.</param> /// <param name="overrides">A configuration object for providing the HTTP payload for the request.</param> /// <returns>A <see cref="ClientResponse"/> instance of the executed request.</returns> public virtual ClientResponse PerformRequest(string method, string path, Action<HttpPayload> overrides = null) { Ensure.NotNull(method, "method"); Ensure.NotNull(path, "path"); var payload = new HttpPayload(method); if (defaults != null) { defaults.ApplyTo(payload); } path = path.RemoveLeadingSlash(); path = payload.ExtractQueryString(path); overrides.TryInvoke(payload); CrowbarContext.Reset(); var request = new CrowbarHttpRequestCapture(new CrowbarHttpRequest(path, payload)); var response = new CrowbarHttpResponse(); using (var handle = CreateRequestWaitHandle()) { var worker = new CrowbarHttpWorker(request, response, handle); HttpRuntime.ProcessRequest(worker); handle.Wait(); return CreateResponse(request, response); } }
/// <summary> /// Asserts that the response content type is of the MIME-type 'text/html'. /// </summary> /// <param name="response">The <see cref="ClientResponse"/> that the assert should be made on.</param> /// <param name="assertions">Additional assertions on the CQ object.</param> /// <returns>The CQ object.</returns> public static CQ ShouldBeHtml(this ClientResponse response, Action<CQ> assertions = null) { response.ShouldHaveContentType("text/html"); CQ document; try { document = response.AsCsQuery(); } catch (Exception exception) { throw AssertException.Create(response, "Failed to convert response body into a CQ object.", exception); } assertions.TryInvoke(document); return document; }
/// <summary> /// Asserts that the response content type is of the MIME-type 'text/html'. /// </summary> /// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param> /// <param name="assertions">Additional assertions on the CQ object.</param> /// <returns>The CQ object.</returns> public static CQ ShouldBeHtml(this BrowserResponse response, Action<CQ> assertions = null) { response.AssertStatusCode(HttpStatusCode.OK); response.AssertContentType("text/html"); CQ document; try { document = response.AsCsQuery(); } catch (Exception exception) { throw new AssertException("Failed to convert response body into a CQ object.", exception); } assertions.TryInvoke(document); return document; }
/// <summary> /// Performs a request against the host application using the specified HTTP method. /// </summary> /// <param name="method">The HTTP method that should be used.</param> /// <param name="path">The path that is being requested.</param> /// <param name="overrides">A configuration object for providing the browser context for the request.</param> /// <returns>A <see cref="BrowserResponse"/> instance of the executed request.</returns> public BrowserResponse PerformRequest(string method, string path, Action<BrowserContext> overrides = null) { Ensure.NotNull(method, "method"); Ensure.NotNull(path, "path"); var context = new BrowserContext(mvcMajorVersion, method); path = path.RemoveLeadingSlash(); path = context.ExtractQueryString(path); defaults.TryInvoke(context); overrides.TryInvoke(context); CrowbarContext.Reset(); var output = new StringWriter(); var workerRequest = new SimulatedWorkerRequest(path, context, output); HttpRuntime.ProcessRequest(workerRequest); string rawHttpRequest = workerRequest.GetRawHttpRequest(); return CreateResponse(output, rawHttpRequest); }
/// <summary> /// Asserts that the response content type is of the MIME-type 'application/xml' or the specified override. /// </summary> /// <param name="response">The <see cref="ClientResponse"/> that the assert should be made on.</param> /// <param name="assertions">Additional assertions on the XML object.</param> /// <param name="contentType">The expected content type.</param> /// <returns>An XElement.</returns> public static XElement ShouldBeXml(this ClientResponse response, Action<XElement> assertions = null, string contentType = "application/xml") { response.ShouldHaveContentType(contentType); XElement xml; try { xml = response.AsXml(); } catch (Exception exception) { throw AssertException.Create(response, "Failed to convert response body into XML.", exception); } assertions.TryInvoke(xml); return xml; }
protected RabbitMQChannelBase(ChannelManagerBase channelManager, Action<ICommunicationObject> communicationObjectCreatedCallback) : base(channelManager) { communicationObjectCreatedCallback.TryInvoke(this); }
public override bool Write(byte[] chunk, int index, int count, Action dataWrittenCallback = null) { if (this.IsDisposed) return false; var args = new SocketAsyncEventArgs(); args.SetBuffer(chunk, index, count); args.Completed += (sender, e) => { this.BytesWritten += e.BytesTransferred; dataWrittenCallback.TryInvoke(); }; return this._socket.SendAsync(args); }
public static IEnumerator GenericDelay(float duration, System.Action callback) { yield return(new WaitForSecondsRealtime(duration)); callback.TryInvoke(); }
/// <summary> /// Asserts that the response content type is of the MIME-type 'application/xml' or the specified override. /// </summary> /// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param> /// <param name="assertions">Additional assertions on the XML object.</param> /// <param name="contentType">The expected content type.</param> /// <returns>An XElement.</returns> public static XElement ShouldBeXml(this BrowserResponse response, Action<XElement> assertions = null, string contentType = "application/xml") { response.AssertStatusCode(HttpStatusCode.OK); response.AssertContentType(contentType); XElement xml; try { xml = response.AsXml(); } catch (Exception exception) { throw new AssertException("Failed to convert response body into XML.", exception); } assertions.TryInvoke(xml); return xml; }