public async Task <IActionResult> GetResultCounts(HttpRequest request)
        {
            string json = await request.GetRawBodyStringAsync();

            TestScenariosResultsCountsRequestModel requestModel = JsonConvert.DeserializeObject <TestScenariosResultsCountsRequestModel>(json);

            if (requestModel == null || requestModel.TestScenarioIds.IsNullOrEmpty())
            {
                _logger.Error("Null or empty test scenario ids provided");

                return(new BadRequestObjectResult("Null or empty test scenario ids provided"));
            }

            ConcurrentBag <TestScenarioResultCounts> resultCounts = new ConcurrentBag <TestScenarioResultCounts>();

            Parallel.ForEach(requestModel.TestScenarioIds, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 10
            }, testScenarioId =>
            {
                SearchModel searchModel = new SearchModel
                {
                    IncludeFacets       = true,
                    Top                 = 1,
                    PageNumber          = 1,
                    OverrideFacetFields = new string[] { "testResult" },
                    Filters             = new Dictionary <string, string[]> {
                        { "testScenarioId", new[] { testScenarioId } }
                    }
                };

                TestScenarioSearchResults result = _testResultsService.SearchTestScenarioResults(searchModel).Result;

                if (result != null && !result.Results.IsNullOrEmpty())
                {
                    Facet facet = result.Facets?.FirstOrDefault(m => m.Name == "testResult");

                    if (facet != null)
                    {
                        FacetValue passedValue  = facet.FacetValues.FirstOrDefault(m => m.Name == "Passed");
                        FacetValue failedValue  = facet.FacetValues.FirstOrDefault(m => m.Name == "Failed");
                        FacetValue ignoredValue = facet.FacetValues.FirstOrDefault(m => m.Name == "Ignored");

                        resultCounts.Add(new TestScenarioResultCounts
                        {
                            TestScenarioName = result.Results.First().TestScenarioName,
                            TestScenarioId   = testScenarioId,
                            Passed           = passedValue != null ? passedValue.Count : 0,
                            Failed           = failedValue != null ? failedValue.Count : 0,
                            Ignored          = ignoredValue != null ? ignoredValue.Count : 0,
                            LastUpdatedDate  = result.Results.First().LastUpdatedDate
                        });
                    }
                }
            });

            return(new OkObjectResult(resultCounts));
        }
        public async Task GetResultCounts_GivenModelWithScenarioIdsButBothResultsButNoFacets_ReturnsOKWithNoResult()
        {
            //Arrange
            TestScenariosResultsCountsRequestModel model = new TestScenariosResultsCountsRequestModel
            {
                TestScenarioIds = new[] { "1", "2" }
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest httpRequest = Substitute.For <HttpRequest>();

            httpRequest
            .Body
            .Returns(stream);

            ILogger logger = CreateLogger();

            TestScenarioSearchResults testScenarioSearchResults1 = new TestScenarioSearchResults();
            TestScenarioSearchResults testScenarioSearchResults2 = new TestScenarioSearchResults();

            ITestResultsSearchService searchService = CreateTestResultsSearchService();

            searchService
            .SearchTestScenarioResults(Arg.Any <SearchModel>())
            .Returns(testScenarioSearchResults1, testScenarioSearchResults2);

            TestResultsCountsService service = CreateResultCountsService(searchService, logger: logger);

            //Act
            IActionResult result = await service.GetResultCounts(httpRequest);

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();

            OkObjectResult okResult = result as OkObjectResult;

            ConcurrentBag <TestScenarioResultCounts> results = okResult.Value as ConcurrentBag <TestScenarioResultCounts>;

            results
            .Count
            .Should()
            .Be(0);
        }
Ejemplo n.º 3
0
 public Task <IActionResult> RunSearchTestScenarioResults()
 {
     return(_testResultsSearchService.SearchTestScenarioResults(ControllerContext.HttpContext.Request));
 }
Ejemplo n.º 4
0
 public Task <IActionResult> RunSearchTestScenarioResults([FromBody] SearchModel searchModel)
 {
     return(_testResultsSearchService.SearchTestScenarioResults(searchModel));
 }
        public async Task GetResultCounts_GivenModelWithScenarioIdsWithAllFacetValues_ReturnsOKeResult()
        {
            //Arrange
            TestScenariosResultsCountsRequestModel model = new TestScenariosResultsCountsRequestModel
            {
                TestScenarioIds = new[] { "1" }
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest httpRequest = Substitute.For <HttpRequest>();

            httpRequest
            .Body
            .Returns(stream);

            ILogger logger = CreateLogger();

            TestScenarioSearchResults testScenarioSearchResults1 = new TestScenarioSearchResults
            {
                Results = new[]
                {
                    new TestScenarioSearchResult
                    {
                        TestScenarioName = "Test Name",
                        LastUpdatedDate  = DateTimeOffset.Now
                    }
                },
                Facets = new[]
                {
                    new Facet {
                        Name = "testResult", FacetValues = new[] {
                            new FacetValue {
                                Count = 10, Name = "Passed"
                            },
                            new FacetValue {
                                Count = 87, Name = "Failed"
                            },
                            new FacetValue {
                                Count = 6, Name = "Ignored"
                            }
                        }
                    }
                }
            };

            ITestResultsSearchService searchService = CreateTestResultsSearchService();

            searchService
            .SearchTestScenarioResults(Arg.Any <SearchModel>())
            .Returns(testScenarioSearchResults1);

            TestResultsCountsService service = CreateResultCountsService(searchService, logger: logger);

            //Act
            IActionResult result = await service.GetResultCounts(httpRequest);

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();

            OkObjectResult okResult = result as OkObjectResult;

            ConcurrentBag <TestScenarioResultCounts> results = okResult.Value as ConcurrentBag <TestScenarioResultCounts>;

            results
            .Count
            .Should()
            .Be(1);

            results
            .First()
            .Passed
            .Should()
            .Be(10);

            results
            .First()
            .Failed
            .Should()
            .Be(87);

            results
            .First()
            .Ignored
            .Should()
            .Be(6);
        }
        public async Task GetResultCounts_GivenModelWithScenarioIds_ReturnsOKWithTwoResults()
        {
            //Arrange
            TestScenariosResultsCountsRequestModel model = new TestScenariosResultsCountsRequestModel
            {
                TestScenarioIds = new[] { "1", "2" }
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest httpRequest = Substitute.For <HttpRequest>();

            httpRequest
            .Body
            .Returns(stream);

            ILogger logger = CreateLogger();

            TestScenarioSearchResults testScenarioSearchResults = new TestScenarioSearchResults
            {
                Results = new[]
                {
                    new TestScenarioSearchResult
                    {
                        TestScenarioName = "Test Name 1",
                        LastUpdatedDate  = DateTimeOffset.Now
                    },
                    new TestScenarioSearchResult
                    {
                        TestScenarioName = "Test Name 2",
                        LastUpdatedDate  = DateTimeOffset.Now
                    }
                },
                Facets = new[]
                {
                    new Facet {
                        Name = "testResult"
                    }
                }
            };

            ITestResultsSearchService searchService = CreateTestResultsSearchService();

            searchService
            .SearchTestScenarioResults(Arg.Any <SearchModel>())
            .Returns(testScenarioSearchResults);

            TestResultsCountsService service = CreateResultCountsService(searchService, logger: logger);

            // Act
            IActionResult result = await service.GetResultCounts(httpRequest);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .BeAssignableTo <IEnumerable <TestScenarioResultCounts> >()
            .Which
            .Should()
            .HaveCountGreaterThan(0);
        }