parent
e920138edd
commit
b7cdedde8d
|
@ -3,9 +3,11 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace RulesEngine.Models
|
namespace RulesEngine.Models
|
||||||
{
|
{
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
internal class CompiledRule
|
internal class CompiledRule
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace RulesEngine.Models
|
namespace RulesEngine.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rule class
|
/// Rule class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
public class Rule
|
public class Rule
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
|
|
||||||
using RulesEngine.HelperFunctions;
|
using RulesEngine.HelperFunctions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace RulesEngine.Models
|
namespace RulesEngine.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rule result class with child result heirarchy
|
/// Rule result class with child result heirarchy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
public class RuleResultTree
|
public class RuleResultTree
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -49,6 +51,7 @@ namespace RulesEngine.Models
|
||||||
/// This method will return all the error and warning messages to caller
|
/// This method will return all the error and warning messages to caller
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>RuleResultMessage</returns>
|
/// <returns>RuleResultMessage</returns>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
public RuleResultMessage GetMessages()
|
public RuleResultMessage GetMessages()
|
||||||
{
|
{
|
||||||
RuleResultMessage ruleResultMessage = new RuleResultMessage();
|
RuleResultMessage ruleResultMessage = new RuleResultMessage();
|
||||||
|
@ -62,6 +65,7 @@ namespace RulesEngine.Models
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class will hold the error messages
|
/// This class will hold the error messages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
public class RuleResultMessage
|
public class RuleResultMessage
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace RulesEngine.Models
|
namespace RulesEngine.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Workflow rules class for deserialization the json config file
|
/// Workflow rules class for deserialization the json config file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
public class WorkflowRules
|
public class WorkflowRules
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<Version>2.0.0</Version>
|
||||||
|
<Copyright>Copyright (c) Microsoft Corporation.</Copyright>
|
||||||
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
<PackageProjectUrl>https://github.com/microsoft/RulesEngine</PackageProjectUrl>
|
||||||
|
<Authors>Dishant Munjal, Abbas Cyclewala, Yogesh Prajapati</Authors>
|
||||||
|
<Description>Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.</Description>
|
||||||
|
<PackageTags>BRE, Rules Engine, Abstraction</PackageTags>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -13,4 +20,11 @@
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.18" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.18" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\..\LICENSE">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath></PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -0,0 +1,215 @@
|
||||||
|
using RulesEngine.Extensions;
|
||||||
|
using RulesEngine.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace RulesEngine.UnitTest
|
||||||
|
{
|
||||||
|
[Trait("Category", "Unit")]
|
||||||
|
public class ListofRuleResultTreeExtensionTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void OnSuccessWithSuccessTest()
|
||||||
|
{
|
||||||
|
var rulesResultTree = new List<RuleResultTree>()
|
||||||
|
{
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = true,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var successEventName = string.Empty;
|
||||||
|
|
||||||
|
rulesResultTree.OnSuccess((eventName) =>
|
||||||
|
{
|
||||||
|
successEventName = eventName;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.True(successEventName.Equals("Test Rule 1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnSuccessWithSuccessWithEventTest()
|
||||||
|
{
|
||||||
|
var rulesResultTree = new List<RuleResultTree>()
|
||||||
|
{
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = true,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 1",
|
||||||
|
SuccessEvent = "Event 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var successEventName = string.Empty;
|
||||||
|
|
||||||
|
rulesResultTree.OnSuccess((eventName) =>
|
||||||
|
{
|
||||||
|
successEventName = eventName;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.True(successEventName.Equals("Event 1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnSuccessWithouSuccessTest()
|
||||||
|
{
|
||||||
|
var rulesResultTree = new List<RuleResultTree>()
|
||||||
|
{
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var successEventName = string.Empty;
|
||||||
|
|
||||||
|
rulesResultTree.OnSuccess((eventName) =>
|
||||||
|
{
|
||||||
|
successEventName = eventName;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.True(successEventName.Equals(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnFailWithSuccessTest()
|
||||||
|
{
|
||||||
|
var rulesResultTree = new List<RuleResultTree>()
|
||||||
|
{
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = true,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var successEventName = true;
|
||||||
|
|
||||||
|
rulesResultTree.OnFail(() =>
|
||||||
|
{
|
||||||
|
successEventName = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.True(successEventName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnFailWithoutSuccessTest()
|
||||||
|
{
|
||||||
|
var rulesResultTree = new List<RuleResultTree>()
|
||||||
|
{
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new RuleResultTree()
|
||||||
|
{
|
||||||
|
ChildResults = null,
|
||||||
|
ExceptionMessage = string.Empty,
|
||||||
|
Input = new object(),
|
||||||
|
IsSuccess = false,
|
||||||
|
Rule = new Rule()
|
||||||
|
{
|
||||||
|
RuleName = "Test Rule 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var successEventName = true;
|
||||||
|
|
||||||
|
rulesResultTree.OnFail(() =>
|
||||||
|
{
|
||||||
|
successEventName = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.False(successEventName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) Microsoft Corporation.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
|
||||||
using System;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace RulesEngine.UnitTest
|
|
||||||
{
|
|
||||||
[Trait("Category","Unit")]
|
|
||||||
public class NullLoggerTest
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void NullLogger_BeginScope_DoesNotThrow()
|
|
||||||
{
|
|
||||||
var logger = new NullLogger<RulesEngine>();
|
|
||||||
|
|
||||||
using (logger.BeginScope("test-value"))
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(LogLevel.Critical)]
|
|
||||||
[InlineData(LogLevel.Debug)]
|
|
||||||
[InlineData(LogLevel.Error)]
|
|
||||||
[InlineData(LogLevel.Information)]
|
|
||||||
[InlineData(LogLevel.None)]
|
|
||||||
[InlineData(LogLevel.Trace)]
|
|
||||||
[InlineData(LogLevel.Warning)]
|
|
||||||
public void NullLogger_IsEnabled_ReturnsTrue(LogLevel logLevel)
|
|
||||||
{
|
|
||||||
var logger = new NullLogger<RulesEngine>();
|
|
||||||
logger.IsEnabled(logLevel).Equals(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void NullLogger_Log_DoesNotThrow()
|
|
||||||
{
|
|
||||||
var logger = new NullLogger<RulesEngine>();
|
|
||||||
logger.Log(LogLevel.Critical, 1, "This is a critical message.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue