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);
        }
Esempio n. 3
0
        public void PostExerciseTestRun_ShouldNotCreateNewTestsIfUserIsAStudent()
        {
            //Arrange
            var exercise = new Exercise
            {
                Id   = _random.NextPositive(),
                Code = Guid.NewGuid().ToString()
            };

            _assignmentServiceMock.Setup(service => service.GetOrCreateExerciseAsync(It.IsAny <ExerciseDto>()))
            .ReturnsAsync(exercise);

            var exerciseDto = new ExerciseDtoBuilder().WithExerciseCode(exercise.Code).Build();
            var postedModel = new CreateExerciseTestRunModelBuilder()
                              .WithExercise(exerciseDto)
                              .WithSourceCode()
                              .Build();

            _controller = CreateControllerWithUserInContext(Role.Constants.Student);

            //Act
            _controller.PostExerciseTestRun(postedModel).Wait();

            //Assert
            _assignmentServiceMock.Verify(service => service.LoadTestsForAssignmentAsync(exercise), Times.Once);
            _assignmentServiceMock.Verify(
                service => service.LoadOrCreateTestsForAssignmentAsync(It.IsAny <Assignment>(),
                                                                       It.IsAny <IEnumerable <string> >()), Times.Never);
        }
Esempio n. 4
0
 public void Setup()
 {
     _random = new Random();
     _testResultConverterMock = new Mock <ITestRunConverter>();
     _testRunServiceMock      = new Mock <ITestRunService>();
     _assignmentServiceMock   = new Mock <IAssignmentService>();
     _userId     = _random.Next(1, int.MaxValue);
     _controller = CreateControllerWithUserInContext(Role.Constants.Lector);
 }
Esempio n. 5
0
        public static void Main()
        {
            var testAssemblies = new[]
            {
                Assembly.Load("ErraticMotion.NETMF.System.Tests.Unit"),
                Assembly.Load("ErraticMotion.Reaction.Emv.Types.Tests.Unit")
            };

            var controller = new TestRunController(testAssemblies);

            controller.TestCompleted         += (sende, e) => Console.WriteLine(e);
            controller.TestAssemblyCompleted += (sender, e) => Console.WriteLine(e);
            controller.Execute();
            Thread.Sleep(Timeout.Infinite);
        }
        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);
        }