Skip to content

Commit

Permalink
Added a new unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed Aug 28, 2015
1 parent f169fde commit 05adf7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public void Validate()

if (_validationErrors.Any())
{
throw new AbpValidationException("Method arguments are not valid! See ValidationErrors for details.") { ValidationErrors = _validationErrors };
throw new AbpValidationException(
"Method arguments are not valid! See ValidationErrors for details.",
_validationErrors
);
}

foreach (var parameterValue in _parameterValues)
Expand Down Expand Up @@ -145,6 +148,7 @@ private void SetValidationAttributeErrors(object validatingObject)
DisplayName = property.Name,
MemberName = property.Name
};

foreach (var attribute in validationAttributes)
{
var result = attribute.GetValidationResult(property.GetValue(validatingObject), validationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,22 @@ public void Should_Not_Work_With_Wrong_Array_Input_1()
}));
}

[Fact]
public void Should_Not_Work_If_Array_Is_Null()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod4(new MyMethod4Input()) //ArrayItems is null!
);
}

#region Nested Classes

public interface IMyAppService
{
MyMethodOutput MyMethod(MyMethodInput input);
MyMethodOutput MyMethod2(MyMethod2Input input);
MyMethodOutput MyMethod3(MyMethod3Input input);
MyMethodOutput MyMethod4(MyMethod4Input input);
}

public class MyAppService : IMyAppService, IApplicationService
Expand All @@ -120,6 +129,11 @@ public MyMethodOutput MyMethod3(MyMethod3Input input)
{
return new MyMethodOutput { Result = 42 };
}

public MyMethodOutput MyMethod4(MyMethod4Input input)
{
return new MyMethodOutput { Result = 42 };
}
}

public class MyMethodInput : IInputDto
Expand Down Expand Up @@ -150,6 +164,12 @@ public class MyMethod3Input : IInputDto
public MyClassInList[] ArrayItems { get; set; }
}

public class MyMethod4Input : IInputDto
{
[Required]
public MyClassInList[] ArrayItems { get; set; }
}

public class MyClassInList : IValidate
{
[Required]
Expand Down

0 comments on commit 05adf7e

Please sign in to comment.