Пример #1
0
        public static List <TestPropertyOverride> ApplyTestPropertyOverrides(List <TestPropertyOverride> testPropertyOverrides)
        {
            List <TestPropertyOverride> unusedOverrides = new List <TestPropertyOverride>();

            if (!(testPropertyOverrides is null))
            {
                foreach (var testPropertyOverride in testPropertyOverrides)
                {
                    var property = TestProperties.GetProperty(testPropertyOverride.Name);

                    if (property != null)
                    {
                        // Preserve original value and description
                        property.OverriddenValue       = property.Value;
                        property.OverriddenDescription = property.Description;
                        property.Overridden            = true;

                        // Capture test property override
                        property.TestPropertyOverride = testPropertyOverride;

                        // Set property members to overridden values.
                        property.Value       = testPropertyOverride.Value;
                        property.Description = testPropertyOverride.Description;
                    }
                    else
                    {
                        unusedOverrides.Add(testPropertyOverride);
                    }
                }
            }

            return(unusedOverrides);
        }
Пример #2
0
        /// <summary>
        /// Searches a string for each ocurrence of a string and replaces with named property.
        /// </summary>
        /// <param name="target">Target string to fixup.</param>
        /// <param name="searchValue">String to search for and replace if found.</param>
        /// <param name="propertyName">Name of replacement property (without brackets).</param>
        /// <returns></returns>
        public static string FixupString(string target, string propertyName)
        {
            string fixedup = target;  // Preserve original string.

            // Get fixup property
            string propertyValue = Core.TestProperties.GetPropertyValueAsString(propertyName);

            int index = -1;

            // Iterate through string replacing with property
            if (target != null && propertyValue != null)
            {
                propertyValue = TestProperties.ExpandString(propertyValue);

                do
                {
                    index = fixedup.IndexOf(propertyValue, StringComparison.OrdinalIgnoreCase);

                    if (-1 != index)
                    {
                        target  = target.Remove(index, propertyValue.Length);
                        fixedup = target.Insert(index, string.Format("[{0}]", propertyName));
                    }
                } while (-1 != index);
            }

            return(fixedup);
        }
Пример #3
0
        public static void ApplyTestPropertyOverrides(Hashtable testPropertyOverrides)
        {
            foreach (DictionaryEntry testPropertyOverride in testPropertyOverrides)
            {
                var property = TestProperties.GetProperty(testPropertyOverride.Key as string);

                if (property != null)
                {
                    property.Value        = testPropertyOverride.Value;
                    property.Description += " (Test property override)";
                }
                else
                {
                    property = new TestProperty()
                    {
                        Name        = testPropertyOverride.Key as string,
                        Value       = testPropertyOverride.Value,
                        Description = "Test property override",
                        Active      = true
                    };

                    TestProperties.AddProperty(property);
                }
            }
        }
Пример #4
0
        internal void Write(XmlTextWriter xmlWriter)
        {
            // Write test method.
            xmlWriter.WriteStartElement("TestAutomationDefinition");

            // Automation values.
            xmlWriter.WriteElementString("TestAssembly", TestProperties.FixupString(_testAssembly, "TestAssemblies", "TestHome"));
            xmlWriter.WriteElementString("TestClass", _testClass);
            xmlWriter.WriteElementString("TestMethod", _testMethod);

            xmlWriter.WriteStartElement("TestParameters");

            // If test parameters exist, write.
            if (TestParameters != null)
            {
                foreach (TestParameter testParameter in _testParameters)
                {
                    // Writes parent element name.
                    xmlWriter.WriteStartElement("TestParameter");

                    // Write element attributes for name.
                    xmlWriter.WriteElementString("DisplayName", "", testParameter.DisplayName);
                    xmlWriter.WriteElementString("Name", testParameter.Name);
                    xmlWriter.WriteElementString("TypeAsString", testParameter.TypeAsString);
                    xmlWriter.WriteElementString("ValueAsString", testParameter.ValueAsString);

                    // Ends parent element.
                    xmlWriter.WriteEndElement();
                }
            }

            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
        }
