private VariantExecutionModelBase CreateTestExecutionModel(Uri taskCompleteRedirect, DomainModel.TestPoolEntry test, LabVariant variant, LabWork lab, Result result)
        {
            var model = new TestExecutionModel();

            model.Name       = test.TestPool.Name;
            model.Question   = test.TestQuestion.Question;
            model.Answers    = test.TestQuestion.AnswerVariants;
            model.QuestionId = test.Id;
            model.OtherTasks = GetOtherTasksModels(lab, result, null, test).ToArray();
            model.VariantId  = variant.Id;
            model.LabName    = lab.Name;
            var operation  = _operationFactory.Create();
            var testResult = operation.DataContext.Query.OfEntities <TestResult>().FirstOrDefault(e => e.TestPoolEntry.Id == test.Id & e.Result.Id == result.Id);

            operation.Complete();
            model.TestResult = testResult.Id;
            return(model);
        }
Exemple #2
0
        public async Task <IActionResult> RunTests(HttpRequest request)
        {
            string json = await request.GetRawBodyStringAsync();

            TestExecutionModel testExecutionModel = JsonConvert.DeserializeObject <TestExecutionModel>(json);

            BuildProject buildProject = testExecutionModel.BuildProject;

            if (buildProject == null)
            {
                _logger.Error("Null build project provided");
                return(new BadRequestObjectResult("Null build project provided"));
            }

            string specificationId = buildProject.SpecificationId;

            IEnumerable <ProviderResult> providerResults = testExecutionModel.ProviderResults;

            if (providerResults.IsNullOrEmpty())
            {
                _logger.Error("No provider results were provided");
                return(new BadRequestObjectResult("No provider results were provided"));
            }

            IEnumerable <TestScenario> testScenarios = await _scenariosRepository.GetTestScenariosBySpecificationId(specificationId);

            if (testScenarios.IsNullOrEmpty())
            {
                _logger.Warning($"No test scenarios found for specification id: {specificationId}");
                return(new StatusCodeResult(412));
            }

            SpecificationSummary specification = await _specificationRepository.GetSpecificationSummaryById(specificationId);

            if (specification == null)
            {
                _logger.Error($"No specification found for specification id: {specificationId}");
                return(new StatusCodeResult(412));
            }

            IEnumerable <string> providerIds = providerResults.Select(m => m.Provider.Id).ToList();

            IEnumerable <ProviderSourceDataset> sourceDatasets = await _providerSourceDatasetsRepositoryPolicy.ExecuteAsync(() =>
                                                                                                                            _providerSourceDatasetsRepository.GetProviderSourceDatasetsByProviderIdsAndSpecificationId(providerIds, specificationId));

            if (sourceDatasets.IsNullOrEmpty())
            {
                _logger.Error($"No source datasets found for specification id: {specificationId}");
                return(new StatusCodeResult(412));
            }

            IEnumerable <TestScenarioResult> testScenarioResults = await _testResultsRepository.GetCurrentTestResults(providerIds, specificationId);

            IEnumerable <TestScenarioResult> results = await _testEngine.RunTests(testScenarios, providerResults, sourceDatasets, testScenarioResults.ToList(), specification, buildProject);


            if (results.Any())
            {
                HttpStatusCode status = await _testResultsService.SaveTestProviderResults(results, providerResults);

                if (!status.IsSuccess())
                {
                    _logger.Error($"Failed to save test results with status code: {status.ToString()}");
                }
            }

            return(new OkObjectResult(results));
        }
Exemple #3
0
 public Task <IActionResult> RunTests([FromBody] TestExecutionModel testExecutionModel)
 {
     return(_testEngineService.RunTests(testExecutionModel));
 }
        public async Task <IActionResult> RunTests(TestExecutionModel testExecutionModel)
        {
            BuildProject buildProject = testExecutionModel.BuildProject;

            if (buildProject == null)
            {
                _logger.Error("Null build project provided");
                return(new BadRequestObjectResult("Null build project provided"));
            }

            string specificationId = buildProject.SpecificationId;

            IEnumerable <ProviderResult> providerResults = testExecutionModel.ProviderResults;

            if (providerResults.IsNullOrEmpty())
            {
                _logger.Error("No provider results were provided");
                return(new BadRequestObjectResult("No provider results were provided"));
            }

            IEnumerable <TestScenario> testScenarios = await _scenariosRepository.GetTestScenariosBySpecificationId(specificationId);

            if (testScenarios.IsNullOrEmpty())
            {
                _logger.Warning($"No test scenarios found for specification id: {specificationId}");
                return(new PreconditionFailedResult(string.Empty));
            }

            ApiResponse <SpecModel.SpecificationSummary> specificationApiResponse =
                await _specificationsApiClientPolicy.ExecuteAsync(() => _specificationsApiClient.GetSpecificationSummaryById(specificationId));

            if (!specificationApiResponse.StatusCode.IsSuccess() || specificationApiResponse.Content == null)
            {
                _logger.Error($"No specification found for specification id: {specificationId}");
                return(new PreconditionFailedResult(string.Empty));
            }

            SpecModel.SpecificationSummary specification = specificationApiResponse.Content;

            IEnumerable <string> providerIds = providerResults.Select(m => m.Provider.Id).ToList();

            IEnumerable <ProviderSourceDataset> sourceDatasets = await _providerSourceDatasetsRepositoryPolicy.ExecuteAsync(() =>
                                                                                                                            _providerSourceDatasetsRepository.GetProviderSourceDatasetsByProviderIdsAndSpecificationId(providerIds, specificationId));

            if (sourceDatasets.IsNullOrEmpty())
            {
                _logger.Error($"No source datasets found for specification id: {specificationId}");
                return(new PreconditionFailedResult(string.Empty));
            }

            IEnumerable <TestScenarioResult> testScenarioResults = await _testResultsRepository.GetCurrentTestResults(providerIds, specificationId);

            IEnumerable <TestScenarioResult> results = await _testEngine.RunTests(testScenarios, providerResults, sourceDatasets, testScenarioResults.ToList(), specification, buildProject);


            if (results.Any())
            {
                HttpStatusCode status = await _testResultsService.SaveTestProviderResults(results, providerResults);

                if (!status.IsSuccess())
                {
                    _logger.Error($"Failed to save test results with status code: {status}");
                }
            }

            return(new OkObjectResult(results));
        }