Skip to content

Instantly share code, notes, and snippets.

@0liver
Created December 6, 2014 11:06
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 0liver/dbeeb597b626f9a15f36 to your computer and use it in GitHub Desktop.
Save 0liver/dbeeb597b626f9a15f36 to your computer and use it in GitHub Desktop.
ContentHelpers for Unit Testing in Orchard CMS
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.Records;
namespace Nwazet.Commerce.Tests.Helpers {
public class ContentHelpers {
public static ContentItem PreparePart<TPart, TRecord>(TPart part, string contentType, int id = -1)
where TPart : ContentPart<TRecord>
where TRecord : ContentPartRecord, new() {
part.Record = new TRecord();
return PreparePart(part, contentType, id);
}
public static ContentItem PreparePart<TPart>(TPart part, string contentType, int id = -1)
where TPart : ContentPart {
var contentItem = part.ContentItem = new ContentItem {
VersionRecord = new ContentItemVersionRecord {
ContentItemRecord = new ContentItemRecord()
},
ContentType = contentType
};
contentItem.Record.Id = id;
contentItem.Weld(part);
contentItem.Weld(new InfosetPart());
return contentItem;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment