public static void GetDataTypeName_and_IsValid_on_non_null_custom_DataTypeAttribute_is_successful() { var attribute = new DataTypeAttribute("TestCustomDataType"); Assert.Equal("TestCustomDataType", attribute.GetDataTypeName()); AssertEx.DoesNotThrow(() => attribute.Validate(new object(), s_testValidationContext)); }
public static void Validate_DoesNotThrow(DataType dataType) { if (dataType != DataType.Custom) { DataTypeAttribute attribute = new DataTypeAttribute(dataType); attribute.Validate(new object(), s_testValidationContext); } }
public static void GetDataTypeName_and_IsValid_on_empty_custom_DataTypeAttribute_throws_exception() { var attribute = new DataTypeAttribute(string.Empty); Assert.Equal(DataType.Custom, attribute.DataType); // Only throw when call GetDataTypeName() or Validate() AssertEx.Empty(attribute.CustomDataType); // Only throw when call GetDataTypeName() or Validate() Assert.Throws<InvalidOperationException>(() => attribute.GetDataTypeName()); Assert.Throws<InvalidOperationException>(() => attribute.Validate(new object(), s_testValidationContext)); }
public static void Ctor_String(string customDataType) { DataTypeAttribute attribute = new DataTypeAttribute(customDataType); Assert.Equal(DataType.Custom, attribute.DataType); Assert.Equal(customDataType, attribute.CustomDataType); if (string.IsNullOrEmpty(customDataType)) { Assert.Throws <InvalidOperationException>(() => attribute.GetDataTypeName()); Assert.Throws <InvalidOperationException>(() => attribute.Validate(new object(), s_testValidationContext)); } else { Assert.Equal(customDataType, attribute.GetDataTypeName()); attribute.Validate(new object(), s_testValidationContext); } }
public static void GetDataTypeName_and_IsValid_on_empty_custom_DataTypeAttribute_throws_exception() { var attribute = new DataTypeAttribute(string.Empty); Assert.Equal(DataType.Custom, attribute.DataType); // Only throw when call GetDataTypeName() or Validate() AssertEx.Empty(attribute.CustomDataType); // Only throw when call GetDataTypeName() or Validate() Assert.Throws <InvalidOperationException>(() => attribute.GetDataTypeName()); Assert.Throws <InvalidOperationException>(() => attribute.Validate(new object(), s_testValidationContext)); }
public static void GetDataTypeName_and_Validate_successful_for_all_non_custom_DataTypes() { foreach (var enumValue in Enum.GetValues(typeof(DataType))) { var dataType = (DataType)enumValue; if (DataType.Custom != dataType) { var attribute = new DataTypeAttribute(dataType); Assert.Equal(Enum.GetName(typeof(DataType), enumValue), attribute.GetDataTypeName()); AssertEx.DoesNotThrow(() => attribute.Validate(new object(), s_testValidationContext)); } } }
public static void Ctor_String(string customDataType) { DataTypeAttribute attribute = new DataTypeAttribute(customDataType); Assert.Equal(DataType.Custom, attribute.DataType); Assert.Equal(customDataType, attribute.CustomDataType); if (string.IsNullOrEmpty(customDataType)) { Assert.Throws<InvalidOperationException>(() => attribute.GetDataTypeName()); Assert.Throws<InvalidOperationException>(() => attribute.Validate(new object(), s_testValidationContext)); } else { Assert.Equal(customDataType, attribute.GetDataTypeName()); attribute.Validate(new object(), s_testValidationContext); } }