public AppsResult GetTestPlan(int testPlanId)
        {
            var result            = new AppsResult();
            var testRunController = new TestRunController(_env, _data, _driver, _ctx);

            try
            {
                var testplans = _db.GetCollection <TestPlan>("TestPlans").Query().Where(tp => tp.ID == testPlanId);
                if (testplans.Count() == 1)
                {
                    var testPlan    = testplans.Single();
                    var testResults = testRunController.GetLatestResults(TestRunInstanceType.TestPlan, testPlan.ID).Data;
                    testPlan.Results = Newtonsoft.Json.JsonConvert.SerializeObject(testResults);

                    result.Data    = testPlan;
                    result.Success = true;
                }
                else
                {
                    new AppFlows.Test.Fail("Returned either zero or more than one test plans.", ref result);
                }
            }
            catch (System.Exception ex)
            {
                new AppFlows.Test.Exception(ex, ref result);
            }
            return(result);
        }
        public AppsResult GetSteps(int testId)
        {
            var result = new AppsResult();

            try
            {
                if (testId > 0)
                {
                    var testRunController = new TestRunController(_env, _data, _driver, _ctx);
                    var steps             = _db.GetCollection <TestStep>("Steps");

                    var appSteps = steps.Query().Where(s => s.TestID == testId && s.Archived == false).ToList();
                    var test     = (List <Test>)GetTest(testId).Data; //TODO: Refactor safer

                    foreach (var step in appSteps)
                    {
                        //TODO: Decide how to choose between result from test plan or individual step test runs
                        var testResults = testRunController.GetLatestResults(TestRunInstanceType.TestPlan, test.Single().TestPlanID).Data;
                        step.Results = Newtonsoft.Json.JsonConvert.SerializeObject(testResults);
                    }

                    result.Data    = appSteps;
                    result.Success = true;
                }
                else
                {
                    result.FailMessages.Add("Test ID is zero.");
                }
            }
            catch (System.Exception ex)
            {
                new AppFlows.Test.Exception(ex, ref result);
            }
            return(result);
        }
        public AppsResult GetTestPlans(int appId)
        {
            var result = new AppsResult();

            try
            {
                var testRunController = new TestRunController(_env, _data, _driver, _ctx);
                var testplans         = _db.GetCollection <TestPlan>("TestPlans");
                var tests             = _db.GetCollection <Test>("Tests");
                var teststeps         = _db.GetCollection <TestStep>("TestSteps");

                var appTestPlans = testplans.Query().Where(tp => tp.AppID == appId && tp.Archived == false).ToList();

                foreach (var appTestPlan in appTestPlans)
                {
                    var testResults = testRunController.GetLatestResults(TestRunInstanceType.TestPlan, appTestPlan.ID).Data;
                    appTestPlan.Results = Newtonsoft.Json.JsonConvert.SerializeObject(testResults);
                    //var planTests = tests.Query().Where(t => t.TestPlanID == appTestPlan.ID).ToList();

                    //if (planTests.Count() > 0)
                    //{
                    //    appTestPlan.Tests.AddRange(planTests);

                    //    foreach (var planTest in planTests)
                    //    {
                    //        var testSteps = teststeps.Query().Where(ts => ts.TestID == planTest.TestID).ToList();
                    //        if (testSteps.Count() > 0)
                    //        {
                    //            planTest.Steps.AddRange(testSteps);
                    //        }
                    //    }
                    //}
                }

                result.Data    = appTestPlans;
                result.Success = true;
            }
            catch (System.Exception ex)
            {
                new AppFlows.Test.Exception(ex, ref result);
            }
            return(result);
        }
        public AppsResult GetTests(int testPlanId)
        {
            var result            = new AppsResult();
            var testRunController = new TestRunController(_env, _data, _driver, _ctx);

            try
            {
                if (testPlanId > 0)
                {
                    var tests = _db.GetCollection <Test>("Tests");
                    var steps = _db.GetCollection <TestStep>("Steps");

                    var appTests = tests.Query().Where(tp => tp.TestPlanID == testPlanId && tp.Archived == false).ToList();
                    foreach (var test in appTests)
                    {
                        //var testSteps = steps.Query().Where(ts => ts.TestID == test.ID && ts.Archived == false).ToList();
                        //if (testSteps.Count() > 0)
                        //    test.Steps.AddRange(testSteps);

                        //TODO: Refactor to somehow handle getting results produced by clicking "Test" as well as "TestPlan" test runs
                        var testResults = testRunController.GetLatestResults(TestRunInstanceType.TestPlan, testPlanId).Data;
                        test.Results = Newtonsoft.Json.JsonConvert.SerializeObject(testResults);
                    }
                    result.Data    = appTests;
                    result.Success = true;
                }
                else
                {
                    result.FailMessages.Add("Test plan ID is zero.");
                }
            }
            catch (System.Exception ex)
            {
                new AppFlows.Test.Exception(ex, ref result);
            }
            return(result);
        }