FakeDb Serialization

sergeyshushlyapin edited this page May 28, 2015 · 2 revisions

This is the extension for the FakeDb framework that allows to deserialize data in tests. Suggested and implemented by Robin Hermanussen, See more at Unit testing with Sitecore.FakeDb and deserialized data.

In order to install the FakeDb.Serialization package run the following command in the NuGet Package Manager Console:

PM> Install-Package Sitecore.FakeDb.Serialization

How to deserialize an item

[Fact]
public void HowToDeserializeItem()
{
  using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
    {
      new Sitecore.FakeDb.Serialization.DsDbTemplate(
        "/sitecore/templates/Sample/Sample Item"),
      new Sitecore.FakeDb.Serialization.DsDbItem(
        "/sitecore/content/home", true)
    })
  {
    var home = db.GetItem("/sitecore/content/home");
    Assert.Equal("Sitecore", home["Title"]);
  }
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.