Skip to content

Commit d09194e

Browse files
committed
[#251][edit] change type of exception when argument error
1 parent 9954111 commit d09194e

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

src/Simplify.Web.Tests/Model/Validation/Attributes/MaxAttributeTests.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,14 @@ public void Validate_NullValue_NoExceptions()
4848
[Test]
4949
public void Validate_DifferentTypes_ExceptionThrown()
5050
{
51-
// Assign
52-
53-
var value = 15.2;
54-
var defaultMessage = "Type mismatch. The maximum value and property value should be of the same type.";
55-
5651
// Act & Assert
57-
TestAttribute(value, defaultMessage);
52+
Assert.Throws<ArgumentException>(() => TestAttributeForValidValue(15.2));
5853
}
5954

6055
[Test]
6156
public void Validate_ValueTypeNotInheritIComparable_ExceptionThrown()
6257
{
63-
// Assign
64-
65-
var value = new object();
66-
var defaultMessage = $"The type of specified property value must be inherited from {typeof(IComparable)}";
67-
6858
// Act & Assert
69-
TestAttribute(value, defaultMessage);
59+
Assert.Throws<ArgumentException>(() => TestAttributeForValidValue(new object()));
7060
}
7161
}

src/Simplify.Web.Tests/Model/Validation/Attributes/MinAttributeTests.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,14 @@ public void Validate_NullValue_NoExceptions()
4848
[Test]
4949
public void Validate_DifferentTypes_ExceptionThrown()
5050
{
51-
// Assign
52-
53-
var value = 12.5;
54-
var defaultMessage = "Type mismatch. The minimum value and property value should be of the same type.";
55-
5651
// Act & Assert
57-
TestAttribute(value, defaultMessage);
52+
Assert.Throws<ArgumentException>(() => TestAttributeForValidValue(12.5));
5853
}
5954

6055
[Test]
6156
public void Validate_ValueTypeNotInheritIComparable_ExceptionThrown()
6257
{
63-
// Assign
64-
65-
var value = new object();
66-
var defaultMessage = $"The type of specified property value must be inherited from {typeof(IComparable)}";
67-
6858
// Act & Assert
69-
TestAttribute(value, defaultMessage);
59+
Assert.Throws<ArgumentException>(() => TestAttributeForValidValue(new object()));
7060
}
7161
}

src/Simplify.Web/Model/Validation/Attributes/MaxAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
3838
return;
3939

4040
if (value is not IComparable comparableValue)
41-
throw new ModelValidationException($"The type of specified property value must be inherited from {typeof(IComparable)}");
41+
throw new ArgumentException($"The type of specified property value must be inherited from {typeof(IComparable)}");
4242

4343
ValidateTypesMatching(comparableValue);
4444

@@ -52,6 +52,6 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
5252
private void ValidateTypesMatching(IComparable comparableValue)
5353
{
5454
if (comparableValue.GetType() != MaxValue.GetType())
55-
throw new ModelValidationException("Type mismatch. The maximum value and property value should be of the same type.");
55+
throw new ArgumentException("Type mismatch. The maximum value and property value should be of the same type.");
5656
}
5757
}

src/Simplify.Web/Model/Validation/Attributes/MinAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
3838
return;
3939

4040
if (value is not IComparable comparableValue)
41-
throw new ModelValidationException($"The type of specified property value must be inherited from {typeof(IComparable)}");
41+
throw new ArgumentException($"The type of specified property value must be inherited from {typeof(IComparable)}");
4242

4343
ValidateTypesMatching(comparableValue);
4444

@@ -52,6 +52,6 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
5252
private void ValidateTypesMatching(IComparable comparableValue)
5353
{
5454
if (comparableValue.GetType() != MinValue.GetType())
55-
throw new ModelValidationException("Type mismatch. The minimum value and property value should be of the same type.");
55+
throw new ArgumentException("Type mismatch. The minimum value and property value should be of the same type.");
5656
}
5757
}

0 commit comments

Comments
 (0)