-
Notifications
You must be signed in to change notification settings - Fork 36
Branches
Chris Nielsen edited this page Apr 28, 2016
·
2 revisions
The following code creates an item and specifies the branch id. It does not create a real branch.
public void HowToSetBranchId()
{
var branchId = Sitecore.Data.ID.NewID;
using (var db = new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem("home") { BranchId = branchId }
})
{
Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home");
// assert
Xunit.Assert.Equal(branchId, item.BranchId);
}
}
The following code creates a fake branch, then creates a an item based on the fake branch.
public void HowToCreateBranch()
{
var branchId = Sitecore.Data.ID.NewID;
var parentId = Sitecore.Data.ID.NewID;
using (var db = new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem(
"Branch Template",
branchId,
Sitecore.TemplateIDs.BranchTemplate),
new Sitecore.FakeDb.DbItem("Parent", parentId)
})
{
var parent = db.GetItem(parentId);
var child = parent.Add("Child Based on Branch", new Sitecore.Data.BranchId(branchId));
// assert
Xunit.Assert.Equal(branchId, child.BranchId);
}
}