示例#1
0
        private static void serializeToFile(TestPropertyCollection testProperties, List <Type> knownTypes, string filePath)
        {
            try
            {
                //TODO Remove?
                //knownTypes.Add(typeof(TestListenerCollection));

                DataContractSerializer serializer = new DataContractSerializer(typeof(TestPropertyCollection), knownTypes);

                var settings = new XmlWriterSettings()
                {
                    Indent = true
                };

                using (var writer = XmlWriter.Create(filePath, settings))
                {
                    serializer.WriteObject(writer, testProperties);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
            }
        }
 public TestScriptObjectContainer(string title, TestSuite parent)
     : base(title, parent)
 {
     _created           = DateTime.Now;
     _author            = Environment.UserName;
     _testScriptObjects = new TestScriptObjectCollection();
     _status            = Core.Status.Active;
     _testProperties    = new TestPropertyCollection();
 }
示例#3
0
        //public static int VirtualUsers
        //{ get { return GetPropertyValueAsInt("VirtualUsers"); } }

        //public static TimeSpan LaunchDuration
        //{ get { return GetPropertyValueAsTimeSpan("LaunchDuration"); } }

        #endregion

        #region Class public methods

        public static void Initialize()
        {
            _testPropertyCollection = new TestPropertyCollection();

            addSystemProperties();

            TestPropertiesFile = null;

            FireTestPropertiesInitializedEvent();
        }
示例#4
0
        /// <summary>
        /// Writes a test property collection to a valid XMLWriter for subsequent serialization
        /// </summary>
        /// <param name="xmlWriter"></param>
        /// <param name="testProperties"></param>
        internal static void Write(XmlWriter xmlWriter, TestPropertyCollection testProperties)
        {
            xmlWriter.WriteStartElement("TestProperties");

            foreach (var testProperty in testProperties)
            {
                xmlWriter.WriteStartElement("TestProperties");

                xmlWriter.WriteElementString("Name", testProperty.Name);
                xmlWriter.WriteElementString("Description", testProperty.Description);
                xmlWriter.WriteElementString("Value", testProperty.Value.ToString());
                xmlWriter.WriteElementString("Active", testProperty.Active.ToString());

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
示例#5
0
        public static void Save(string filePath, List <Type> knownTypes)
        {
            TestAssert.IsNotNull(_testPropertyCollection, "The TestProperties collection must be initialized before use.");

            // Want to exclude system properties that are read only from serialization.
            TestPropertyCollection tempCollection = new TestPropertyCollection();

            foreach (TestProperty property in _testPropertyCollection)
            {
                tempCollection.Add(property);
            }

            if (knownTypes == null)
            {
                knownTypes = new List <Type>();
                knownTypes.Add(typeof(TestProperty));
                knownTypes.Add(typeof(TestSystemProperty));
            }

            serializeToFile(tempCollection, knownTypes, filePath);
        }
示例#6
0
        private static TestPropertyCollection deserializeFromFile(string filePath, List <Type> knownTypes)
        {
            FileStream             reader         = null;
            TestPropertyCollection testProperties = null;

            try
            {
                //TODO:  05/25/2018, remove?
                //knownTypes.Add(typeof(TestListenerCollection));
                knownTypes.Add(typeof(TestProperty));
                knownTypes.Add(typeof(TestSystemProperty));

                // Create DataContractSerializer.
                DataContractSerializer serializer =
                    new System.Runtime.Serialization.DataContractSerializer(typeof(TestPropertyCollection), knownTypes);

                // Create a file stream to read into.
                reader = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                // Read into object.
                testProperties = serializer.ReadObject(reader) as TestPropertyCollection;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (reader != null)
                {
                    // Close file.
                    reader.Close();
                }
            }

            return(testProperties);
        }
        public TestScriptObjectContainer(TestScriptObjectContainer originalTestScriptObjectContainer, TestScriptObjectContainer parent)
            : base(originalTestScriptObjectContainer, parent)
        {
            _functionalArea = TestUtils.SafeCopyString(originalTestScriptObjectContainer._functionalArea);
            _reference      = TestUtils.SafeCopyString(originalTestScriptObjectContainer._reference);
            _author         = Environment.UserName;
            _created        = originalTestScriptObjectContainer._created;

            _testProperties = new TestPropertyCollection();

            foreach (TestProperty testProperty in originalTestScriptObjectContainer._testProperties)
            {
                _testProperties.Add(new TestProperty(testProperty));
            }

            _testScriptObjects = new TestScriptObjectCollection();

            foreach (TestScriptObject testScriptObject in originalTestScriptObjectContainer._testScriptObjects)
            {
                TestScriptObject newObject = null;

                if (testScriptObject is TestSuite)
                {
                    newObject = new TestSuite((TestSuite)testScriptObject, null, (TestSuite)this);
                }
                else if (testScriptObject is TestCase)
                {
                    newObject = new TestCase((TestCase)testScriptObject, (TestSuite)this);
                }
                else if (testScriptObject is TestStep)
                {
                    newObject = new TestStep((TestStep)testScriptObject, (TestCase)this);
                }

                _testScriptObjects.Add(newObject);
            }
        }
        public TestCaseResult Execute()
        {
            string currentUser = Thread.CurrentThread.Name;

            FireExecutionBeginEvent(this, new TestCaseBeginExecutionArgs(currentUser));

            TestCaseResult testCaseResult = new TestCaseResult();

            testCaseResult.SetReferenceID(SystemID);
            testCaseResult.SetVirtualUser(currentUser);

            // Save copy of test property collection for restoration later (maintains scope)
            TestPropertyCollection savedTestPropertyCollection = new TestPropertyCollection(Core.TestProperties.TestPropertyCollection);

            AddRuntimeTestPropertiesToTestProperties();

            _testClassDictionary = new Dictionary <int, TestClassBase>();

            List <TestScriptObject> activeTestSteps = getActiveChildren();

            testCaseResult.SetStartTime(DateTime.Now);

            if (activeTestSteps.Count > 0)
            {
                // Iterate through each test step.
                foreach (TestStep testStep in activeTestSteps)
                {
                    // Only execute active test steps.
                    if (testStep.Status == Core.Status.Active)
                    {
                        // Stop if test case already failed (i.e., a previous test step has failed...UNLESS
                        // a) the test case is marked to continue on failure (continue regardless of previous failures.
                        // b) a specific test step is marked to always execute (regardless of previous failures).
                        if ((testCaseResult.TestVerdict != TestVerdict.Fail || OnTestStepFailure == OnFailure.Continue) || testStep.AlwaysExecute)
                        {
                            var producerResult = getProducerStepResult(testStep, testCaseResult);
                            var testStepResult = testStep.Execute(_testClassDictionary);

                            testCaseResult.AddResult(testStepResult);
                            testCaseResult.IncrementCounter(testStepResult.TestVerdict);

                            if (testStepResult.TestVerdict != TestVerdict.Pass)
                            {
                                testCaseResult.FinalizeVerdict();
                            }
                        }
                        else
                        {
                            var testStepResult = new TestStepResult(TestVerdict.DidNotExecute,
                                                                    "Did not execute as a previous step failed the test case." +
                                                                    "  To always run, consider setting the \"Always Run\" property to true.");
                            testCaseResult.AddResult(testStepResult);
                            testCaseResult.IncrementCounter(testStepResult.TestVerdict);
                            testStep.FireExecutionCompleteEvent(testStep, testStepResult);
                        }
                    }
                }
            }
            else
            {
                testCaseResult.SetTestVerdict(TestVerdict.DidNotExecute);
                testCaseResult.SetTestMessage("The test case is set to \"Active\", however it does not contain active test steps.");
            }

            testCaseResult.SetEndTime(DateTime.Now);
            testCaseResult.FinalizeVerdict();

            // Restore preserved test property collection.
            Core.TestProperties.SetTestPropertyCollection(savedTestPropertyCollection);

            FireExecutionCompleteEvent(this, testCaseResult);

            return(testCaseResult);
        }
示例#9
0
        //internal static void Read(XPathNavigator nav)
        //{
        //    XPathNodeIterator iterator = nav.Select("TestProperty");

        //    string key, val;

        //    while (iterator.MoveNext())
        //    {
        //        key = iterator.Current.GetAttribute("key", "");
        //        val = iterator.Current.GetAttribute("value", "");

        //        if (key.Length != 0 && val.Length != 0)
        //        {
        //            this.m_properties.Add(key, val);
        //        }
        //    }
        //}

        public static void SetTestPropertyCollection(TestPropertyCollection testPropertyCollection)
        {
            _testPropertyCollection = testPropertyCollection;
        }
 public TestPropertyCollection(TestPropertyCollection testPropertyCollection)
     : base(testPropertyCollection)
 {
 }
示例#11
0
        //public static int VirtualUsers
        //{ get { return GetPropertyValueAsInt("VirtualUsers"); } }

        //public static TimeSpan LaunchDuration
        //{ get { return GetPropertyValueAsTimeSpan("LaunchDuration"); } }

        #endregion

        #region Class public methods

        public static void Initialize()
        {
            _testPropertyCollection = new TestPropertyCollection();

            addSystemProperties();
        }
示例#12
0
        public TestSuiteResult Execute(List <TestCase> discreteTestCases)
        {
            string virtualUser = Thread.CurrentThread.Name;

            FireExecutionBeginEvent(this, new TestSuiteBeginExecutionArgs(virtualUser));

            CheckForPossibleBreakpointMode();

            _qualifiedTestCases = discreteTestCases;

            TestSuiteResult testSuiteResult = new TestSuiteResult();

            testSuiteResult.SetReferenceID(SystemID);
            testSuiteResult.SetVirtualUser(virtualUser);

            // Save copy of test property collection for restoration later (maintains scope)
            TestPropertyCollection savedTestPropertyCollection = new TestPropertyCollection(Core.TestProperties.TestPropertyCollection);

            AddRuntimeTestPropertiesToTestProperties();

            List <TestScriptObject> activeTestScriptObjects = getActiveChildren();

            testSuiteResult.SetStartTime(DateTime.Now);

            if (activeTestScriptObjects.Count > 0)
            {
                // Execute pre-processor
                TestProcessorResult processorResult = new TestProcessorResult();

                if (TestPreprocessor.Status == Core.Status.Active)
                {
                    fireTestPreprocessorBegin(this, new TestProcessorBeginExecutionArgs(virtualUser));

                    processorResult = TestPreprocessor.Execute();

                    fireTestPreprocessorComplete(this, processorResult);

                    //Update test suite result.
                    testSuiteResult.SetTestPreprocessorResult(processorResult);
                }

                if ((processorResult.TestVerdict != TestVerdict.Fail && processorResult.TestVerdict != TestVerdict.Error) ||
                    TestPreprocessor.OnFailure != OnFailure.Stop)
                {
                    // Iterate through suites test script objects
                    foreach (TestScriptObject testScriptObject in TestScriptObjects)
                    {
                        // Only execute Active objects.
                        if (testScriptObject.Status == Core.Status.Active)
                        {
                            if (testScriptObject is TestCase)
                            {
                                TestCase testCase = testScriptObject as TestCase;

                                if (isQualifiedTestCase(testCase))
                                {
                                    var testScriptResult = testCase.Execute();
                                    testSuiteResult.IncrementCounter(testScriptResult.TestVerdict);
                                    testSuiteResult.AddResult(testScriptResult);
                                }
                            }
                            else if (testScriptObject is TestSuite)
                            {
                                TestSuite childSuite       = testScriptObject as TestSuite;
                                var       testScriptResult = childSuite.Execute(discreteTestCases);
                                testSuiteResult.IncrementCounters(testScriptResult);
                                testSuiteResult.AddResult(testScriptResult);
                            }
                        }
                    }
                }
                else
                {
                    if (!TestPreprocessor.IgnoreResult)
                    {
                        testSuiteResult.SetTestVerdict(processorResult.TestVerdict);
                        testSuiteResult.SetTestMessage("The test pre-processor failed, test suite execution stopped per setting.");
                    }
                    else
                    {
                        testSuiteResult.SetTestMessage("The test pre-processor failure ignored per setting.");
                    }
                }

                // Execute post-processor
                if (TestPostprocessor.Status == Core.Status.Active)
                {
                    fireTestPostprocessorBegin(this, new TestProcessorBeginExecutionArgs(virtualUser));

                    processorResult = TestPostprocessor.Execute();

                    fireTestPostprocessorComplete(this, processorResult);

                    if (!TestPostprocessor.IgnoreResult)
                    {
                        //Update test suite result.
                        testSuiteResult.SetTestPostprocessorResult(processorResult);
                    }
                }
            }
            else
            {
                // testSuiteResult.SetTestVerdict(TestVerdict.DidNotExecute);
                testSuiteResult.SetTestMessage("The test suite is set to \"Active\", however it does not contain any active test cases or suites.");
            }

            testSuiteResult.SetEndTime(DateTime.Now);

            testSuiteResult.FinalizeVerdict();

            // Restore preserved test property collection.
            Core.TestProperties.SetTestPropertyCollection(savedTestPropertyCollection);

            FireExecutionCompleteEvent(this, testSuiteResult);

            return(testSuiteResult);
        }
示例#13
0
        public TestCaseResult Execute()
        {
            string currentUser = Thread.CurrentThread.Name;

            FireExecutionBeginEvent(this, new TestCaseBeginExecutionArgs(currentUser));

            CheckForPossibleBreakpointMode();

            TestCaseResult testCaseResult = new TestCaseResult();

            testCaseResult.SetReferenceID(SystemID);
            testCaseResult.SetVirtualUser(currentUser);

            // Save copy of test property collection for restoration later (maintains scope)
            TestPropertyCollection savedTestPropertyCollection = new TestPropertyCollection(Core.TestProperties.TestPropertyCollection);

            AddRuntimeTestPropertiesToTestProperties();

            _testClassDictionary = new Dictionary <int, TestClassBase>();

            List <TestScriptObject> activeTestSteps = getActiveChildren();

            testCaseResult.SetStartTime(DateTime.Now);

            if (activeTestSteps.Count > 0)
            {
                // Iterate through each test step.
                foreach (TestStep testStep in activeTestSteps)
                {
                    var explanation = string.Empty;

                    // Determine is test steup should be run.  If so, execute.
                    if (determineExecutionStatus(testStep, testCaseResult, out explanation))
                    {
                        var testStepResult = testStep.Execute(_testClassDictionary);

                        testCaseResult.AddResult(testStepResult);
                        testCaseResult.IncrementCounter(testStepResult.TestVerdict);

                        if (testStepResult.TestVerdict != TestVerdict.Pass)
                        {
                            testCaseResult.FinalizeVerdict();
                        }
                    }
                    else
                    {
                        var testStepResult = new TestStepResult(TestVerdict.DidNotExecute, explanation);
                        testCaseResult.AddResult(testStepResult);
                        testCaseResult.IncrementCounter(testStepResult.TestVerdict);
                        testStep.FireExecutionCompleteEvent(testStep, testStepResult);
                    }
                }
            }
            else
            {
                testCaseResult.SetTestVerdict(TestVerdict.DidNotExecute);
                testCaseResult.SetTestMessage("The test case is set to \"Active\", however it does not contain active test steps.");
            }

            testCaseResult.SetEndTime(DateTime.Now);
            testCaseResult.FinalizeVerdict();

            // Restore preserved test property collection.
            Core.TestProperties.SetTestPropertyCollection(savedTestPropertyCollection);

            FireExecutionCompleteEvent(this, testCaseResult);

            return(testCaseResult);
        }