Ejemplo n.º 1
0
        public static async Task <IActionResult> HandleRequest(this HttpRequest request, string nodeSecret,
                                                               params TestableAssembly[] assemblies)
        {
            var serializedTrigger = await new StreamReader(request.Body).ReadToEndAsync();
            var trigger           = JsonConvert.DeserializeObject <TestTrigger>(serializedTrigger);

            if (!string.IsNullOrWhiteSpace(nodeSecret))
            {
                if (nodeSecret != trigger.NodeSecret)
                {
                    return(new ForbidResult("The node secret is invalid"));
                }
            }

            var engine = new EagleEngine(assemblies);
            var discoveredTestSuites     = engine.GetDiscoveredTestSuites();
            var httpRequestResultHandler = new HttpRequestResultHandler(discoveredTestSuites, trigger.NodeName, trigger.RequestId, trigger.CallBackUrl);
            var results = await engine.ExecuteTest(httpRequestResultHandler, trigger.Id);

            var result = new TestReport()
            {
                NodeName    = trigger.NodeName,
                RequestId   = trigger.RequestId,
                TestResults = results,
                TestSuites  = discoveredTestSuites
            };

            return(new OkObjectResult(JsonConvert.SerializeObject(result)));
        }
Ejemplo n.º 2
0
        private static async Task HandleEagleRequest(HttpContext context, string nodeSecret, params TestableAssembly[] testableAssemblies)
        {
            var bodyAsText = await GetBody(context);

            TestTrigger testTrigger = JsonConvert.DeserializeObject <TestTrigger>(bodyAsText);
            var         response    = context.Response;

            response.ContentType = "application/json";

            if (!string.IsNullOrWhiteSpace(nodeSecret))
            {
                if (nodeSecret != testTrigger.NodeSecret)
                {
                    response.StatusCode = (int)HttpStatusCode.Forbidden;
                    await response.WriteAsync(JsonConvert.SerializeObject("the node secret is wrong"));

                    return;
                }
            }
            response.StatusCode = (int)HttpStatusCode.OK;
            var            eagleEngine = new EagleEngine(testableAssemblies);
            var            testSuites  = eagleEngine.GetDiscoveredTestSuites();
            IResultHandler handler     = new HttpRequestResultHandler(testSuites, testTrigger.NodeName, testTrigger.RequestId,
                                                                      testTrigger.CallBackUrl);
            var result = await eagleEngine.ExecuteTest(handler, testTrigger.Id);


            var report = new TestReport()
            {
                TestResults = result,
                TestSuites  = testSuites,
                NodeName    = testTrigger.NodeName,
                RequestId   = testTrigger.RequestId,
            };
            await response.WriteAsync(JsonConvert.SerializeObject(report));
        }