Пример #1
0
        public void TestRunScheduler_VerifyGetTestRunStatus_ReturnsResults()
        {
            TimeSpan expectedRunTime = TimeSpan.FromSeconds(40);

            Mock <ITestRunExecutor> mockExecutor = new Mock <ITestRunExecutor>();

            mockExecutor
            .SetupGet(s => s.ElapsedTime)
            .Returns(expectedRunTime);

            mockExecutor
            .SetupGet(s => s.Status)
            .Returns(ExecutorStatus.Completed);

            Mock <ITestRunExecutorFactory> mockFactory = new Mock <ITestRunExecutorFactory>();

            mockFactory.Setup(m => m.GetNewTestRunExecutor(It.IsAny <string>())).Returns(mockExecutor.Object);

            var schedulerUnderTest = new TestRunScheduler(mockFactory.Object);

            Guid          testRunId = schedulerUnderTest.StartNewTestRun("mockTestSuite");
            TestRunStatus actual    = schedulerUnderTest.GetTestRunStatus(testRunId);

            Assert.AreEqual(expectedRunTime, actual.CurrentRunTime);
            Assert.AreEqual(RunStatus.Completed, actual.Status);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            PrintUsage();

            TestRunScheduler scheduler = new TestRunScheduler();

            bool exit = false;

            while (!exit)
            {
                string userInput = Console.ReadLine();

                string invokedVerb         = null;
                object invokedVerbInstance = null;

                var options = new Options();
                if (!CommandLine.Parser.Default.ParseArguments(userInput.Split(' '), options,
                                                               (verb, subOptions) =>
                {
                    invokedVerb = verb;
                    invokedVerbInstance = subOptions;
                }))
                {
                    Console.WriteLine($"Unrecognized command: {userInput}.");
                    PrintUsage();
                    continue;
                }

                switch (invokedVerb)
                {
                case "exit":

                    exit = true;
                    Console.WriteLine("Exiting test runner.");
                    scheduler.CancelAllTestRuns();

                    continue;

                case "start":

                    var startRunOptions = (StartNewTestRunOptions)invokedVerbInstance;
                    Console.WriteLine($"Starting test run of {startRunOptions.TestSuiteName}.");

                    Guid testRunId = scheduler.StartNewTestRun(startRunOptions.TestSuiteName);

                    Console.WriteLine($"Started test run with id {testRunId}.");
                    break;

                case "status":

                    var statusOptions = (CommonOptions)invokedVerbInstance;

                    try
                    {
                        Console.WriteLine($"Retrieving status of test run with id {statusOptions.TestRunGuid}.");
                        TestRunStatus status = scheduler.GetTestRunStatus(Guid.Parse(statusOptions.TestRunGuid));
                        Console.WriteLine(status);
                    }
                    catch (TestRunNotFoundException ex)
                    {
                        Console.WriteLine("Failed to retrieve status of test run:");
                        Console.WriteLine(ex.Message);
                    }

                    break;

                case "results":

                    var resultsOptions = (CommonOptions)invokedVerbInstance;

                    try
                    {
                        Console.WriteLine($"Retrieving results of test run with id {resultsOptions.TestRunGuid}.");
                        TestRunResults results = scheduler.GetTestRunResults(Guid.Parse(resultsOptions.TestRunGuid));
                        Console.WriteLine(results);
                    }
                    catch (TestRunNotFoundException ex)
                    {
                        Console.WriteLine("Failed to retrieve results of test run:");
                        Console.WriteLine(ex.Message);
                    }

                    break;

                case "cancel":

                    var cancelRunOptions = (CommonOptions)invokedVerbInstance;

                    try
                    {
                        Console.WriteLine($"Canceling test run with id {cancelRunOptions.TestRunGuid}.");
                        scheduler.CancelTestRun(Guid.Parse(cancelRunOptions.TestRunGuid));
                        Console.WriteLine("Test run canceled.");
                    }
                    catch (TestRunNotFoundException ex)
                    {
                        Console.WriteLine("Failed to cancel test run:");
                        Console.WriteLine(ex.Message);
                    }

                    break;
                }
            }
        }