-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from interappconnectorproject/feat-17-custom-m…
…essage-validator Feature #17 custom error message in custom argument validation added
- Loading branch information
Showing
7 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/InterAppConnector.Test.Library/Commands/ValidatedValueTypeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using InterAppConnector.Attributes; | ||
using InterAppConnector.Interfaces; | ||
using InterAppConnector.Test.Library.DataModels; | ||
|
||
namespace InterAppConnector.Test.Library.Commands | ||
{ | ||
[Command("validatedvaluetype")] | ||
public class ValidatedValueTypeCommand : ICommand<ValidatedValueTypeDataModel> | ||
{ | ||
public string Main(ValidatedValueTypeDataModel arguments) | ||
{ | ||
return CommandOutput.Ok(arguments.Age); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/InterAppConnector.Test.Library/DataModels/ValidatedValueTypeDataModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using InterAppConnector.Attributes; | ||
using InterAppConnector.Test.Library.Validators; | ||
|
||
namespace InterAppConnector.Test.Library.DataModels | ||
{ | ||
public class ValidatedValueTypeDataModel | ||
{ | ||
[ValueValidator(typeof(AgeValidatorWithCustomErrorMessageValidator))] | ||
public uint Age { get; set; } | ||
|
||
[ValueValidator(typeof(BirthDateValidator))] | ||
[CustomInputString("ddMMyyyy")] | ||
public DateTime? OptionalDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../InterAppConnector.Test.Library/Validators/AgeValidatorWithCustomErrorMessageValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using InterAppConnector.Interfaces; | ||
|
||
namespace InterAppConnector.Test.Library.Validators | ||
{ | ||
public class AgeValidatorWithCustomErrorMessageValidator : IValueValidator | ||
{ | ||
public object GetSampleValidValue() | ||
{ | ||
return 25; | ||
} | ||
|
||
public bool ValidateValue(object value) | ||
{ | ||
bool validated = true; | ||
uint number = (uint)value; | ||
|
||
if (number > 100) | ||
{ | ||
throw new ArgumentException("The age must be between 0 and 100. For instance, a valid value is " + GetSampleValidValue()); | ||
} | ||
|
||
return validated; | ||
} | ||
} | ||
} |