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 GetSupportedLanguages_OneSelected_ShouldReturnSelected(Db db, [Content] DbTemplate template, DbItem item, string rootName) { template.BaseIDs = new[] { Templates.Site.ID, Feature.Language.Templates.LanguageSettings.ID }; var languageItem = new DbItem("en"); db.Add(languageItem); var siteRootItem = new DbItem(rootName, ID.NewID, template.ID) { new DbField(Feature.Language.Templates.LanguageSettings.Fields.SupportedLanguages) { { "en", languageItem.ID.ToString() } } }; siteRootItem.Add(item); db.Add(siteRootItem); var contextItem = db.GetItem(item.ID); Context.Item = contextItem; var supportedLanguages = LanguageRepository.GetSupportedLanguages(); supportedLanguages.Count().Should().BeGreaterThan(0); }
public void LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable(Db db, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile) { var profileItem = new DbItem("profile", ID.NewID, new TemplateID(ProfileItem.TemplateID)); db.Add(profileItem); var profileSettingItem = new DbItem("profileSetting", ID.NewID, new TemplateID(Templates.ProfilingSettings.ID)) { {Templates.ProfilingSettings.Fields.SiteProfiles, profileItem.ID.ToString()} }; db.Add(profileSettingItem); var provider = new ProfileProvider(); var fakeSiteContext = new FakeSiteContext(new StringDictionary { {"rootPath", "/sitecore"}, {"startItem", profileSettingItem.FullPath.Remove(0, "/sitecore".Length)} }) { Database = db.Database }; using (new SiteContextSwitcher(fakeSiteContext)) { var siteProfiles = provider.GetSiteProfiles(); siteProfiles.Count().Should().Be(1); } }
public void RenderParallaxMediaAttributes_Video_ShouldReturnVideoType(Db db) { var homeItemId = ID.NewID; var mediaItemId = ID.NewID; db.Add(new DbItem("home", homeItemId) { new DbLinkField("BackgroundMedia", Templates.HasParallaxBackground.Fields.BackgroundMedia) { LinkType = "media", TargetID = mediaItemId } }); db.Add(new DbItem("mediaItem", mediaItemId) { { "Mime type", "video/fake" } }); var homeItem = db.GetItem(homeItemId); var htmlString = homeItem.RenderParallaxMediaAttributes(); var attributes = htmlString.ToString().Split(' ').Select(x => x.Split('=')).ToDictionary(x => x[0], val => val.Length == 1 ? "" : val[1].Trim('\'', '"')); attributes["data-multibackground-layer-0-attachment"].Should().Be("static"); attributes["data-multibackground"].Should().BeEmpty(); attributes["data-multibackground-layer-0-type"].Should().Be("video"); attributes["data-multibackground-layer-0-format"].Should().Be("fake"); }
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); } }
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); }
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); }
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); }
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); }
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); }
public void TrackRegister_Call_ShouldTrackRegistrationGoal(Db db, ID outcomeID, ITracker tracker, [Frozen]IAccountsSettingsService accountsSettingsService, [Frozen]ITrackerService trackerService, [Greedy]AccountTrackerService accountTrackerService) { // Arrange accountsSettingsService.GetRegistrationOutcome(Arg.Any<Item>()).Returns(outcomeID); db.Add(new DbItem("Item", AccountTrackerService.RegistrationGoalId)); db.Add(new DbItem("Item", AccountTrackerService.LoginGoalId)); //Act accountTrackerService.TrackRegistration(); //Assert trackerService.Received().TrackPageEvent(AccountTrackerService.RegistrationGoalId); trackerService.Received().TrackOutcome(outcomeID); }
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"]); } }
public void GetFieldsToEdit_ItemHasNoCustomFields_ReturnEmptyString(Db db, DbItem item) { db.Add(item); var testItem = db.GetItem(item.ID); GetFieldsToEditService.GetFieldsToEdit(testItem).Should().BeEmpty(); }
public void Create_ShouldReturnNewsRepository(NewsRepositoryFactory factory, Db db, string itemName, ID itemId) { db.Add(new DbItem(itemName, itemId, Templates.NewsFolder.ID)); var contextItem = db.GetItem(itemId); var repo = factory.Create(contextItem); repo.Should().BeAssignableTo<INewsRepository>(); }
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 Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem, [Content] DbTemplate template) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = contextItem.Paths.FullPath }; //act using (new SettingsSwitcher("Foundation.LocalDatasource.LocalDatasourceFolderTemplate", template.ID.ToString())) { processor.Process(getRenderingDatasourceArgs); } //assert var datasourceFolder = contextItem.GetChildren().First(); getRenderingDatasourceArgs.DatasourceRoots.First().ID.Should().Be(datasourceFolder.ID); datasourceFolder.TemplateID.Should().Be(template.ID); }
/// <summary> /// Adds multiple DbTemplates with the option to merge fields into existing DbTemplates /// </summary> /// <param name="db"></param> /// <param name="templates"></param> /// <param name="merge"></param> public static void AddRange(this Db db, IEnumerable <DbTemplate> templates, bool merge) { if (templates != null && templates.Count() > 0) { if (merge) { db.AddRange(templates); } else { foreach (DbItem item in templates) { var existing = db.GetItem(item.ID); if (existing == null) { db.Add(item); } else { //Merge in fields } } } } }
/// <summary> /// Adds multiple DbItems with the option to merge field values into existing DbItems /// </summary> /// <param name="db"></param> /// <param name="items"></param> /// <param name="merge"></param> public static void AddRange(this Db db, IEnumerable <DbItem> items, bool merge) { if (items != null && items.Count() > 0) { if (merge) { db.AddRange(items); } else { foreach (DbItem item in items) { var existing = db.GetItem(item.ID); if (existing == null) { db.Add(item); } else { foreach (DbField field in item.Fields) { if (existing.Fields.Any(f => f.Name == field.Name)) { using (new EditContext(existing)) existing[field.Name] = field.Value; } } } } } } }
public void GetEnumerator_Call_ReturnScoresWithKeyName(Db db, ID keyId1, ID keyId2, DbItem profileItem, IBehaviorProfileContext behaviorProfile) { //Arrange using (new SecurityDisabler()) { profileItem.Add(new DbItem("Key1", keyId1, ProfileKeyItem.TemplateID) { {ProfileKeyItem.FieldIDs.NameField,"key1name" } }); profileItem.Add(new DbItem("Key2", keyId2, ProfileKeyItem.TemplateID) { {ProfileKeyItem.FieldIDs.NameField,"key2name" } }); db.Add(profileItem); var item = db.GetItem(profileItem.FullPath); var profile = new ProfileItem(item); var behaviorScores = new List<KeyValuePair<ID, float>>() { new KeyValuePair<ID, float>(keyId1, 10), new KeyValuePair<ID, float>(keyId2, 20) }; behaviorProfile.Scores.Returns(behaviorScores); var behaviorProfileDecorator = new BehaviorProfileDecorator(profile, behaviorProfile); //Act var result = behaviorProfileDecorator.ToList(); //Assert result.Should().BeEquivalentTo(new[] { new KeyValuePair<string, float>("key1name", 10), new KeyValuePair<string, float>("key2name", 20) }); } }
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 GetDataSources_SiteInfoIsNull_ShouldReturnNull([Frozen]ISettingsProvider settingsProvider, [Greedy]ConfigurationDatasourceProvider provider, string settingName, Item contextItem, DbItem sourceDbItem, Db db) { provider.Database = db.Database; db.Add(sourceDbItem); settingsProvider.GetCurrentSiteInfo(Arg.Any<Item>()).Returns((SiteInfo)null); var sources = provider.GetDatasources(settingName, contextItem); sources.Should().HaveCount(0); }
public void GetSiteDefinition_ItemOutsideSiteHierarcy_ShouldReturnContextSiteDefinition(SiteContext siteContext, DbItem item, Db db, string siteName) { var siteDefinitionId = ID.NewID; var home = new DbItem("home", ID.NewID); db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) { home }); var definitionItem = db.GetItem(siteDefinitionId); db.Add(item); var contextItem = db.GetItem(item.ID); var fakeSite = new Sitecore.FakeDb.Sites.FakeSiteContext(new Sitecore.Collections.StringDictionary { { "name", siteName }, { "database", db.Database.Name }, { "rootPath", "/sitecore/content/" + siteName }, { "startItem", "/home" } }); using (new Sitecore.Sites.SiteContextSwitcher(fakeSite)) { var siteDefinition = siteContext.GetSiteDefinition(contextItem); siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID); } }
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); }
public void BranchId_ReturnsExpectedValue(Db db, DbItem item, Guid branchId) { item.BranchId = new ID(branchId); db.Add(item); var dbItem = db.GetItem(item.ID); new ItemData(dbItem).BranchId.Should().Be(branchId); }
/// <summary> /// Add multiple DbItems /// </summary> /// <param name="db"></param> /// <param name="items"></param> public static void AddRange(this Db db, IEnumerable <DbItem> items) { if (items != null && items.Count() > 0) { foreach (var item in items) { db.Add(item); } } }
public void Get_ContextItemParentIsMatchingTemplate_ShouldReturnParent(Db db) { var contextItemId = ID.NewID; db.Add(new DbItem("context", contextItemId, Templates.SiteMetadata.ID)); var contextItem = db.GetItem(contextItemId); var keywordsModel = MetadataRepository.Get(contextItem.Add("child", new TemplateID(ID.NewID))); keywordsModel.ID.Should().Be(contextItemId); }
public void Get_ContextItemIsMatchingTemplate_ShouldReturnSelf(Db db, string contextItemName) { var contextItemId = ID.NewID; db.Add(new DbItem(contextItemName, contextItemId, Templates.SiteMetadata.ID)); var contextItem = db.GetItem(contextItemId); var keywordsModel = MetadataRepository.Get(contextItem); keywordsModel.ID.Should().Be(contextItemId); }
public void GetFieldsToEdit_ItemHasFields_ReturnFields(Db db, DbItem item, DbField field1, DbField field2) { item.Add(field1); item.Add(field2); db.Add(item); var testItem = db.GetItem(item.ID); var expectedResult = new [] {field1.Name + "|" + field2.Name, field2.Name + "|" + field1.Name}; GetFieldsToEditService.GetFieldsToEdit(testItem).Should().BeOneOf(expectedResult); }
private IChallengeStore CreateTestStore(Db db) { // fakedb doesn't like it when we create our own template with the item API. So we'll prep that in advance. db.Add(new DbTemplate("Authentication Challenge") { new DbField("Expires") }); return new TestSitecoreDatabaseChallengeStore(); }
public void SiteDefinitions_ShouldReturnSiteDefinitionFromTheItemList(Db db, ItemSiteDefinitionsProvider provider, SiteDefinitionsProviderBase baseProvider) { db.Add(new DbItem("site1", ID.NewID, Templates.Site.ID)); db.Add(new DbItem("site2", ID.NewID, Templates.Site.ID)); db.Add(new DbItem("site3", ID.NewID, Sitecore.TemplateIDs.StandardTemplate)); var fakeSite = new FakeSiteContext(new StringDictionary { {"displayMode", "normal"}, {"rootPath", "/sitecore/content"}, { "name", "site1"} }) as SiteContext; using (new SiteContextSwitcher(fakeSite)) { var results = provider.SiteDefinitions; results.Count().ShouldBeEquivalentTo(2); results.Should().As<IEnumerable<SiteDefinition>>(); } }
public void GetSiteDefinition_ProviderReturnsEmpty_ShouldReturnNull(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName) { db.Add(item); var contextItem = db.GetItem(item.ID); provider.GetContextSiteDefinition(Arg.Any<Item>()).Returns((SiteDefinition)null); var siteContext = new SiteContext(provider); siteContext.GetSiteDefinition(contextItem).ShouldBeEquivalentTo(null); }
public void Process_SiteSettingNameHasWrongFirmat_SourcesAndTemplateAreNotSet(GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName) { renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{settingName}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
public void Get_ValidVideoLinksItems_ShouldReturnItems(Db db, [Content] MediaTemplate mediaTemplate, [Content] MediaSelectorTemplate selectorTemplate, [Content] VideoTemplate vt) { var mediaItem = new DbItem("childVideo", ID.NewID, new TemplateID(Templates.HasMedia.ID)) { {Templates.HasMediaVideo.Fields.VideoLink, "videoLink"} }; db.Add(mediaItem); var selectorItem = new DbItem("selector", ID.NewID, new TemplateID(Templates.HasMediaSelector.ID)) { {Templates.HasMediaSelector.Fields.MediaSelector, mediaItem.ID.ToString()} }; db.Add(selectorItem); // substitute the original provider with the mocked one var carouselElements = MediaSelectorElementsRepository.Get(db.GetItem(selectorItem.ID)); carouselElements.Count().Should().Be(1); carouselElements.First().Item.ID.Should().Be(mediaItem.ID); carouselElements.First().Item[Templates.HasMediaVideo.Fields.VideoLink].Should().Be("videoLink"); }
/// <summary> /// Add multiple DbTemplates /// </summary> /// <param name="db"></param> /// <param name="templates"></param> public static void AddRange(this Db db, IEnumerable <DbTemplate> templates) { if (templates != null && templates.Count() > 0) { foreach (var item in templates) { db.Add(item); } } }