Skip to content

Instantly share code, notes, and snippets.

@bentayloruk
Created May 21, 2012 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentayloruk/d2cf5dc9138d7a489e3f to your computer and use it in GitHub Desktop.
Save bentayloruk/d2cf5dc9138d7a489e3f to your computer and use it in GitHub Desktop.
Enticify Admin Trigger Examples
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