Exemplo n.º 1
0
        internal TestStepResult Execute(Dictionary <int, TestClassBase> testClassDictionary)
        {
            TestAssert.IsNotNull(TestAutomationDefinition,
                                 "The test step is marked as active, however its automation definition has not been set.");

            string currentUser = Thread.CurrentThread.Name;

            TestStepResult result = new TestStepResult();

            result.SetReferenceID(SystemID);
            result.SetVirtualUser(currentUser);
            result.SetTestVerdict(TestVerdict.Pass);

            FireExecutionBeginEvent(this, new TestStepBeginExecutionArgs(currentUser));

            TestAutomationDefinition.ResultStruct resultStruct = TestAutomationDefinition.Invoke(testClassDictionary);

            result.SetStartTime(resultStruct.StartTime);
            result.SetEndTime(resultStruct.EndTime);
            result.SetTestVerdict(determineVerdict(ExpectedTestVerdict, resultStruct.TestVerdict));
            result.SetTestMessage(resultStruct.TestMessage);
            result.SetTestChecks(resultStruct.TestChecks);
            result.SetTestWarnings(resultStruct.TestWarnings);
            result.SetTestData(resultStruct.TestData);

            FireExecutionCompleteEvent(this, result);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Iteratively processes a string all property callouts with actual property values.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string ExpandString(string source, bool ignoreEscaped)
        {
            TestAssert.IsNotNull(_testPropertyCollection, "The TestProperties collection must be initialized before use.");
            TestAssert.IsFalse(string.IsNullOrEmpty(source), "The target string key cannot be a null or empty value.");

            //source = GetPropertyValueAsString(source, source);

            string leftEscapeToken  = "&@#!~?^";
            string rightEscapeToken = "!@*&%+";

            string target        = source;
            bool   macroExpanded = false;

            TestProperty testProperty;

            if (source.ToUpper() == "[NULL]")
            {
                target = null;
            }
            else if (source.ToUpper() == "[EMPTYSTRING]")
            {
                target = "";
            }
            else
            {
                string macro = StripMacro(source, ignoreEscaped);

                if (null != macro)
                {
                    if (_testPropertyCollection.TryGetValue(macro, out testProperty))
                    {
                        if (testProperty.Value is string)
                        {
                            target        = target.Replace(string.Format("[{0}]", macro), (string)testProperty.Value);
                            macroExpanded = true;
                        }
                    }
                }

                if (macroExpanded)
                {
                    target = ExpandString(target, ignoreEscaped);
                }

                target = target.Replace(leftEscapeToken, "[");
                target = target.Replace(rightEscapeToken, "]");
            }

            return(target);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        internal ResultStruct Invoke(Dictionary <int, TestClassBase> testClassDictionary)
        {
            ResultStruct resultStruct = new ResultStruct();

            try
            {
                Assembly assembly      = TestReflection.LoadTestAssembly(TestProperties.ExpandString(TestAssembly));
                Type     testClassType = TestReflection.GetTestClass(assembly, TestClass);

                TestAssert.IsNotNull(testClassType, "The test class specified \"{0}\" cannot be located or is not a valid test class.  " +
                                     "Check the test class's TestClassAttribute has been set.", TestClass);

                Type[] types = TestParameters.GetParameterTypes();

                MethodInfo testMethod = TestReflection.GetTestMethod(testClassType, TestMethod, types);

                TestAssert.IsNotNull(testMethod, "The test method specified \"{0}\" cannot be located or it is not a valid test method.  " +
                                     "Check the test method signature is correct and the TestMethodAttribute had been set.", TestMethod);

                TestClassBase testClassInstance;
                var           virtualUser = Thread.CurrentThread.Name;
                int           hashcode    = testClassType.GetHashCode() + virtualUser.GetHashCode();

                if (testClassDictionary != null && testClassDictionary.TryGetValue(hashcode, out testClassInstance))
                {
                    testClassInstance.TestMessage = null;
                    testClassInstance.ResetTestCheckCollection();
                    testClassInstance.ResetTestWarningCollection();
                    testClassInstance.ResetTestDataCollection();
                    testClassInstance.TestVerdict = TestVerdict.Pass;
                }
                else
                {
                    testClassInstance             = Activator.CreateInstance(testClassType) as TestClassBase;
                    testClassInstance.VirtualUser = virtualUser;

                    if (testClassDictionary != null)
                    {
                        testClassDictionary.Add(hashcode, testClassInstance);
                    }
                }

                object[] values = TestParameters.GetParameterValues();

                PropertyInfo property = null;

                //TODO - this needs to be abstractedfrom TestExecutor class.
                //if (!TestExecutor.SuppressExecution)
                if (true)
                {
                    resultStruct.StartTime = DateTime.Now;

                    resultStruct.TestVerdict = (TestVerdict)testMethod.Invoke(testClassInstance, values);

                    resultStruct.EndTime = DateTime.Now;

                    property = testClassType.GetProperty("TestMessage");
                    resultStruct.TestMessage = (string)property.GetValue(testClassInstance, null);
                }
                else
                {
                    resultStruct.TestVerdict = TestVerdict.Pass;
                    resultStruct.TestMessage = "Test runtime execution has been suppressed.";
                }

                // Get properties
                property = testClassType.GetProperty("TestChecks");
                resultStruct.TestChecks = (TestCheckCollection)property.GetValue(testClassInstance, null);

                property = testClassType.GetProperty("TestWarnings");
                resultStruct.TestWarnings = (TestWarningCollection)property.GetValue(testClassInstance, null);

                property = testClassType.GetProperty("TestData");
                resultStruct.TestData = (TestDataCollection)property.GetValue(testClassInstance, null);

                resultStruct = determineTestVerdict(resultStruct);
            }
            catch (Exception e)
            {
                if (e is System.Reflection.ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    var loaderExceptions  = typeLoadException.LoaderExceptions;
                }

                resultStruct.TestVerdict  = TestVerdict.Error;
                resultStruct.TestMessage += e.ToString();
            }

            return(resultStruct);
        }