예제 #1
0
        /// <summary>
        /// Runs the specified apid code.
        /// </summary>
        /// <param name="apidCode">The apid code.</param>
        /// <param name="requestContext">The request context.</param>
        /// <param name="responseContext">The response context.</param>
        public static void Run(string apidCode, JavaScriptRequestContext requestContext, JavaScriptResponseContext responseContext)
        {
            var jsEngine  = CreateEngine();
            var runMethod = jsEngine.Execute(apidCode).GetValue("run");

            runMethod.Invoke(JsValue.FromObject(jsEngine, requestContext), JsValue.FromObject(jsEngine, responseContext));
        }
예제 #2
0
        /// <summary>
        /// Runs the specified API to run.
        /// </summary>
        /// <param name="apiToRun">The API to run.</param>
        /// <param name="hostRequestContext">The host request context.</param>
        /// <returns>HttpResponseMessage</returns>
        public HttpResponseMessage Run(MockApiModel apiToRun, HttpRequestMessage hostRequestContext)
        {
            var requestContext  = new JavaScriptRequestContext(hostRequestContext);
            var responseContext = new JavaScriptResponseContext();

            JavaScriptRuntime.Run(apiToRun.Body, requestContext, responseContext);
            return(responseContext.CreateHostResponse(hostRequestContext));
        }