public void Ctor_Void_Success() { EnumTypeConstraint c = new EnumTypeConstraint(); Assert.AreEqual(Constraint.TypeConstraintName, c.Name); Assert.AreEqual(string.Empty, c.TypeName); Assert.IsNull(c.ResolvedType); }
public void Ctor_StringUnknownType_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName.Replace("UriKind", "MyClass"); EnumTypeConstraint c = new EnumTypeConstraint(type); Assert.AreEqual(Constraint.TypeConstraintName, c.Name); Assert.AreEqual(type, c.TypeName); Assert.IsNull(c.ResolvedType); }
public void Ctor_String_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); Assert.AreEqual(Constraint.TypeConstraintName, c.Name); Assert.AreEqual(type, c.TypeName); Assert.IsNotNull(c.ResolvedType); Assert.IsFalse(c.HasFlags); Assert.AreEqual(3, c.EnumValues.Count); Assert.IsNotNull(c.ResolvedType); // To trigger retrieval of already resolved type }
public void Ctor_SerializationInfo_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); System.IO.MemoryStream Buffer = SerializationHelper.Serialize(c); EnumTypeConstraint c2 = SerializationHelper.Deserialize<EnumTypeConstraint>(Buffer); Assert.AreEqual(Constraint.TypeConstraintName, c2.Name); Assert.AreEqual(type, c2.TypeName); Assert.IsNotNull(c2.ResolvedType); }
public void Ctor_StringNull_Error() { CustomAssert.ThrowsException<CodedArgumentNullOrWhiteSpaceException>(() => { EnumTypeConstraint c = new EnumTypeConstraint(null); }); }
public void Validate_InvValueType_Success() { string type = typeof(System.Text.RegularExpressions.RegexOptions).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate("narf", ParameterDataType.Enum, Constants.MemberName); Assert.IsNotNull(result); Assert.IsTrue(result.GetEnumerator().MoveNext()); }
public void Validate_WrongEnum_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate(System.StringComparison.CurrentCulture, ParameterDataType.Enum, Constants.MemberName); Assert.IsNotNull(result); Assert.IsTrue(result.GetEnumerator().MoveNext()); }
public void SetParameters_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(); c.SetParametersInternal(new string[] { type }, ParameterDataType.Enum); Assert.AreEqual(type, c.TypeName); Assert.IsNotNull(c.ResolvedType); }
public void Validate_ValueNull_Error() { CustomAssert.ThrowsException<CodedArgumentNullException>(() => { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate(null, ParameterDataType.Enum, Constants.MemberName); }); }
public void Validate_NotEnum_Success() { string type = typeof(System.Uri).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate(System.UriKind.Absolute, ParameterDataType.Enum, Constants.MemberName); Assert.IsNotNull(result); Assert.IsFalse(result.GetEnumerator().MoveNext()); }
public void Validate_InvEnum_Success() { string type = typeof(System.DayOfWeek).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate((System.DayOfWeek)0x80, ParameterDataType.Enum, Constants.MemberName); Assert.IsNotNull(result); Assert.IsTrue(result.GetEnumerator().MoveNext()); }
public void SetParameters_ParamWhitespace_Error() { CustomAssert.ThrowsException<ConstraintConfigurationException>(() => { EnumTypeConstraint c = new EnumTypeConstraint(); c.SetParametersInternal(new string[] { " " }, ParameterDataType.Enum); }); }
public void SetParameters_ParamsNullOrNoDataType_Error() { CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() => { EnumTypeConstraint c = new EnumTypeConstraint(); c.SetParametersInternal(new string[0], ParameterDataType.None); }); CustomAssert.ThrowsException<CodedArgumentNullException>(() => { EnumTypeConstraint c = new EnumTypeConstraint(); c.SetParametersInternal(null, ParameterDataType.Enum); }); }
public void ToDataType_Enumeration_Success() { string value = "5"; EnumTypeConstraint c = new EnumTypeConstraint(typeof(DayOfWeek).AssemblyQualifiedName); object result = ParameterConvert.ToDataType(value, ParameterDataType.Enum, new Constraint[] { c }); Assert.AreEqual(DayOfWeek.Friday, result); }
public void Validate_ValueFlagsInt_Success() { string type = typeof(System.Text.RegularExpressions.RegexOptions).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); IEnumerable<ParameterValidationResult> result = c.Validate(System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase, ParameterDataType.Enum, Constants.MemberName); Assert.IsNotNull(result); Assert.IsFalse(result.GetEnumerator().MoveNext()); }
public void ToDataType_EnumerationInvType_Error() { EnumTypeConstraint c = new EnumTypeConstraint("Hi.I.Am.Not, A.Real.Type"); string value = "5"; CustomAssert.ThrowsException<ParameterConversionException>(() => { object result = ParameterConvert.ToDataType(value, ParameterDataType.Enum, new Constraint[] { c }); }); CustomAssert.ThrowsException<ParameterConversionException>(() => { object result = ParameterConvert.ToDataType(value, ParameterDataType.Enum, new Constraint[0]); }); }
public void ToString_Success() { string type = typeof(System.UriKind).AssemblyQualifiedName; EnumTypeConstraint c = new EnumTypeConstraint(type); Assert.AreEqual(string.Format("[Type('{0}')]", type), c.ToString()); }