public void ParseFields_ReturnsExpectedValues(string fieldValue, string standardValue, string expected) { using (var db = new Db()) { var testFieldId = ID.NewID; var template = new DbTemplate("Test Template") { { testFieldId, standardValue } }; db.Add(template); var testItem = ItemManager.CreateItem("Test", db.GetItem(ItemIDs.ContentRoot), template.ID); if (expected != null) { using (new EditContext(testItem)) { testItem[testFieldId] = expected; } } var sut = new FieldReader(); testItem.Fields.ReadAll(); var result = sut.ParseFields(testItem, FieldReader.FieldReadType.Versioned).FirstOrDefault(f => f.FieldId == testFieldId.Guid); if (expected == null) result.Should().BeNull(); else result.Value.Should().Be(expected); } }
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); }
public void Add(DbTemplate template) { Assert.ArgumentNotNull(template, "template"); Assert.ArgumentCondition(!this.DataStorage.FakeTemplates.ContainsKey(template.ID), "template", "A template with the same id has already been added."); this.DataStorage.AddFakeTemplate(template); }
static void Main(string[] args) { var assembly = Assembly.GetExecutingAssembly(); var templateMapping = new AutoTemplateMapping(assembly); using (var db = new Db()) { var pageTemplate = new DbTemplate("Page", new Sitecore.Data.ID("{B30304AF-6B39-4AB7-832E-C858A76B9C7B}")) { "Title" }; db.Add(pageTemplate); var articlePageTemplate = new DbTemplate("ArticlePage", new Sitecore.Data.ID("{13175CCF-54D3-43B3-B2D8-EF8863916B53}")) { BaseIDs = new [] { pageTemplate.ID } }; articlePageTemplate.Add("Content"); db.Add(articlePageTemplate); var page1Item = new DbItem("Page1") { TemplateID = pageTemplate.ID }; page1Item.Add("Title", "Welcome"); db.Add(page1Item); var articlePage1Item = new DbItem("ArticlePage1") { TemplateID = articlePageTemplate.ID }; articlePage1Item.Add("Title", "Welcome to article 1"); articlePage1Item.Add("Content", "This is the content of article 1"); db.Add(articlePage1Item); var page1 = templateMapping.ResolveAs<IPageItem>(db.GetItem(page1Item.ID)).ValueOrFailure(); Console.WriteLine(page1.Title.RawValue); var article1 = templateMapping.ResolveAs<IArticlePageItem>(db.GetItem(articlePage1Item.ID)).ValueOrFailure(); Console.WriteLine(article1.Title.RawValue); Console.WriteLine(article1.Content.RawValue); Console.ReadKey(); } }
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 }; db.Add(new DbTemplate(Foundation.MultiSite.Templates.Site.ID)); db.Add(new DbTemplate(Templates.LanguageSettings.ID)); db.Add(template); db.Add(new DbItem(rootName, rootId, template.ID) {item}); var contextItem = db.GetItem(item.ID); Sitecore.Context.Item = contextItem; var supportedLanguages = LanguageRepository.GetSupportedLanguages(); }
public void HasFieldValue_FieldHasStandardValue_ShouldReturnTrue(Db db, string itemName, TemplateID templateId, ID fieldId, string value) { var template = new DbTemplate("Sample", templateId) { {fieldId, value} }; db.Add(template); //Arrange var contentRoot = db.GetItem(ItemIDs.ContentRoot); var item = contentRoot.Add("Home", new TemplateID(template.ID)); //Act item.FieldHasValue(fieldId).Should().BeTrue(); }
public void Add(DbTemplate template) { Assert.ArgumentNotNull(template, "template"); if (ID.IsNullOrEmpty(template.ID)) { template.ID = ID.NewID; } else { Assert.ArgumentCondition(!this.DataStorage.FakeTemplates.ContainsKey(template.ID), "template", "A tamplete with the same id has already been added."); } this.DataStorage.FakeTemplates.Add(template.ID, template); }
protected virtual void CreateTemplate(DbItem item) { var isResolved = this.ResolveTemplate(item); if (isResolved) { return; } if (!ID.IsNullOrEmpty(item.TemplateID) && this.DataStorage.GetFakeTemplate(item.TemplateID) != null) { return; } if (item.TemplateID == ID.Null) { item.TemplateID = ID.NewID; } var fields = new DbFieldCollection(); foreach (var itemField in item.Fields) { var templatefield = new DbField(itemField.Name) { ID = itemField.ID }; fields.Add(templatefield); } var template = new DbTemplate(item.Name, item.TemplateID, fields); this.Add(template); }