Пример #5
0
        public TestAutomationDefinition(XPathNavigator navigator)
        {
            var testAssembly = TestUtils.GetXPathValue(navigator, "TestAssembly");

            _testAssembly   = TestProperties.FixupString(testAssembly, "TestAssemblies", "TestHome");
            _testClass      = TestUtils.GetXPathValue(navigator, "TestClass");
            _testMethod     = TestUtils.GetXPathValue(navigator, "TestMethod");
            _testParameters = TestParameterCollection.ReadParameters(navigator);
        }
        private void openFile(string filePath)
        {
            try
            {
                DialogResult result = DialogResult.No;

                if (_changed)
                {
                    // Prompt to save if currently loaded has changed.
                    result = promptToSave();
                }

                if (result != DialogResult.Cancel)
                {
                    if (result == DialogResult.Yes)
                    {
                        saveFile();
                    }

                    if (string.IsNullOrEmpty(filePath))
                    {
                        m_openFileDialog.InitialDirectory = TestProperties.ExpandString(TestProperties.TestConfigs);
                        result    = this.m_openFileDialog.ShowDialog(this);
                        _filePath = m_openFileDialog.FileName;
                    }
                    else
                    {
                        result = DialogResult.OK;
                    }

                    if (result == DialogResult.OK)
                    {
                        var testListeners = TestListenerCollection.DeserializeFromFile(_filePath);
                        displayListenerCollection(testListeners);
                        _testListeners = testListeners;
                        m_testListenersTreeView.Nodes[0].ToolTipText = _filePath;
                        markAsUnchanged();
                    }
                }
            }
            catch (System.Runtime.Serialization.SerializationException)
            {
                DisplayErrorMessage(
                    string.Format("Unable to access file:\r\n\r\n\"{0}\".\r\n\r\nPlease verify it is valid test listener configuration file.",
                                  m_openFileDialog.FileName));
            }
            catch (Exception exp)
            {
                DisplayErrorMessage(exp.Message);
            }
        }
Пример #7
0
        public object[] GetParameterValues()
        {
            List <object> values = new List <object>();

            foreach (TestParameter parameter in this)
            {
                var @value = parameter.GetValue();

                if (@value is string)
                {
                    @value = TestProperties.ExpandString(@value as string, true);
                }

                values.Add(@value);
            }

            return(values.ToArray <object>());
        }
Пример #8
0
        private List <object> getRuntimeParameters()
        {
            List <object> runtimeParams = new List <object>();

            foreach (TestParameter testParameter in TestParameters)
            {
                if (testParameter.ValueAsString is string)
                {
                    testParameter.ValueAsString = TestProperties.ExpandString((string)testParameter.ValueAsString);
                }

                Type type = Type.GetType(testParameter.TypeAsString);

                object value;

                TestUtils.FromString(testParameter.ValueAsString, type, out value);
            }

            return(runtimeParams);
        }
Пример #9
0
        virtual public TestVerdict DumpProperties()
        {
            try
            {
                this.Setup();

                TestMessage += TestProperties.ToString();
                TestVerdict  = Core.TestVerdict.Pass;
            }
            catch (Exception e)
            {
                this.TestMessage += e.Message;
                this.TestVerdict  = TestVerdict.Error;
            }
            finally
            {
                this.Teardown();
            }

            return(TestVerdict);
        }
Пример #10
0
 /// <summary>
 /// Convenience method around test TestProperties ExpandString method.
 /// </summary>
 /// <param name="testProperty"></param>
 /// <returns>Expanded string or original string if not expandable</returns>
 protected string ExpandString(string testProperty)
 {
     return(string.IsNullOrEmpty(testProperty) ? testProperty : TestProperties.ExpandString(testProperty));
 }
        /// <summary>
        /// Constructor for the test listeners editor dialog.
        /// </summary>
        /// <param name="filePath">File path of test listener's file.</param>
        public TestListenersEditorDialog(string filePath)
        {
            _filePath = filePath is null ? filePath : TestProperties.ExpandString(filePath);

            InitializeComponent();
        }
Пример #12
0
 public TestScriptResult()
     : base()
 {
     _virtualUser = Thread.CurrentThread.Name;
     _testRunId   = TestProperties.GetPropertyValueAsString("TestRunId");
 }
Пример #13
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);
        }