- Define simple generic Rule object to keep all rules
- Make a processing engine which keeps a list of rules
- Engine goes through the rule for the given input
- If the engine hits a rule condition then invoke an action against it.
The implementation will just focus on the rule engine & inform that the rule has hit. What to do after the rule is hit, the business function will be just mocked.
For eg. If Product is Book, then do some action.
Rule Engine & Functions to be carried out are two seperate concerns.
Implementation under PromotionEngine folder.
Test Case Implementations :
- Tests_BRE_01 : Some basic functional cases
- Tests_BRE_02 : Functional cases provided as example
- Tests_BRE_03 : Added new promo rule
Implementation under BusinessRuleEngine folder.
Test Case Implementations :
- Tests_BRE_01 : Some basic for query helpers
- Tests_BRE_02 : Functional Test Cases
Business Rule which stores the business rules to be verified if they are satisfied
Code to identify the rule
The where condition which defines the business rule to be verified.
Engine to verify the business rules against an given input.
Name for the engine
List of all rules that are defined
M:PP.CodeTest.BusinessRuleEngine.Process(PP.CodeTest.OrderItem,System.Action{PP.CodeTest.BusinessFunctionRule,PP.CodeTest.OrderItem},System.Action)
Process the rules on the input
| Name | Description |
|---|---|
| item: | Input on which the rules are to be applied |
| Name | Description |
| ----- | ------ |
| onRuleHit: | Invoke delegate when a particular rules is satisified |
| Name | Description |
| ----- | ------ |
| onComplete: | Invoke delegate when the engine has completely processed the input |
Mode in which the product is bought
Type of product
This is just used to record the sequence of rule hits. It will enable to test if the rules are properly executed in the sequence.
Sample order item to mock the input
Interface for Business Engine
Generic interface that defines for any input
Interface for Promotion Engine
Interface for Promotion Rules
Generic interface that defines a rule for the system
Generic interface for Rule Engine
This is just a helper class to create dynamic expressions NOTE: Time was not spent on writing this code it was already part of my personal code
Sample cart item to mock the input
Mock pricing store to get pricing information
Provides price of an item.
| Name | Description |
|---|---|
| key: | SKU ID |
| Returns: |
Provides the pricing when a promo code is applied
| Name | Description |
|---|---|
| promoKey: | Promo Code |
| Returns: |
Promotion Rule which stores the business rules to be verified if they are satisfied
The list of business conditions.
The where condition by which the system can identify which items to look for
The count of items that are required for apply the business condition
Friendly code for the rule
M:PP.CodeTest.PromotionRule.#ctor(System.String,System.Collections.Generic.Dictionary{System.String,System.Int32},System.Int32)
Promotion rule which includes the conditions to verify
| Name | Description |
|---|---|
| code: | Friendly code for the rule |
| Name | Description |
| ----- | ------ |
| conditions: | Dictionary of rules which can used to define the rule for apply promo on any SKU |
| Name | Description |
| ----- | ------ |
| order: | Order in which the rule needs to be executed. |
Engine to verify the business rules against an given input.
Query conditions which are used repeatedly