/// <summary> /// Validates If a Custom test property is valid and then adds it to the TestContext property list. /// </summary> /// <param name="testMethodInfo"> The test method info. </param> /// <param name="testContext"> The test context. </param> /// <param name="propertyName"> The property name. </param> /// <param name="propertyValue"> The property value. </param> /// <returns> True if its a valid Test Property. </returns> private bool ValidateAndAssignTestProperty( TestMethodInfo testMethodInfo, ITestContext testContext, string propertyName, string propertyValue) { if (PredefinedNames.Any(predefinedProp => predefinedProp == propertyName)) { testMethodInfo.NotRunnableReason = string.Format( CultureInfo.CurrentCulture, Resource.UTA_ErrorPredefinedTestProperty, testMethodInfo.TestMethod.DeclaringType.FullName, testMethodInfo.TestMethod.Name, propertyName); return(false); } if (string.IsNullOrEmpty(propertyName)) { testMethodInfo.NotRunnableReason = string.Format( CultureInfo.CurrentCulture, Resource.UTA_ErrorTestPropertyNullOrEmpty, testMethodInfo.TestMethod.DeclaringType.FullName, testMethodInfo.TestMethod.Name); return(false); } object existingValue; if (testContext.TryGetPropertyValue(propertyName, out existingValue)) { // Do not add to the test context because it would conflict with an already existing value. // We were at one point reporting a warning here. However with extensibility centered around TestProperty where // users can have multiple WorkItemAttributes(say) we cannot throw a warning here. Users would have multiple of these attributes // so that it shows up in reporting rather than seeing them in TestContext properties. } else { testContext.AddProperty(propertyName, propertyValue); } return(true); }