-
-
Save bentayloruk/d2cf5dc9138d7a489e3f to your computer and use it in GitHub Desktop.
Enticify Admin Trigger Examples
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
using Enticify.Promotions.Admin; | |
using Enticify.Promotions.Admin.PropertyReferences; | |
using Xunit; | |
namespace Enticify.Tests.Promotions.Admin | |
{ | |
public class TriggerExamples | |
{ | |
private readonly PromotionDefinition _pd = new PromotionDefinition(); | |
[Fact] | |
public void XAmountInBasket() | |
{ | |
//Spend $100 on anything. | |
_pd.ConditionExpression = new LineUnitSelection | |
{ | |
SelectionQuantity = new[] {new SubtotalRangeQuantity(100, 100, "USD")}, | |
LineUnitExpression = new AlwaysTrueExpression() | |
}; | |
} | |
[Fact] | |
public void SpecificProductInBasket() | |
{ | |
//Buy 1 of Product 1234 (from catalog Beads). | |
_pd.ConditionExpression = new LineUnitSelection | |
{ | |
SelectionQuantity = new[] {new QuantityRange(1, 1, "*")}, | |
LineUnitExpression = new ExpressionCombination(CombinationResult.AllTrue) | |
{ | |
new Equals<string>(new LineItemPropertyReference("ProductID"), "1234"), | |
new Equals<string>(new LineItemPropertyReference("CatalogName"), "Beads"), | |
} | |
}; | |
} | |
[Fact] | |
public void DealerLevel() | |
{ | |
//"GOLD" or "SILVER" dealers get it. | |
_pd.PrerequisiteExpresssion = new ExpressionCombination(CombinationResult.AnyTrue) | |
{ | |
new Equals<string>(new ContextObjectPropertyReference("UserObject", "DealerInfo.Level"), "SILVER"), | |
new Equals<string>(new ContextObjectPropertyReference("UserObject", "DealerInfo.Level"), "GOLD"), | |
}; | |
} | |
[Fact] | |
public void ComplexExpressionExample() | |
{ | |
//This example demonstrates ExpressionCombination nesting. | |
_pd.PrerequisiteExpresssion = new ExpressionCombination(CombinationResult.AllTrue) | |
{ | |
//Silver OR Gold dealer | |
new ExpressionCombination(CombinationResult.AnyTrue) | |
{ | |
new Equals<string>(new ContextObjectPropertyReference("UserObject", "DealerInfo.Level"), "SILVER"), | |
new Equals<string>(new ContextObjectPropertyReference("UserObject", "DealerInfo.Level"), "GOLD"), | |
}, | |
//...AND, | |
new ExpressionCombination(CombinationResult.NoneTrue) | |
{ | |
new Equals<string>(new ContextObjectPropertyReference("UserObject", "Account.Level"), "BASIC"), | |
new Equals<bool>(new ContextObjectPropertyReference("CustomObjectThingy", "BoolProp"), false), | |
} | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment