/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected override object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { ValidateArg.NotNull(property, "property"); switch (property.Id) { case "TestResult.ComputerName": return(this.ComputerName); case "TestResult.DisplayName": return(this.DisplayName); case "TestResult.Duration": return(this.Duration); case "TestResult.EndTime": return(this.EndTime); case "TestResult.ErrorMessage": return(this.ErrorMessage); case "TestResult.ErrorStackTrace": return(this.ErrorStackTrace); case "TestResult.Outcome": return(this.Outcome); case "TestResult.StartTime": return(this.StartTime); } return(base.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected override object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { if (property is null) { throw new ArgumentNullException(nameof(property)); } switch (property.Id) { case "TestCase.CodeFilePath": return(this.CodeFilePath); case "TestCase.DisplayName": return(this.DisplayName); case "TestCase.ExecutorUri": return(this.ExecutorUri); case "TestCase.FullyQualifiedName": return(this.FullyQualifiedName); case "TestCase.Id": return(this.Id); case "TestCase.LineNumber": return(this.LineNumber); case "TestCase.Source": return(this.Source); } // It is a custom test case property. Should be retrieved from the TestObject store. return(base.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Set TestProperty's value /// </summary> protected override void ProtectedSetPropertyValue(TestProperty property, object value) { if (property is null) { throw new ArgumentNullException(nameof(property)); } switch (property.Id) { case "TestResult.ComputerName": this.ComputerName = (string)value; return; case "TestResult.DisplayName": this.DisplayName = (string)value; return; case "TestResult.Duration": this.Duration = (TimeSpan)value; return; case "TestResult.EndTime": this.EndTime = (DateTimeOffset)value; return; case "TestResult.ErrorMessage": this.ErrorMessage = (string)value; return; case "TestResult.ErrorStackTrace": this.ErrorStackTrace = (string)value; return; case "TestResult.Outcome": this.Outcome = (TestOutcome)value; return; case "TestResult.StartTime": this.StartTime = (DateTimeOffset)value; return; } base.ProtectedSetPropertyValue(property, value); }
/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected override object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { ValidateArg.NotNull(property, "property"); switch (property.Id) { case "TestCase.CodeFilePath": return(this.CodeFilePath); case "TestCase.DisplayName": return(this.DisplayName); case "TestCase.ExecutorUri": return(this.ExecutorUri); case "TestCase.FullyQualifiedName": return(this.FullyQualifiedName); case "TestCase.Id": return(this.Id); case "TestCase.LineNumber": return(this.LineNumber); case "TestCase.Source": return(this.Source); } // It is a custom test case property. Should be retrieved from the TestObject store. return(base.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Set TestProperty's value /// </summary> protected override void ProtectedSetPropertyValue(TestProperty property, object value) { ValidateArg.NotNull(property, "property"); switch (property.Id) { case "TestCase.CodeFilePath": this.CodeFilePath = (string)value; return; case "TestCase.DisplayName": this.DisplayName = (string)value; return; case "TestCase.ExecutorUri": this.ExecutorUri = value as Uri ?? new Uri((string)value); return; case "TestCase.FullyQualifiedName": this.FullyQualifiedName = (string)value; return; case "TestCase.Id": this.Id = value is Guid ? (Guid)value : Guid.Parse((string)value); return; case "TestCase.LineNumber": this.LineNumber = (int)value; return; case "TestCase.Source": this.Source = (string)value; return; } // It is a custom test case property. Should be set in the TestObject store. base.ProtectedSetPropertyValue(property, value); }
/// <summary> /// Set TestProperty's value /// </summary> protected override void ProtectedSetPropertyValue(TestProperty property, object value) { ValidateArg.NotNull(property, "property"); switch (property.Id) { case "TestResult.ComputerName": this.ComputerName = (string)value; return; case "TestResult.DisplayName": this.DisplayName = (string)value; return; case "TestResult.Duration": this.Duration = (TimeSpan)value; return; case "TestResult.EndTime": this.EndTime = (DateTimeOffset)value; return; case "TestResult.ErrorMessage": this.ErrorMessage = (string)value; return; case "TestResult.ErrorStackTrace": this.ErrorStackTrace = (string)value; return; case "TestResult.Outcome": this.Outcome = (TestOutcome)value; return; case "TestResult.StartTime": this.StartTime = (DateTimeOffset)value; return; } base.ProtectedSetPropertyValue(property, value); }
/// <summary> /// Returns TestProperty's value /// </summary> /// <returns>property's value. default value is returned if the property is not present</returns> public T GetPropertyValue <T>(TestProperty property, T defaultValue, CultureInfo culture) { ValidateArg.NotNull(property, "property"); ValidateArg.NotNull(culture, "culture"); object objValue = this.ProtectedGetPropertyValue(property, defaultValue); return(ConvertPropertyTo <T>(property, culture, objValue)); }
/// <summary> /// Convert passed in value into the specified type when property is registered. /// </summary> /// <returns>Converted object</returns> private static T ConvertPropertyTo <T>(TestProperty property, CultureInfo culture, object value) { ValidateArg.NotNull(property, nameof(property)); ValidateArg.NotNull(culture, nameof(culture)); if (value == null) { return(default);
/// <summary> /// Set TestProperty's value to the specified value T. /// </summary> public void SetPropertyValue <T>(TestProperty property, T value, CultureInfo culture) { ValidateArg.NotNull(property, nameof(property)); ValidateArg.NotNull(culture, nameof(culture)); object objValue = ConvertPropertyFrom <T>(property, culture, value); this.ProtectedSetPropertyValue(property, objValue); }
/// <summary> /// Remove test property from the current TestObject. /// </summary> /// <param name="property"></param> public void RemovePropertyValue(TestProperty property) { ValidateArg.NotNull(property, nameof(property)); if (this.store.TryGetValue(property, out var value)) { this.store.Remove(property); } }
/// <summary> /// Set TestProperty's value to the specified value T. /// </summary> public void SetPropertyValue <T>(TestProperty property, LazyPropertyValue <T> value, CultureInfo culture) { ValidateArg.NotNull(property, "property"); ValidateArg.NotNull(culture, "culture"); object objValue = ConvertPropertyFrom <T>(property, culture, value); this.ProtectedSetPropertyValue(property, objValue); }
/// <summary> /// Remove test property from the current TestObject. /// </summary> /// <param name="property"></param> public void RemovePropertyValue(TestProperty property) { ValidateArg.NotNull(property, "property"); object value; if (this.store.TryGetValue(property, out value)) { this.store.Remove(property); } }
/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected virtual object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { ValidateArg.NotNull(property, nameof(property)); if (!this.store.TryGetValue(property, out var value)) { value = defaultValue; } return(value); }
/// <summary> /// Return TMI Test id when available for TestPlatform TestCase. /// </summary> /// <param name="rockSteadyTestCase"> /// The rock Steady Test Case. /// </param> /// <returns> /// The <see cref="Guid"/>. /// </returns> private static Guid GetTmiTestId(ObjectModel.TestCase rockSteadyTestCase) { Guid tmiTestId = Guid.Empty; ObjectModel.TestProperty tmiTestIdProperty = rockSteadyTestCase.Properties.FirstOrDefault(property => property.Id.Equals(TmiTestIdPropertyIdentifier)); if (null != tmiTestIdProperty) { tmiTestId = rockSteadyTestCase.GetPropertyValue(tmiTestIdProperty, Guid.Empty); } return(tmiTestId); }
/// <summary> /// Convert passed in value from TestProperty's specified value type. /// </summary> /// <returns>Converted object</returns> private static object ConvertPropertyFrom <T>(TestProperty property, CultureInfo culture, object value) { if (property is null) { throw new ArgumentNullException(nameof(property)); } if (culture is null) { throw new ArgumentNullException(nameof(culture)); } var valueType = property.GetValueType(); // Do not try conversion if the object is already of the type we're trying to convert. // Note that typeof(T) may be object in case the value is getting deserialized via the StoreKvpList, however // the de-serializer could have converted it already, hence the runtime type check. if (valueType != null && (valueType.GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()) || valueType.GetTypeInfo().IsAssignableFrom(value?.GetType().GetTypeInfo()))) { return(value); } // Traits are KeyValuePair based. Use the custom converter in that case. if (valueType == typeof(KeyValuePair <string, string>[])) { return(keyValueConverter.ConvertFrom(null, culture, (string)value)); } // Use a custom string array converter for string[] types. if (valueType == typeof(string[])) { return(stringArrayConverter.ConvertFrom(null, culture, (string)value)); } TypeConverter converter = TypeDescriptor.GetConverter(valueType); if (converter == null) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, ConverterNotSupported, valueType.Name)); } try { return(converter.ConvertFrom(null, culture, value)); } catch (FormatException) { throw; } catch (Exception e) { // some type converters throw strange exceptions (e.g.: System.Exception by Int32Converter) throw new FormatException(e.Message, e); } }
/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> private object PrivateGetPropertyValue(TestProperty property, object defaultValue) { ValidateArg.NotNull(property, "property"); object value; if (!this.store.TryGetValue(property, out value)) { value = defaultValue; } return(value); }
/// <summary> /// Set TestProperty's value /// </summary> protected virtual void ProtectedSetPropertyValue(TestProperty property, object value) { ValidateArg.NotNull(property, "property"); if (property.ValidateValueCallback == null || property.ValidateValueCallback(value)) { this.store[property] = value; } else { throw new ArgumentException(property.Label); } }
/// <summary> /// Returns property value of the specify TestProperty /// </summary> /// <param name="property">TestObject's TestProperty</param> /// <returns>property value</returns> public object GetPropertyValue(TestProperty property) { ValidateArg.NotNull(property, "property"); object defaultValue = null; var valueType = property.GetValueType(); if (valueType != null && valueType.GetTypeInfo().IsValueType) { defaultValue = Activator.CreateInstance(valueType); } return(this.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Remove test property from the current TestObject. /// </summary> /// <param name="property"></param> public void RemovePropertyValue(TestProperty property) { if (property is null) { throw new ArgumentNullException(nameof(property)); } object value; if (this.store.TryGetValue(property, out value)) { this.store.Remove(property); } }
/// <summary> /// Convert passed in value into the specified type when property is registered. /// </summary> /// <returns>Converted object</returns> private static T ConvertPropertyTo <T>(TestProperty property, CultureInfo culture, object value) { if (property is null) { throw new ArgumentNullException(nameof(property)); } if (culture is null) { throw new ArgumentNullException(nameof(culture)); } //var lazyValue = value as LazyPropertyValue<T>; if (value == null) { return(default(T)); } else if (value is T) { return((T)value); } //else if (lazyValue != null) //{ // return lazyValue.Value; //} var valueType = property.GetValueType(); TypeConverter converter = TypeDescriptor.GetConverter(valueType); if (converter == null) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, ConverterNotSupported, valueType.Name)); } try { return((T)converter.ConvertTo(null, culture, value, typeof(T))); } catch (FormatException) { throw; } catch (Exception e) { // some type converters throw strange exceptions (e.g.: System.Exception by Int32Converter) throw new FormatException(e.Message, e); } }
/// <summary> /// Returns TestProperty's value /// </summary> /// <returns>property's value. default value is returned if the property is not present</returns> public T GetPropertyValue <T>(TestProperty property, T defaultValue, CultureInfo culture) { if (property is null) { throw new ArgumentNullException(nameof(property)); } if (culture is null) { throw new ArgumentNullException(nameof(culture)); } object objValue = this.ProtectedGetPropertyValue(property, defaultValue); return(ConvertPropertyTo <T>(property, culture, objValue)); }
/// <summary> /// Set TestProperty's value to the specified value T. /// </summary> public void SetPropertyValue <T>(TestProperty property, T value, CultureInfo culture) { if (property is null) { throw new ArgumentNullException(nameof(property)); } if (culture is null) { throw new ArgumentNullException(nameof(culture)); } object objValue = ConvertPropertyFrom <T>(property, culture, value); this.ProtectedSetPropertyValue(property, objValue); }
///// <summary> ///// Set TestProperty's value to the specified value T. ///// </summary> //public void SetPropertyValue<T>(TestProperty property, LazyPropertyValue<T> value, CultureInfo culture) //{ // if (property is null) // throw new ArgumentNullException(nameof(property)); // if (culture is null) // throw new ArgumentNullException(nameof(culture)); // object objValue = ConvertPropertyFrom<T>(property, culture, value); // this.ProtectedSetPropertyValue(property, objValue); //} #endregion Property Values #region Helpers /// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected virtual object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { if (property is null) { throw new ArgumentNullException(nameof(property)); } object value; if (!this.store.TryGetValue(property, out value)) { value = defaultValue; } return(value); }
/// <summary> /// Set TestProperty's value /// </summary> protected virtual void ProtectedSetPropertyValue(TestProperty property, object value) { if (property is null) { throw new ArgumentNullException(nameof(property)); } if (property.ValidateValueCallback == null || property.ValidateValueCallback(value)) { this.store[property] = value; } else { throw new ArgumentException(property.Label); } }
/// <summary> /// Returns property value of the specify TestProperty /// </summary> /// <param name="property">TestObject's TestProperty</param> /// <returns>property value</returns> public object GetPropertyValue(TestProperty property) { if (property is null) { throw new ArgumentNullException(nameof(property)); } object defaultValue = null; var valueType = property.GetValueType(); if (valueType != null && valueType.GetTypeInfo().IsValueType) { defaultValue = Activator.CreateInstance(valueType); } return(this.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Convert passed in value into the specified type when property is registered. /// </summary> /// <returns>Converted object</returns> private static T ConvertPropertyTo <T>(TestProperty property, CultureInfo culture, object value) { ValidateArg.NotNull(property, "property"); ValidateArg.NotNull(culture, "culture"); var lazyValue = value as LazyPropertyValue <T>; if (value == null) { return(default(T)); } else if (value is T) { return((T)value); } else if (lazyValue != null) { return(lazyValue.Value); } var valueType = property.GetValueType(); TypeConverter converter = TypeDescriptor.GetConverter(valueType); if (converter == null) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.ConverterNotSupported, valueType.Name)); } try { return((T)converter.ConvertTo(null, culture, value, typeof(T))); } catch (FormatException) { throw; } catch (Exception e) { // some type converters throw strange exceptions (eg: System.Exception by Int32Converter) throw new FormatException(e.Message, e); } }
/// <summary> /// Gets test id. /// Return TMI Test id when available for TestPlatform test case. /// </summary> /// <param name="rockSteadyTestCase"></param> /// <returns>Test id</returns> public static Guid GetTestId(ObjectModel.TestCase rockSteadyTestCase) { Guid testId = Guid.Empty; // Setting test id to tmi test id. ObjectModel.TestProperty tmiTestIdProperty = rockSteadyTestCase.Properties.FirstOrDefault( property => property.Id.Equals(Constants.TmiTestIdPropertyIdentifier)); if (null != tmiTestIdProperty) { testId = rockSteadyTestCase.GetPropertyValue(tmiTestIdProperty, Guid.Empty); } // If tmi test id not present, picking from platform test id. if (Guid.Empty.Equals(testId)) { testId = rockSteadyTestCase.Id; } return(testId); }
/// <summary> /// Return TestProperty's value /// </summary> /// <returns></returns> protected override object ProtectedGetPropertyValue(TestProperty property, object defaultValue) { if (property is null) { throw new ArgumentNullException(nameof(property)); } switch (property.Id) { case "TestResult.ComputerName": return(this.ComputerName); case "TestResult.DisplayName": return(this.DisplayName); case "TestResult.Duration": return(this.Duration); case "TestResult.EndTime": return(this.EndTime); case "TestResult.ErrorMessage": return(this.ErrorMessage); case "TestResult.ErrorStackTrace": return(this.ErrorStackTrace); case "TestResult.Outcome": return(this.Outcome); case "TestResult.StartTime": return(this.StartTime); } return(base.ProtectedGetPropertyValue(property, defaultValue)); }
/// <summary> /// Convert passed in value from TestProperty's specified value type. /// </summary> /// <returns>Converted object</returns> private static object ConvertPropertyFrom <T>(TestProperty property, CultureInfo culture, object value) { ValidateArg.NotNull(property, "property"); ValidateArg.NotNull(culture, "culture"); var valueType = property.GetValueType(); // Do not try conversion if the object is already of the type we're trying to convert. // Note that typeof(T) may be object in case the value is getting deserialized via the StoreKvpList, however // the deserializer could have converted it already, hence the runtime type check. if (valueType != null && (valueType.GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()) || valueType.GetTypeInfo().IsAssignableFrom(value?.GetType().GetTypeInfo()))) { return(value); } TypeConverter converter = TypeDescriptor.GetConverter(valueType); if (converter == null) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.ConverterNotSupported, valueType.Name)); } try { return(converter.ConvertFrom(null, culture, value)); } catch (FormatException) { throw; } catch (Exception e) { // some type converters throw strange exceptions (eg: System.Exception by Int32Converter) throw new FormatException(e.Message, e); } }
/// <summary> /// Set TestProperty's value /// </summary> /// <param name="property">TestObject's TestProperty</param> /// <param name="value">value to be set</param> public void SetPropertyValue(TestProperty property, object value) { this.ProtectedSetPropertyValue(property, value); }