Esempio n. 1
0
        public string GetTestRunNameFromListOfTestsToRun(List <TestToRun> listOfTestsToRun)
        {
            TestToRun firstOrDefault = listOfTestsToRun.FirstOrDefault();

            if (firstOrDefault != null)
            {
                return(firstOrDefault.Arguments[1]);
            }

            return("Could not find name.");
        }
Esempio n. 2
0
        public List <TestToRun> GetTestsToRun(TestLibraryContainer testLibraryContainer, string assemblyLocation, string projectName, List <string> namespaces)
        {
            var testToRuns = new List <TestToRun>();

            if (namespaces != null)
            {
                foreach (var testClass in testLibraryContainer.TestClasses)
                {
                    foreach (var ns in namespaces)
                    {
                        if (testClass.Name.Contains(ns))
                        {
                            foreach (var testMethod in testClass.TestMethods)
                            {
                                var testToRun = new TestToRun();

                                var testRecord = new TestRecord
                                {
                                    AssertCount = testMethod.AssertCount,
                                    DateOfTest  = DateTime.Now,
                                    Description = testMethod.Name,
                                    Executed    = false,
                                    FullName    = string.Format("{0}.{1}", testClass.Name, testMethod.Name),
                                    HasResults  = false,
                                    IsError     = false,
                                    IsFailure   = false,
                                    IsSuccess   = false,
                                    Message     = "",
                                    Time        = 0,
                                    Name        = testMethod.Name,
                                    Project     = projectName,
                                    StackTrace  = "",
                                };

                                testToRun.TestRecord = testRecord;

                                var      fixture = string.Format("/fixture:{0}", testClass.Name);
                                string[] arg     = { fixture, assemblyLocation };

                                testToRun.Arguments = arg;

                                testToRuns.Add(testToRun);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var testClass in testLibraryContainer.TestClasses)
                {
                    foreach (var testMethod in testClass.TestMethods)
                    {
                        var testToRun = new TestToRun();

                        var testRecord = new TestRecord
                        {
                            AssertCount = testMethod.AssertCount,
                            DateOfTest  = DateTime.Now,
                            Description = testMethod.Name,
                            Executed    = false,
                            FullName    = string.Format("{0}.{1}", testClass.Name, testMethod.Name),
                            HasResults  = false,
                            IsError     = false,
                            IsFailure   = false,
                            IsSuccess   = false,
                            Message     = "",
                            Time        = 0,
                            Name        = testMethod.Name,
                            Project     = projectName,
                            StackTrace  = "",
                        };

                        testToRun.TestRecord = testRecord;

                        var      fixture = string.Format("/fixture:{0}", testClass.Name);
                        string[] arg     = { fixture, assemblyLocation };

                        testToRun.Arguments = arg;

                        testToRuns.Add(testToRun);
                    }
                }
            }

            var elements = new HashSet <string>(); // Type of property

            testToRuns.RemoveAll(i => !elements.Add(i.Arguments[0]));

            return(testToRuns);
        }
Esempio n. 3
0
        public void StartPerformanceTest(TestToRun testToRun, Guid guid)
        {
            //we clone our arguments  but might not need to, need to investigate
            string[] test = CloneObject(testToRun.Arguments);

            //we lock the arguments so that we dont get any bad threading stuff
            lock (test)
            {
                Parallel.Invoke(() =>
                {
                    //set up and run our task
                    TestResult testResult = _testRunnerResultManager.CreateTestResult();

                    Task <TestResult> task = Task.Factory.StartNew(() =>
                                                                   testResult = RunPerformanceTest(test, guid)
                                                                   );

                    //some crap i got of the net
                    Task <TaskStatus> continuation = task.ContinueWith(antecedent => antecedent.Status);

                    if (continuation.Result == TaskStatus.RanToCompletion)
                    {
                        //the task ran to completion! Woo.
                        //load up our test run. This probably needs sorting.
                        TestRun testRun = _testRunnerResultManager.GetTestRun(guid);
                        List <TestResult> testResults = _testRunnerResultManager.GetTests(testResult);

                        foreach (TestResult result in testResults)
                        {
                            //map our initial record and result so we have the right information to save.
                            TestRecord recordToSave = _testRunnerResultManager.MapTestResultToTestRecord(result,
                                                                                                         testToRun.TestRecord, testRun, guid);

                            //save our record.
                            _testRunnerResultManager.SaveTestRecord(recordToSave, testRun);
                        }
                    }
                    else
                    {
                        //the task failed!!! Ohh dear.
                        //get the test run so we have its ID
                        TestRun testRun = _testRunnerResultManager.GetTestRun(guid);

                        //get the real test from the test result object NUnit has kindly passed to us.
                        TestResult resultOfTest = _testRunnerResultManager.GetTest(testResult);

                        //map our initial record and result so we have the right information to save.
                        TestRecord recordToSave = _testRunnerResultManager.MapTestResultToTestRecord(resultOfTest,
                                                                                                     testToRun.TestRecord, testRun, guid);

                        //some custom stuff becasue of the error
                        if (continuation.Exception != null)
                        {
                            testToRun.TestRecord.StackTrace = continuation.Exception.ToString();
                        }
                        if (continuation.Status != TaskStatus.RanToCompletion)
                        {
                            testToRun.TestRecord.Message = continuation.Status.ToString();
                        }

                        //save our record.
                        _testRunnerResultManager.SaveTestRecord(recordToSave, testRun);
                    }
                });
            }
        }