Comments (2)
If the item has a template defined FakeDb will create fields on the Sitecore item using its template definition. Here's a slightly modified version of your code and it passes assertions:
[Fact]
public void ShouldCreateChildItemsWithFields_Alternative()
{
ID directoryTemplateId = ID.NewID;
using (var db = new Db
{
new DbTemplate("Media folder", directoryTemplateId) { {"test1"}, {"test2"} },
new DbItem("DownloadDir", ID.NewID, directoryTemplateId)
{
new DbItem("SubdirOne", ID.NewID, directoryTemplateId)
}
})
{
Item downloadDir = db.GetItem("/sitecore/content/DownloadDir");
downloadDir.Children.Should().HaveCount(1);
downloadDir.Fields.Should().HaveCount(2);
}
}
If you don't give your item a template then the fields it carries will be pushed into the Sitecore item because FakeDb will generate a template for the item based on its fields. Here's another version:
[Fact]
public void ShouldCreateChildItemsWithFields_AlternativeTwo()
{
using (var db = new Db
{
new DbItem("DownloadDir")
{
new DbItem("SubdirOne"),
new DbField("test1"),
new DbField("test2")
}
})
{
Item downloadDir = db.GetItem("/sitecore/content/DownloadDir");
downloadDir.Children.Should().HaveCount(1);
downloadDir.Fields.Should().HaveCount(2);
}
}
Note: prefer collection initializers to direct property setters. The code looks cleaner and FakeDb strives to provide a nice DSL for FakeDb initialization
from sitecore.fakedb.
Thanks for the quick response. It all sounds pretty obvious now!
from sitecore.fakedb.
Related Issues (20)
- Could not find configuration node: databases/database[@id='master'] HOT 3
- Content search config in SC9 uses incorrect class name HOT 5
- Support for Template Sections HOT 2
- Does FakeDb distinguish between item's Name and DisplayName? HOT 7
- Update Sitecore.FakeDb.AutoFixture Nuget reference to AutoFixture HOT 1
- Unable to set to the ValidFrom of the latest version HOT 2
- Issue with Sitecore 9 HOT 4
- Sitecore 9.1 HOT 1
- Sitecore 9 TrackingField HOT 3
- Unable to switch page DisplayMode
- Could not load file or assembly 'Sitecore.Kernel, Version=8.1.0.0... HOT 2
- Proposal: Updates to support Sitecore 9.x HOT 5
- Standard field contains old values HOT 3
- Blobs for 9.3
- Upgrade to Sitecore 9.3 HOT 1
- FakeDb does not have GetItem(string path, Language lang) overload HOT 4
- Issue with Autofixture.AutoDbCustomization and NUnit3 HOT 5
- Method 'GetReferrers' in type 'Sitecore.FakeDb.Links.FakeLinkDatabase' does not have an implementation HOT 2
- Adding an item from branch template doesn't work
- System.InvalidOperationException : Stack is null or empty.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitecore.fakedb.