public object Post(UploadTestResults request)
        {
            var testPlanId = request.TestPlanId;
            var testRunId = request.TestRunId.GetValueOrDefault();
            TestRun testRun = null;

            if (base.Request.Files.Length == 0)
                throw new ArgumentException("No Test Result supplied");

            var processedResults = new List<TestResult>();
            var newResults = new List<TestResult>();
            foreach (var httpFile in base.Request.Files)
            {
                if (httpFile.FileName.ToLower().EndsWith(".zip"))
                {
                    using (var zip = ZipFile.Read(httpFile.InputStream))
                    {
                        var zipResults = new List<TestResult>();
                        foreach (var zipEntry in zip)
                        {
                            using (var ms = new MemoryStream())
                            {
                                zipEntry.Extract(ms);
                                var bytes = ms.ToArray();

                                var result = new MemoryStream(bytes).ToTestResult();
                                zipResults.Add(result);
                            }
                        }

                        if (request.CreateNewTestRuns)
                        {
                            var seriesId = httpFile.FileName.Substring(0, httpFile.FileName.Length - ".zip".Length);
                            testRun = CreateTestRun(testPlanId, seriesId);
                            testRun = AddTestResults(GetSignedInUserId(), testPlanId, testRun.Id, zipResults);
                            processedResults.AddRange(zipResults);
                        }
                        else
                        {
                            newResults.AddRange(zipResults);
                        }
                    }
                }
                else
                {
                    var result = httpFile.InputStream.ToTestResult();
                    newResults.Add(result);
                }
            }

            if (newResults.Count > 0)
            {
                testRun = AddTestResults(GetSignedInUserId(), testPlanId, testRunId, newResults);
                processedResults.AddRange(newResults);
            }

            return new UploadTestResultsResponse
            {
                success = true,
                TestRun = testRun,
                Results = processedResults,
            };
        }
示例#2
0
        public object Post(UploadTestResults request)
        {
            var     testPlanId = request.TestPlanId;
            var     testRunId  = request.TestRunId.GetValueOrDefault();
            TestRun testRun    = null;

            if (base.Request.Files.Length == 0)
            {
                throw new ArgumentException("No Test Result supplied");
            }

            var processedResults = new List <TestResult>();
            var newResults       = new List <TestResult>();

            foreach (var httpFile in base.Request.Files)
            {
                if (httpFile.FileName.ToLower().EndsWith(".zip"))
                {
                    using (var zip = ZipFile.Read(httpFile.InputStream))
                    {
                        var zipResults = new List <TestResult>();
                        foreach (var zipEntry in zip)
                        {
                            using (var ms = new MemoryStream())
                            {
                                zipEntry.Extract(ms);
                                var bytes = ms.ToArray();

                                var result = new MemoryStream(bytes).ToTestResult();
                                zipResults.Add(result);
                            }
                        }

                        if (request.CreateNewTestRuns)
                        {
                            var seriesId = httpFile.FileName.Substring(0, httpFile.FileName.Length - ".zip".Length);
                            testRun = CreateTestRun(testPlanId, seriesId);
                            testRun = AddTestResults(GetSignedInUserId(), testPlanId, testRun.Id, zipResults);
                            processedResults.AddRange(zipResults);
                        }
                        else
                        {
                            newResults.AddRange(zipResults);
                        }
                    }
                }
                else
                {
                    var result = httpFile.InputStream.ToTestResult();
                    newResults.Add(result);
                }
            }

            if (newResults.Count > 0)
            {
                testRun = AddTestResults(GetSignedInUserId(), testPlanId, testRunId, newResults);
                processedResults.AddRange(newResults);
            }

            return(new UploadTestResultsResponse
            {
                success = true,
                TestRun = testRun,
                Results = processedResults,
            });
        }