public void IsVerbalParameter_ArgumentProcessorSettingWithAttribute_ResultAsExpected(Type type, Boolean expected) { ParameterObjectAttribute attribute = null; if (type == typeof(SwitchParameterAttribute)) { attribute = new SwitchParameterAttribute(); } else if (type == typeof(OptionParameterAttribute)) { attribute = new OptionParameterAttribute(); } else if (type == typeof(VerbalParameterAttribute)) { attribute = new VerbalParameterAttribute(); } else if (type == typeof(UnsupportedParameterAttribute)) { attribute = new UnsupportedParameterAttribute(); } ArgumentProcessorSetting setting = new ArgumentProcessorSetting(new TestPropertyInfo(typeof(Object)), attribute); Assert.That(setting.IsVerbalParameter(), Is.EqualTo(expected)); }
/// <summary> /// Convenient method to check for verbal parameter types. /// </summary> /// <remarks> /// This convenient method checks if a parameter is of type verbal. /// </remarks> /// <param name="setting"> /// An instance of argument processor settings. /// </param> /// <returns> /// True, if a parameter is of type verbal and false otherwise. /// </returns> public static Boolean IsVerbalParameter(this ArgumentProcessorSetting setting) { if (setting != null) { return(setting.Attribute is VerbalParameterAttribute); } else { return(false); } }
public void Construction_TestClassConverter_CustomConverterIsEnabled() { TestClassConverter candidate = new TestClassConverter(); PropertyInfo property = candidate.GetType().GetRuntimeProperty("TestType"); ParameterObjectAttribute attribute = (ParameterObjectAttribute)property.GetCustomAttribute(typeof(OptionParameterAttribute)); ArgumentProcessorSetting actual = new ArgumentProcessorSetting(property, attribute, true); Assert.That(actual.CustomConverter, Is.Not.Null); Assert.That(actual.HasCustomConverter, Is.True); }
public void InvokeCustomConverter_ConvertMethodInvocation_ParametersAsExpected() { TestClassConverter candidate = new TestClassConverter(); PropertyInfo property = candidate.GetType().GetRuntimeProperty("TestType"); ParameterObjectAttribute attribute = (ParameterObjectAttribute)property.GetCustomAttribute(typeof(OptionParameterAttribute)); ArgumentProcessorSetting actual = new ArgumentProcessorSetting(property, attribute, true); actual.InvokeCustomConverter("parameter", "argument", "delimiter"); Assert.That(ArgumentProcessorSettingTests.parameter, Is.EqualTo("parameter")); Assert.That(ArgumentProcessorSettingTests.argument, Is.EqualTo("argument")); Assert.That(ArgumentProcessorSettingTests.delimiter, Is.EqualTo("delimiter")); }
public void InvokeCustomConverter_ConvertMethodInvocationThrows_ThrowsCustomConverterException(Type type) { Object candidate = null; if (type == typeof(TestClassInvokeConvertThrowsNotImplementedException)) { candidate = new TestClassInvokeConvertThrowsNotImplementedException(); } else if (type == typeof(TestClassInvokeConvertThrowsCustomConverterException)) { candidate = new TestClassInvokeConvertThrowsCustomConverterException(); } PropertyInfo property = candidate.GetType().GetRuntimeProperty("TestType"); ParameterObjectAttribute attribute = (ParameterObjectAttribute)property.GetCustomAttribute(typeof(OptionParameterAttribute)); ArgumentProcessorSetting actual = new ArgumentProcessorSetting(property, attribute, true); Assert.That(() => actual.InvokeCustomConverter("parameter", "argument", "delimiter"), Throws.InstanceOf <CustomConverterException>()); }
public void InvokeCustomConverter_CustomConverterIsDisabled_ThrowsCustomConverterException(Boolean?enabled) { TestClassStandard candidate = new TestClassStandard(); PropertyInfo property = candidate.GetType().GetRuntimeProperty("TestType"); ParameterObjectAttribute attribute = (ParameterObjectAttribute)property.GetCustomAttribute(typeof(OptionParameterAttribute)); ArgumentProcessorSetting actual = null; if (enabled.HasValue) { actual = new ArgumentProcessorSetting(property, attribute, enabled.Value); } else { actual = new ArgumentProcessorSetting(property, attribute); } Assert.That(() => actual.InvokeCustomConverter("parameter", "argument", "delimiter"), Throws.InstanceOf <CustomConverterException>()); }
public void Construction_TestClassOfSpecificType_CustomConverterIsDisabled(Type type) { Object candidate = null; if (type == typeof(TestClassStandard)) { candidate = new TestClassStandard(); } else if (type == typeof(TestClassNullConverter)) { candidate = new TestClassNullConverter(); } else if (type == typeof(TestClassConverterConstructorThrows)) { candidate = new TestClassConverterConstructorThrows(); } else if (type == typeof(TestClassWrongConverterWrongDataType)) { candidate = new TestClassWrongConverterWrongDataType(); } else if (type == typeof(TestClassWrongConverterNoGenericType)) { candidate = new TestClassWrongConverterNoGenericType(); } else if (type == typeof(TestClassWrongConverterWrongInterfaceType)) { candidate = new TestClassWrongConverterWrongInterfaceType(); } else if (type == typeof(TestClassWrongConverterNoGenericInterface)) { candidate = new TestClassWrongConverterNoGenericInterface(); } PropertyInfo property = candidate.GetType().GetRuntimeProperty("TestType"); ParameterObjectAttribute attribute = (ParameterObjectAttribute)property.GetCustomAttribute(typeof(OptionParameterAttribute)); ArgumentProcessorSetting actual = new ArgumentProcessorSetting(property, attribute, true); Assert.That(actual.CustomConverter, Is.Null); Assert.That(actual.HasCustomConverter, Is.False); }
/// <summary> /// Extracts the applied parameter label. /// </summary> /// <remarks> /// This method extracts the applied parameter label (solid or brief) from /// provided settings instance. /// </remarks> /// <param name="setting"> /// An instance of argument processor settings. /// </param> /// <returns> /// The label value to be used. It is either the solid label or the brief /// label. But if none of both is used then the property name is assumed /// as parameter label. /// </returns> public static String ToParameterLabel(this ArgumentProcessorSetting setting) { if (setting != null && setting.Attribute != null && setting.Property != null) { if (setting.Attribute.IsSolidLabel) { return($"{ParameterPrefixes.SolidPrefix}{setting.Attribute.SolidLabel}"); } else if (setting.Attribute.IsBriefLabel) { return($"{ParameterPrefixes.BriefPrefix}{setting.Attribute.BriefLabel}"); } else { return(setting.Property.Name); } } else { return(String.Empty); } }
public void ToParameterLabel_ArgumentProcessorSettingIsNull_ResultIsEmpty() { ArgumentProcessorSetting setting = null; Assert.That(setting.ToParameterLabel(), Is.Empty); }
public void IsVerbalParameter_ArgumentProcessorSettingIsNull_ResultIsFalse() { ArgumentProcessorSetting setting = null; Assert.That(setting.IsVerbalParameter(), Is.False); }