本文整理汇总了C#中Sitecore.FakeDb.Db.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# Db.GetItem方法的具体用法?C# Db.GetItem怎么用?C# Db.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sitecore.FakeDb.Db
的用法示例。
在下文中一共展示了Db.GetItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDatasources_LocationSetByRelativePath_ShouldReturnSourcesFromSettingItem
public void GetDatasources_LocationSetByRelativePath_ShouldReturnSourcesFromSettingItem([Frozen]ISiteSettingsProvider siteSettingsProvider, [Greedy]DatasourceProvider provider, string name, string contextItemName, Db db, string settingItemName, Item item, string sourceRootName)
{
var contextItemId = ID.NewID;
var contextDbItem = new DbItem(contextItemName.Replace("-", String.Empty), contextItemId);
var rootName = sourceRootName.Replace("-", string.Empty);
var sourceRoot = new DbItem(rootName);
contextDbItem.Add(sourceRoot);
db.Add(contextDbItem);
var settingId = ID.NewID;
var settingDbItem = new DbItem(settingItemName.Replace("-", String.Empty), settingId, Templates.DatasourceConfiguration.ID)
{
new DbField(Templates.DatasourceConfiguration.Fields.DatasourceLocation)
{
{
"en", $"./{rootName}"
}
}
};
var contextItem = db.GetItem(contextItemId);
db.Add(settingDbItem);
var sourceRootItem = db.GetItem(sourceRoot.ID);
var settingItem = db.GetItem(settingId);
siteSettingsProvider.GetSetting(Arg.Any<Item>(), Arg.Any<string>(), Arg.Any<string>()).Returns(settingItem);
var sources = provider.GetDatasourceLocations(contextItem, name);
sources.Should().NotBeNull();
sources.Should().Contain(sourceRootItem);
}
示例2: Update_ItemPassed_ShouldReplaceLinks
public void Update_ItemPassed_ShouldReplaceLinks([Substitute] LinkDatabase linkDb, Db db)
{
var datasourceItemId = ID.NewID;
db.Add(new DbItem("source")
{
Children =
{
new DbItem("_Local")
{
new DbItem("DatasourceItem")
}
},
Fields =
{
"testField"
}
});
;
db.Add(new DbItem("target")
{
Children =
{
new DbItem("_Local")
{
new DbItem("DatasourceItem")
}
},
Fields =
{
"testField"
}
});
;
var sourceItem = db.GetItem("/sitecore/content/source");
var targetItem = db.GetItem("/sitecore/content/target");
var datasourceItem = db.GetItem("/sitecore/content/source/_Local/DatasourceItem");
var targetDatasourceItem = db.GetItem("/sitecore/content/target/_Local/DatasourceItem");
var itemLinks = new[]
{
new ItemLink(sourceItem, FieldIDs.LayoutField, datasourceItem, string.Empty)
};
linkDb.GetReferences(sourceItem).Returns(itemLinks.ToArray());
using (new LinkDatabaseSwitcher(linkDb))
{
using (new EditContext(targetItem))
{
targetItem["__Renderings"] = datasourceItem.ID.ToString();
}
var referenceReplacer = new UpdateLocalDatasourceReferencesService(sourceItem, targetItem);
referenceReplacer.Update();
var expectedValue = targetDatasourceItem.ID.ToString();
targetItem["__Renderings"].Should().Be(expectedValue);
}
}
示例3: GetSiteDefinition_ItemInSiteHierarcy_ShouldReturnHierarchicalSiteDefinition
public void GetSiteDefinition_ItemInSiteHierarcy_ShouldReturnHierarchicalSiteDefinition(SiteContext siteContext, DbItem item , Db db, string siteName)
{
var siteDefinitionId = ID.NewID;
db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) {item});
var contextItem = db.GetItem(item.ID);
var definitionItem = db.GetItem(siteDefinitionId);
var siteDefinition = siteContext.GetSiteDefinition(contextItem);
siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
}
示例4: GetBackgroundClass_ClassFieldIsSet_ShouldReturnClassValue
public void GetBackgroundClass_ClassFieldIsSet_ShouldReturnClassValue(Db db, [Substitute] Rendering rendering, ID itemId, string itemName,[Content] DbItem renderingItem, string classValue)
{
var rItem = db.GetItem(renderingItem.ID);
db.Add(new DbItem(itemName, itemId) {new DbField(Templates.Style.Fields.Class) { {"en", classValue}} });
var backgroundClassItem = db.GetItem(itemId);
rendering.RenderingItem.Returns(rItem);
var parameters = new RenderingParameters($"{Constants.BackgroundLayoutParameters.Background}={backgroundClassItem.ID}");
rendering.Parameters.Returns(parameters);
var bgClass = rendering.GetBackgroundClass();
bgClass.Should().BeEquivalentTo(classValue);
}
示例5: GetSettingsItem_ShouldReturnSettingItem
public void GetSettingsItem_ShouldReturnSettingItem(string settingName, [Frozen]Item contextItem, [Substitute]SiteContext context, Db db, string definitionItemName)
{
var provider = new SettingsProvider(context);
var settingItemId = ID.NewID;
var definitionId = ID.NewID;
db.Add(new DbItem(definitionItemName, definitionId) {new DbItem(SettingsProvider.SettingsRootName) {new DbItem(settingName, settingItemId, Templates.SiteSettings.ID)} });
var definitionItem = db.GetItem(definitionId);
var setting = db.GetItem(settingItemId);
context.GetSiteDefinition(Arg.Any<Item>()).Returns(new SiteDefinition {Item = definitionItem });
var settingItem = provider.GetSettingItem(settingName, contextItem);
settingItem.ID.ShouldBeEquivalentTo(setting.ID);
}
示例6: GetDatasources_ShouldReturnSourcesFromSettingItem
public void GetDatasources_ShouldReturnSourcesFromSettingItem([Frozen]ISiteSettingsProvider siteSettingsProvider, [Greedy]DatasourceProvider provider, string name, Item contextItem, Db db, string settingItemName, Item item, DbItem sourceRoot)
{
var settingId = ID.NewID;
db.Add(new DbItem(settingItemName, settingId, Templates.DatasourceConfiguration.ID) {new DbField(Templates.DatasourceConfiguration.Fields.DatasourceLocation) { {"en", sourceRoot.ID.ToString()} } });
db.Add(sourceRoot);
var sourceRootItem = db.GetItem(sourceRoot.ID);
var settingItem = db.GetItem(settingId);
siteSettingsProvider.GetSetting(Arg.Any<Item>(), Arg.Any<string>(), Arg.Any<string>()).Returns(settingItem);
var sources = provider.GetDatasourceLocations(item, name);
sources.Should().NotBeNull();
sources.Should().Contain(sourceRootItem);
}
示例7: GetDatasourceTemplate_ShouldReturnTemplateFromSettingItem
public void GetDatasourceTemplate_ShouldReturnTemplateFromSettingItem([Frozen]ISettingsProvider settingsProvider, [Greedy]ItemDatasourceProvider provider, string name, Item contextItem, Db db, string settingItemName, Item item, DbItem sourceTemplate)
{
provider.Database = db.Database;
var settingId = ID.NewID;
db.Add(new DbItem(settingItemName, settingId) { new DbField(Templates.DatasourceConfiguration.Fields.DatasourceTemplate) { { "en", sourceTemplate.ID.ToString() } } });
db.Add(sourceTemplate);
var sourceRootItem = db.GetItem(sourceTemplate.ID);
var settingItem = db.GetItem(settingId);
settingsProvider.GetSettingItem(Arg.Any<string>(), Arg.Any<Item>()).Returns(settingItem);
var sources = provider.GetDatasourceTemplate(name, item);
sources.Should().NotBeNull();
sources.ID.ShouldBeEquivalentTo(sourceRootItem.ID);
}
示例8: GetDatasources_LocationSetByQuery_ShouldReturnSourcesFromSettingItem
public void GetDatasources_LocationSetByQuery_ShouldReturnSourcesFromSettingItem([Frozen]ISettingsProvider settingsProvider, [Greedy]ItemDatasourceProvider provider, string name, Item contextItem, Db db, string settingItemName, Item item, string sourceRootName)
{
var sourceRoot = new DbItem(sourceRootName.Replace("-", string.Empty));
provider.Database = db.Database;
var settingId = ID.NewID;
db.Add(sourceRoot);
var sourceRootItem = db.GetItem(sourceRoot.ID);
db.Add(new DbItem(settingItemName, settingId, Templates.DatasourceConfiguration.ID) { new DbField(Templates.DatasourceConfiguration.Fields.DatasourceLocation) { { "en", $"query:{sourceRootItem.Paths.Path}" } } });
var settingItem = db.GetItem(settingId);
settingsProvider.GetSettingItem(Arg.Any<string>(), Arg.Any<Item>()).Returns(settingItem);
var sources = provider.GetDatasources(name, item);
sources.Should().NotBeNull();
sources.Should().Contain(sourceRootItem);
}
示例9: DemoContent_RenderingContextItemInitialized_ShouldReturnDemoContentView
public void DemoContent_RenderingContextItemInitialized_ShouldReturnDemoContentView(Db db, [Greedy] DemoController sut, [Content] DemoContentItem item)
{
using (RenderingContext.EnterContext(new Rendering(), db.GetItem(item.ID)))
{
sut.DemoContent().As<ViewResult>().Model.Should().BeOfType<DemoContent>();
}
}
示例10: Execute_EnforeTemplateOnlyDoesNotInheritTemplate_AbortsPipeline
public void Execute_EnforeTemplateOnlyDoesNotInheritTemplate_AbortsPipeline()
{
//Arrange
var task = new EnforcedTemplateCheck();
using (Db database = new Db
{
new DbTemplate(new ID(TemplateInferredTypeTaskFixture.StubInferred.TemplateId)),
new Sitecore.FakeDb.DbItem("Target", ID.NewID, new ID(TemplateInferredTypeTaskFixture.StubInferred.TemplateId))
})
{
var path = "/sitecore/content/Target";
var item = database.GetItem(path);
var config = new SitecoreTypeConfiguration();
config.EnforceTemplate = SitecoreEnforceTemplate.Template;
config.TemplateId = new ID(Guid.NewGuid());
var typeContext = new SitecoreTypeCreationContext();
typeContext.Item = item;
var args = new ObjectConstructionArgs(null, typeContext, config, null, new ModelCounter());
//Act
task.Execute(args);
//Assert
Assert.IsNull(args.Result);
}
}
示例11: GetSupportedLanguages_ShouldReturlListOfSupportedLanguages
public void GetSupportedLanguages_ShouldReturlListOfSupportedLanguages(Db db, DbItem item , string rootName)
{
var contextItemId = ID.NewID;
var rootId = ID.NewID;
var template = new DbTemplate();
template.BaseIDs = new[]
{
Foundation.Multisite.Templates.Site.ID,
Templates.LanguageSettings.ID
};
var languageItem = new DbItem("en");
db.Add(languageItem);
db.Add(new DbTemplate(Foundation.Multisite.Templates.Site.ID));
db.Add(new DbTemplate(Templates.LanguageSettings.ID) {Fields = { { Templates.LanguageSettings.Fields.SupportedLanguages, languageItem.ID.ToString()} }});
db.Add(template);
var rootItem = new DbItem(rootName, rootId, template.ID){ new DbField(Templates.LanguageSettings.Fields.SupportedLanguages) { {"en", languageItem.ID.ToString()} } };
rootItem.Add(item);
db.Add(rootItem);
var contextItem = db.GetItem(item.ID);
Sitecore.Context.Item = contextItem;
var supportedLanguages = LanguageRepository.GetSupportedLanguages();
supportedLanguages.Count().Should().BeGreaterThan(0);
}
示例12: Execute_CreatesInferredType
public void Execute_CreatesInferredType()
{
//Arrange
using (Db database = new Db
{
new DbTemplate(new ID(StubInferred.TemplateId)),
new Sitecore.FakeDb.DbItem("Target", ID.NewID, new ID(StubInferred.TemplateId))
})
{
var context = Context.Create(FakeDb.Utilities.CreateStandardResolver());
var path = "/sitecore/content/Target";
context.Load(new AttributeTypeLoader(typeof(StubInferred)));
var typeContext = new SitecoreTypeCreationContext();
var args = new ConfigurationResolverArgs(context, typeContext, null, null);
var task = new TemplateInferredTypeTask();
typeContext.InferType = true;
typeContext.Item = database.GetItem(path);
typeContext.RequestedType = typeof(IBase);
args.RequestedType = typeof(IBase);
//Act
task.Execute(args);
//Assert
Assert.IsNotNull(args.Result);
Assert.AreEqual(typeof(StubInferred), args.Result.Type);
}
}
示例13: GetProfileShouldReturnFullEditProfileModel
public void GetProfileShouldReturnFullEditProfileModel(Db db, [Substitute] UserProfile userProfile, [RightKeys("FirstName", "LastName", "Phone", "Interest")] IDictionary<string, string> properties,
[Frozen] IProfileSettingsService profileSettingsService, [Frozen] IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService)
{
using (db)
{
var id = new ID();
db.Add(new DbItem("Profile", id)
{
Fields =
{
new DbField("FirstName", Templates.UserProfile.Fields.FirstName),
new DbField("LastName", Templates.UserProfile.Fields.LastName),
new DbField("Phone", Templates.UserProfile.Fields.PhoneNumber),
new DbField("Interest", Templates.UserProfile.Fields.Interest)
}
});
profileSettingsService.GetUserDefaultProfile().Returns(db.GetItem(id));
userProfileProvider.GetCustomProperties(Arg.Any<UserProfile>()).Returns(properties);
var result = userProfileService.GetProfile(userProfile);
result.FirstName.Should().Be(properties["FirstName"]);
result.LastName.Should().Be(properties["LastName"]);
result.PhoneNumber.Should().Be(properties["Phone"]);
result.Interest.Should().Be(properties["Interest"]);
}
}
示例14: GetActive_ShouldReturnLanguageModelForContextLanguage
public void GetActive_ShouldReturnLanguageModelForContextLanguage(Db db, [Content] DbItem item)
{
var contextItem = db.GetItem(item.ID);
Context.Item = contextItem;
var activeLanguage = LanguageRepository.GetActive();
activeLanguage.TwoLetterCode.Should().BeEquivalentTo(Context.Language.Name);
}
示例15: GetKeywords_ContextItem_ShouldReturnKeywordsModel
public void GetKeywords_ContextItem_ShouldReturnKeywordsModel(Db db, string contextItemName, string keyword1ItemName, string keyword2ItemName)
{
var contextItemId = ID.NewID;
var keyword1Id = ID.NewID;
var keyword2Id = ID.NewID;
db.Add(new DbItem(contextItemName, contextItemId, Templates.PageMetadata.ID)
{
new DbField(Templates.PageMetadata.Fields.Keywords)
{
{"en", $"{keyword1Id}|{keyword2Id}"}
}
});
db.Add(new DbItem(keyword1ItemName, keyword1Id, Templates.Keyword.ID)
{
new DbField(Templates.Keyword.Fields.Keyword)
{
{"en", keyword1ItemName}
}
});
db.Add(new DbItem(keyword2ItemName, keyword2Id, Templates.Keyword.ID)
{
new DbField(Templates.Keyword.Fields.Keyword)
{
{"en", keyword2ItemName}
}
});
var contextItem = db.GetItem(contextItemId);
var keywordsModel = MetadataRepository.GetKeywords(contextItem);
keywordsModel.Should().BeOfType<MetaKeywordsModel>();
keywordsModel.Keywords.Count().Should().Be(2);
}