コード例 #1
0
        public ActionResult AssignTestCases(int id = 0)
        {
            var testRun = db.TestRuns.Find(id);

            if (testRun == null) return HttpNotFound();

            SelectTestCasesVM vm = new SelectTestCasesVM();
            vm.TestRunID = testRun.TestRunID;
            var testSuite = (from tc in db.TestCases
                             where tc.TestSuiteID == testRun.TestPlan.TeamID
                             orderby tc.Title
                             select tc).ToList();
            vm.TestCases = new SelectList(testSuite, "TestCaseID", "Title");

            vm.TestCasesInTestRun = new List<int>();
            foreach (var item in testRun.Results)
            {
                vm.TestCasesInTestRun.Add(item.TestCaseID);
            }

            return PartialView(vm);
        }
コード例 #2
0
        public ActionResult AssignTestCases(SelectTestCasesVM vm)
        {
            List<int> uncheckedTestCases = new List<int>(from value in db.Results
                                                         where value.TestRunID == vm.TestRunID
                                                         select value.TestCaseID).ToList();

            // If there is at least 1 test case checked
            if (vm.SelectedTestCases != null)
            {
                foreach (var testCaseID in vm.SelectedTestCases)
                {
                    if (uncheckedTestCases.Contains(Convert.ToInt32(testCaseID)))
                    {
                        int id = Convert.ToInt32(testCaseID);
                        uncheckedTestCases.RemoveAll(item => item == id);
                    }
                    else
                    {
                        var result = new Result
                        {
                            TestRunID = vm.TestRunID,
                            TestCaseID = Convert.ToInt32(testCaseID),
                            State = State.Untested,
                            TestCase = db.TestCases.Find(Convert.ToInt32(testCaseID)),
                            TestRun = db.TestRuns.Find(vm.TestRunID)
                        };

                        db.Results.Add(result);
                        db.SaveChanges();
                    }
                }
            }

            RemoveResults(uncheckedTestCases, vm.TestRunID);

            return RedirectToAction("Index", "ExecuteTestRun", new { id = vm.TestRunID });
        }