This project is read-only.

Testing complex business rules which act upon a collection of Blog Posts

Topics: Writing modules
Jan 10, 2012 at 11:05 AM

I am creating a module which performs business rules on various parts of a BlogPost, so that a specific BlogPost is selected from a collection of BlogPosts. The collection of BlogPosts is returned from the ContentManager.

The problem comes when trying to write unit tests for these business rules.

At the moment I am trying to go down a route like in Orchard.Tests.ContentManagement.ContentQueryTests. But adding my sample data is proving to be difficult, as when I perform

var allitems = _manager.Query().List();

The items are returned with no parts, when they were added with 2 parts. Here is the code I used to add the items:

        private dynamic ConstructLeadPromoteContentItem(bool lead, bool promote, DateTime published) {

            var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("testing").Build())

            builder.As<CommonPart>().Record = new CommonPartRecord();
            builder.As<LeadPromotePart>().Record = new LeadPromotePartRecord();

            builder.As<CommonPart>().PublishedUtc = published;
            builder.As<LeadPromotePart>().NewsAndBlogsLead = lead;
            builder.As<LeadPromotePart>().NewsAndBlogsPromote = promote;

            return builder;

        private void AddSampleData() {
            var contentItem = ConstructLeadPromoteContentItem(true, false, new DateTime(2012, 1, 1));
            var ci = _manager.Create<ContentItem>("testing", item => item = contentItem);


So I would like to know,

  • Is this approach to testing the right approach to take?
  • If not, can anyone suggest a better approach?