Exemplo n.º 1
0
        public void GetResponseStream_GivenGroupedResultWithIViewData_ReturnsXmlContainingGroupedResult()
        {
            var request  = new PortalRequest();
            var response = new PortalResponse(request){ReturnFormat = ReturnFormat.XML2};
            var grouped  = new GroupedResult<IResult>(new[] { new ResultGroup<ViewDataResultMock>(2, 0, new[] { new ViewDataResultMock(), new ViewDataResultMock() }) });
            request.Stopwatch.Reset();

            response.WriteToOutput(grouped);

            using (var stream = new StreamReader(response.GetResponseStream()))
            {
                var readToEnd = stream.ReadToEnd();
                Assert.That(readToEnd, Is.EqualTo("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><PortalResponse><Header><Duration>0</Duration></Header><Body><Groups><ResultGroup><Count>2</Count><TotalCount>2</TotalCount><Results><ViewDataResultMock><Fullname>test</Fullname></ViewDataResultMock><ViewDataResultMock><Fullname>test</Fullname></ViewDataResultMock></Results></ResultGroup></Groups></Body><Error /></PortalResponse>"));
            }
        }
Exemplo n.º 2
0
        private GroupedResult CalculateGroupedResultsForTestcase(int intTestcaseID, List <Result> results, DateTime?resultsSince)
        {
            //Don't show not supported state...
            results = results.Where(t => t.ResultCode != TestState.NotSupported).ToList();

            if (!results.Any())
            {
                return(null);
            }

            //If we have a date since filter, only use results if there are new ones...
            if (resultsSince.HasValue && results.Max(t => t.Testtime) + new TimeSpan(0, 0, 10) < resultsSince.Value)
            {
                return(null);
            }

            GroupedResult groupedResult = new GroupedResult {
                Testcase = intTestcaseID
            };

            var groupedResultsByResultCode = results.GroupBy(result => result.ResultCode, result => result,
                                                             (key, elements) => new { ResultCode = key, Results = elements.ToList() });

            bool allResultsAreEqual = groupedResultsByResultCode.Count() == 1;

            foreach (var result in groupedResultsByResultCode)
            {
                GroupedResultPart groupedResultPart = new GroupedResultPart {
                    ResultCode = result.ResultCode
                };
                if (allResultsAreEqual)
                {
                    groupedResultPart.ResultLabel = (result.ResultCode).ToString();
                }
                else if (result.Results.Count == 1)
                {
                    Result singleResult = result.Results[0];
                    groupedResultPart.ResultLabel = singleResult.Browser.Name + " " + singleResult.Language.Languagecode + " " + ((TestState)result.ResultCode);
                }
                else
                {
                    groupedResultPart.ResultLabel = result.Results.Count + "x " + (result.ResultCode);
                }
                groupedResult.GroupedResultParts.Add(groupedResultPart);
            }

            return(groupedResult);
        }
Exemplo n.º 3
0
        IList <GroupedResult> ITestViewerService.GetResults(int testsystemIndex, int testsuiteId, DateTime?resultsSince)
        {
            Testsuite      testsuite = _testsuiteRepository.GetById(testsuiteId);
            IList <Result> results   = _resultRepository.GetListOfResults(testsystemIndex, testsuite.Browsers, testsuite.Testcases,
                                                                          testsuite.Languages).ToList();

            List <GroupedResult> groupedResults = new List <GroupedResult>();

            foreach (Testcase testcase in testsuite.Testcases)
            {
                GroupedResult groupedResult = CalculateGroupedResultsForTestcase(testcase.ID, results.Where(result => result.Testcase.ID == testcase.ID).ToList(), resultsSince);
                if (groupedResult != null)
                {
                    groupedResults.Add(groupedResult);
                }
            }

            return(groupedResults);
        }