This code is base on Eric Evans and Martin Fowler's article introducing the Specification pattern
Simple example in the tests can be found here UserPreviouslyActiveIsPartOfTheRecentlyInactiveCohort.cs
ISpecification<UserContext> inactiveCohort =
new UserIsInactiveForOverTwoWeeks()
.And(new UserHasViewedSomeThing())
.And(new UserHasUploadedSomeThing())
.And(new UserHasNotReceivedAReportThisMonth());
var userContext = new UserContext
{
LastActiveDate = DateTime.UtcNow.AddDays(-15),
LastReportSent = DateTime.UtcNow.AddMonths(-1),
TotalUploads = 10,
TotalViews = 50
};
bool userInCohort = inactiveCohort.IsSatisfiedBy(userContext)