1- using RelogicLabs . JsonSchema . Exceptions ;
2- using RelogicLabs . JsonSchema . Functions ;
3- using RelogicLabs . JsonSchema . Message ;
4- using RelogicLabs . JsonSchema . Tree ;
5- using RelogicLabs . JsonSchema . Types ;
6- using RelogicLabs . JsonSchema . Utilities ;
1+ using RelogicLabs . JSchema . Exceptions ;
2+ using RelogicLabs . JSchema . Functions ;
3+ using RelogicLabs . JSchema . Message ;
4+ using RelogicLabs . JSchema . Tree ;
5+ using RelogicLabs . JSchema . Nodes ;
6+ using RelogicLabs . JSchema . Utilities ;
77
88// Functions for positive (valid) test cases
9- namespace RelogicLabs . JsonSchema . Tests . External ;
9+ namespace RelogicLabs . JSchema . Tests . External ;
1010
11- public class ExternalFunctions : FunctionBase
11+ public class ExternalFunctions : FunctionProvider
1212{
1313 public const string EVENFUNC01 = "EVENFUNC01" ;
1414 public const string ERRACCESS01 = "ERRACCESS01" ;
@@ -22,9 +22,9 @@ public ExternalFunctions(RuntimeContext runtime) : base(runtime) { }
2222 public bool Even ( JNumber target )
2323 {
2424 bool result = target % 2 == 0 ;
25- if ( ! result ) return FailWith ( new JsonSchemaException (
25+ if ( ! result ) return Fail ( new JsonSchemaException (
2626 new ErrorDetail ( EVENFUNC01 , "Number is not even" ) ,
27- new ExpectedDetail ( Function , "even number" ) ,
27+ new ExpectedDetail ( Caller , "even number" ) ,
2828 new ActualDetail ( target , $ "number { target } is odd") ) ) ;
2929 return true ;
3030 }
@@ -41,9 +41,9 @@ public bool CanTest(JNumber target, JString str1, JBoolean bool1, params JNumber
4141 public bool CheckAccess ( JInteger target , JReceiver userRole )
4242 {
4343 string role = userRole . GetValueNode < JString > ( ) ;
44- if ( role == "user" && target > 5 ) return FailWith ( new JsonSchemaException (
44+ if ( role == "user" && target > 5 ) return Fail ( new JsonSchemaException (
4545 new ErrorDetail ( ERRACCESS01 , "Data access incompatible with 'user' role" ) ,
46- new ExpectedDetail ( Function , "an access at most 5 for 'user' role" ) ,
46+ new ExpectedDetail ( Caller , "an access at most 5 for 'user' role" ) ,
4747 new ActualDetail ( target , $ "found access { target } which is greater than 5") ) ) ;
4848 return true ;
4949 }
@@ -53,9 +53,9 @@ public bool Condition(JInteger target, JReceiver receiver)
5353 var threshold = receiver . GetValueNode < JInteger > ( ) ;
5454 Console . WriteLine ( "Received threshold: " + threshold ) ;
5555 bool result = threshold < target ;
56- if ( ! result ) return FailWith ( new JsonSchemaException (
56+ if ( ! result ) return Fail ( new JsonSchemaException (
5757 new ErrorDetail ( CONDFUNC01 , "Number does not satisfy the condition" ) ,
58- new ExpectedDetail ( Function , $ "a number > { threshold } of '{ receiver . Name } '") ,
58+ new ExpectedDetail ( Caller , $ "a number > { threshold } of '{ receiver . Name } '") ,
5959 new ActualDetail ( target , $ "found number { target } <= { threshold } ") ) ) ;
6060 return result ;
6161 }
@@ -67,17 +67,17 @@ public bool ConditionAll(JInteger target, JReceiver receiver)
6767 Console . WriteLine ( "Target: " + target ) ;
6868 Console . WriteLine ( "Received integers: " + values ) ;
6969 bool result = list . All ( i => i < target ) ;
70- if ( ! result ) return FailWith ( new JsonSchemaException (
70+ if ( ! result ) return Fail ( new JsonSchemaException (
7171 new ErrorDetail ( CONDFUNC02 , "Number does not satisfy the condition" ) ,
72- new ExpectedDetail ( Function , $ "a number > any of { values } of '{ receiver . Name } '") ,
72+ new ExpectedDetail ( Caller , $ "a number > any of { values } of '{ receiver . Name } '") ,
7373 new ActualDetail ( target , $ "found number { target } <= some of { values } ") ) ) ;
7474 return true ;
7575 }
7676
77- public FutureValidator SumEqual ( JInteger target , JReceiver receiver )
77+ public FutureFunction SumEqual ( JInteger target , JReceiver receiver )
7878 {
79- // Capture the current value of the function for future lambda
80- var caller = Function ;
79+ // Capture the current value of the caller
80+ var current = Caller ;
8181 return ( ) =>
8282 {
8383 var values = receiver . GetValueNodes < JInteger > ( ) ;
@@ -86,18 +86,18 @@ public FutureValidator SumEqual(JInteger target, JReceiver receiver)
8686 Console . WriteLine ( "Received values: " + expression ) ;
8787 int result = values . Sum ( i => ( int ) i ) ;
8888 if ( result != target )
89- return FailWith ( new JsonSchemaException (
89+ return Fail ( new JsonSchemaException (
9090 new ErrorDetail ( SUMEQUAL01 , $ "Number != sum of { expression } = { result } ") ,
91- new ExpectedDetail ( caller , $ "a number = sum of numbers { result } ") ,
91+ new ExpectedDetail ( current , $ "a number = sum of numbers { result } ") ,
9292 new ActualDetail ( target , $ "found number { target } != { result } ") ) ) ;
9393 return true ;
9494 } ;
9595 }
9696
97- public FutureValidator Minmax ( JInteger target , JReceiver min , JReceiver max )
97+ public FutureFunction Minmax ( JInteger target , JReceiver min , JReceiver max )
9898 {
99- // Capture the current value of the function for future lambda
100- var caller = Function ;
99+ // Capture the current value of the caller
100+ var current = Caller ;
101101 return ( ) =>
102102 {
103103 var intMin = min . GetValueNode < JInteger > ( ) ;
@@ -106,9 +106,9 @@ public FutureValidator Minmax(JInteger target, JReceiver min, JReceiver max)
106106 Console . WriteLine ( $ "Received min: { intMin } , max: { intMax } ") ;
107107 bool result = target >= intMin && target <= intMax ;
108108 if ( ! result )
109- return FailWith ( new JsonSchemaException (
109+ return Fail ( new JsonSchemaException (
110110 new ErrorDetail ( MINMAX01 , "Number is outside of range" ) ,
111- new ExpectedDetail ( caller , $ "a number in range [{ intMin } , { intMax } ]") ,
111+ new ExpectedDetail ( current , $ "a number in range [{ intMin } , { intMax } ]") ,
112112 new ActualDetail ( target , $ "found number { target } not in range") ) ) ;
113113 return true ;
114114 } ;
0 commit comments