sshushliapin/Sitecore.FakeDb

Unable to add an item to the Media Library

Closed this issue · 1 comments

From SO. The following test fails:

using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
  ID mediaItemId = ID.NewID;
  var mediaFakeItem = new Sitecore.FakeDb.DbItem("my-image", mediaItemId);
  mediaFakeItem.FullPath = "/sitecore/media library/my-image";
  db.Add(mediaFakeItem);
  Sitecore.Data.Items.Item mediaItem = db.GetItem(mediaItemId);

  // Expected: /sitecore/media library/my-image
  // Actual:   /sitecore/content/my-image
  Assert.Equal("/sitecore/media library/my-image", mediaFakeItem.FullPath);
}

The problem is in the mutable ParentID and FullPath fields. Changing only one of them makes them unsynchronized which leads to unpredictable results.

Fixed in v2.0.0-beta2. Now the FullPath setting is closed so that it's not possible to use it in the wrong way.

In order to create an item in Media Library the ParentID property should be utilized:

var mediaFakeItem = new DbItem("my-image")
   {
     ParentID = Sitecore.ItemIDs.MediaLibraryRoot
   };