-
Notifications
You must be signed in to change notification settings - Fork 36
Query
sergeyshushlyapin edited this page Nov 4, 2014
·
1 revision
The Query
API needs the Context.Database
set, and the example below uses
DatabaseSwitcher
to do so:
[Fact]
public void HowToWorkWithQueryApi()
{
const string Query = "/sitecore/content/*[@@key = 'home']";
using (new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem("home")
})
{
Sitecore.Data.Items.Item[] result =
Sitecore.Data.Query.Query.SelectItems(Query);
Xunit.Assert.Equal(result.Count(), 1);
Xunit.Assert.Equal(result[0].Key, "home");
}
}
[Fact]
public void HowToWorkWithFastQueryApi()
{
const string Query = "fast:/sitecore/content/*[@@key = 'home']";
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem("home")
})
{
Sitecore.Data.Items.Item homeItem = db.Database.SelectSingleItem(Query);
Xunit.Assert.Equal(homeItem.Key, "home");
}
}
Important:
Under the hood Sitecore Query is used. The Fast Query limitations are not applied to the result.