当前位置: 首页>>代码示例>>C#>>正文


C# Db.Add方法代码示例

本文整理汇总了C#中Sitecore.FakeDb.Db.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Db.Add方法的具体用法?C# Db.Add怎么用?C# Db.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sitecore.FakeDb.Db的用法示例。


在下文中一共展示了Db.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable

    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);
      }
    }
开发者ID:Sitecore,项目名称:Habitat,代码行数:28,代码来源:ProfileProviderTests.cs

示例2: 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);
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:26,代码来源:LanguageRepositoryTests.cs

示例3: GetSupportedLanguages_OneSelected_ShouldReturnSelected

    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);
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:27,代码来源:LanguageRepositoryTests.cs

示例4: RenderParallaxMediaAttributes_Video_ShouldReturnVideoType

    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");
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:29,代码来源:MediaSelectorElementsRepositoryTests.cs

示例5: 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);
      }
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:60,代码来源:UpdateLocalDatasourceReferencesService.cs

示例6: 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);
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:32,代码来源:MetadataRepositoryTests.cs

示例7: 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);
 }
开发者ID:alinulms,项目名称:Habitat,代码行数:28,代码来源:DatasourceProviderTests.cs

示例8: 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);
 }
开发者ID:alinulms,项目名称:Habitat,代码行数:12,代码来源:DatasourceProviderTests.cs

示例9: 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);
 }
开发者ID:hinault,项目名称:Habitat,代码行数:13,代码来源:ItemDatasourceProviderTests.cs

示例10: 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);
 }
开发者ID:robearlam,项目名称:Habitat,代码行数:14,代码来源:ItemDatasourceProviderTests.cs

示例11: TrackRegister_Call_ShouldTrackRegistrationGoal

    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);
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:15,代码来源:AccountTrackerServiceTests.cs

示例12: Create_ShouldReturnNewsRepository

 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>();
 }
开发者ID:robearlam,项目名称:Habitat,代码行数:7,代码来源:NewsRepositoryFactoryTests.cs

示例13: ParseFields_ReturnsExpectedValues

		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);
			}
		}
开发者ID:OlegJytnik,项目名称:Rainbow,代码行数:31,代码来源:FieldReaderTests.cs

示例14: Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot

    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);
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:26,代码来源:GetLocalDatasourceLocationTests.cs

示例15: 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"]);
              }
        }
开发者ID:JobiJoba,项目名称:Habitat,代码行数:26,代码来源:UserProfileServiceTests.cs


注:本文中的Sitecore.FakeDb.Db.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。