-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
Hi,
Thanks for such a great framework for unit testing Sitecore. However i am in a bit of a bind as i am writing unit tests for a legacy framework wherein there are several calls to the Sitecore Database with item path and Language overloads. But as i checked in FakeDb's source code there is no receiver for a call of above mentioned type in FakeDb.
Below is a rudimentary sample of code under test:
public Item ReturnItemFromPathandLanguage(string path, string language)
{
// This is just a representation of the code constraint i cannot remove this line
Language lan = Language.Parse(language);
var db = Sitecore.Context.Database;
return db.GetItem(path, lan);
}
The above code works really well in the original Website code and has several calls in other classes as well.
Below is my Unit Test:
[Fact]
public void ReturnItemFromPathandLanguageUT()
{
// create a fake site context
var fakeSite = new Sitecore.FakeDb.Sites.FakeSiteContext(
new Sitecore.Collections.StringDictionary
{
{ "name", "website" }, { "database", "web" }
});
// switch the context site
using (new Sitecore.Sites.SiteContextSwitcher(fakeSite))
{
using (var db = new Db
{
new DbItem("Home") { { "Title", "Welcome!" }, { "en", "Welcome" }}
})
{
var home = db.GetItem("/sitecore/content/home");
SomeClass obj = new SomeClass();
var actual = obj.ReturnItemFromPathandLanguageUT("home.Paths.FullPath","en");
// var expected = home;
// Assert
//Assert.Equal(actual, expected);
}
}
}
My code always returns null in the ReturnItemFromPathandLanguage method where the call is made to Sitecore Database with string and Language overloads. Can you look into this?
Regards,
Nitin
Metadata
Metadata
Assignees
Labels
No labels