Click here to Skip to main content
15,898,947 members

Comments by Scyldshefing (Top 4 by date)

Scyldshefing 31-Dec-16 6:47am View    
Deleted
(Please ignore this comment - I have tried deleting it - It would appear that the posting of xml samples into this site corrupts or looses the terminating element- sorry)
The sample XML you have provided is not a valid XML (which may be the root cause of your problem). Every node in an xml must have an opening and closing elemeny e.g. <corporatename>Prima S. A. should be <corporatename>Prima S. A..</corporatename> Even nodes that contain other nodes e.g. the legalentity in your example sholud have a closing element. (there is a speical case for empty nodes which can be either <postcode> or <postcode> )

e.g. your sample
<legalentity> <corporatename>Prima S. A. <addressinspain>
Street San Vicente, 1
<postcode>41008 <town>Seville <province>Seville <countrycode>ESP

should look more like (I am guesing)
<legalentity>
<corporatename>Prima S. A.
<addressinspain>Street San Vicente, 1
<postcode>41008
<town>Seville
<province>Seville
<countrycode>ESP


Once you have the correct XML format of your target (sample) then you can verify if your code is working or not.
Scyldshefing 30-Dec-16 9:02am View    
I have posted the code to the GitHub @ https://github.com/Scyldshefing/RulesEngineII
Scyldshefing 30-Dec-16 8:21am View    
I cannot use void as a return type in the Lambda expression (certainly not the way I tried it).

if (expressionToCompile != null)
{
ruleDefinition.CompiledExpression =
Expression.Lambda<Func<T, void>>(expressionToCompile, parameter).Compile();
}

gets the following error message:

Keyword 'void' cannot be used in this context

If I replace the int with object and remove the Expression.Constant line I get the following exception in my unit test:

Test Name: TestIfThenElseCondition
Test FullName: UnitTestProject1.GivenIfThenElse.TestIfThenElseCondition
Test Source: c:\VSSolution\RulesEngine\UnitTestProject1\GivenIfThenElse.cs : line 17
Test Outcome: Failed
Test Duration: 0:00:00.0014237

Result Message:
Test method UnitTestProject1.GivenIfThenElse.TestIfThenElseCondition threw exception:
System.ArgumentException: Expression of type 'System.Void' cannot be used for return type 'System.Object'
Result StackTrace:
at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection`1 parameters)
at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable`1 parameters)
at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters)
at RulesEngine.RulesHelper.CompileRuleDefinition[T](RuleDefinition`1 ruleDefinition) in c:\VSSolution\RulesEngine\RulesEngine\RulesHelper.cs:line 111
at RulesEngine.RulesHelper.CompileRuleSet[T](RuleSet`1 ruleSet) in c:\VSSolution\RulesEngine\RulesEngine\RulesHelper.cs:line 71
at UnitTestProject1.GivenIfThenElse.TestIfThenElseCondition() in c:\VSSolution\RulesEngine\UnitTestProject1\GivenIfThenElse.cs:line 34
Scyldshefing 3-Nov-16 3:23am View    
Given that Employee implements IEmployee and both these classes are defined, how are you injecting the mock object (objMock.Object) into the code that is being tested. Your snippet does not show the declaration of the Employee object in the code under test.
To do this sort of thing (Dependency Injection) I use the Microsoft Unityframework (https://msdn.microsoft.com/en-us/library/ff647202.aspx )