/// <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); }
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); } }
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>()); }
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); }
/// <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(); }
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); }