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


C# DbItem.Add方法代码示例

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


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

示例1: GetEnumerator_Call_ReturnScoresWithKeyName

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

示例2: GetFieldsToEdit_ItemHasFields_ReturnFields

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

示例3: GetMaxImageHeight_ImageItems_ReturnMaxHeight

    public void GetMaxImageHeight_ImageItems_ReturnMaxHeight(Db db, int maxHeight, int difference, DbItem modelItem)
    {
      //Arrange
      modelItem.Add(new DbItem("Inner item 1", new ID(), Templates.TeaserHeadline.ID) { {Templates.TeaserContent.Fields.Image, [email protected]"<image mediapath="""" src="""" height=""{maxHeight}"" mediaid="""" ></image>" } });
      modelItem.Add(new DbItem("Inner item 2", new ID(), Templates.TeaserHeadline.ID) { { Templates.TeaserContent.Fields.Image, [email protected]"<image mediapath="""" src="""" height=""{maxHeight - difference}"" mediaid="""" ></image>" } });
      db.Add(modelItem);

      var model = new DynamicTeaserModel(db.GetItem(modelItem.ID));
      //Act
      var result= model.GetMaxImageHeight();
      //Assert      
      result.Should().Be(maxHeight);
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:13,代码来源:DynamicTeaserModelExtensionsTests.cs

示例4: GetMaxImageHeight_NoImageItems_ZeroHeight

    public void GetMaxImageHeight_NoImageItems_ZeroHeight(Db db,DbItem modelItem)
    {
      //Arrange
      modelItem.Add(new DbItem("Inner item 1",new ID(), Templates.TeaserHeadline.ID));
      modelItem.Add(new DbItem("Inner item 2", new ID(), Templates.TeaserHeadline.ID));
      db.Add(modelItem);

      var model = new DynamicTeaserModel(db.GetItem(modelItem.ID));
      //Act
      var maxHeight = model.GetMaxImageHeight();
      //Assert      
      maxHeight.Should().Be(0);
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:13,代码来源:DynamicTeaserModelExtensionsTests.cs

示例5: 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

示例6: 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

示例7: 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

示例8: Main

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

示例9: Process_SiteSettingNameHasWrongFirmat_SourcesAndTemplateAreNotSet

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

示例10: Process_DatasourceProvidersAreNull_SourcesAndTemplateAreNotSet

 public void Process_DatasourceProvidersAreNull_SourcesAndTemplateAreNotSet([Frozen]DatasourceProviderFactory factory, GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName)
 {
   var setting = settingName.Replace("-", string.Empty);
   renderingItem.Add(new DbField("Datasource Location") { {"en", $"site:{setting}"} });
   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();
 }
开发者ID:mikeedwards83,项目名称:Habitat,代码行数:11,代码来源:GetDataSourceLocationAndTemplateFromSiteTests.cs

示例11: Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet

 public void Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet(IDatasourceProvider sourceProvider, [Substitute]DatasourceProviderFactory factory, DbItem renderingItem, Db db, string settingName, Item[] sources, Item sourceTemplate)
 {
   var processor  = new GetDatasourceLocationAndTemplateFromSite(factory);
   sourceProvider.GetDatasources(Arg.Any<string>(), Arg.Any<Item>()).Returns(sources);
   sourceProvider.GetDatasourceTemplate(Arg.Any<string>(), Arg.Any<Item>()).Returns(sourceTemplate);
   factory.GetProvider(Arg.Any<Database>()).Returns(sourceProvider);
   var setting = settingName.Replace("-", string.Empty);
   renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } });
   db.Add(renderingItem);
   var rendering = db.GetItem(renderingItem.ID);
   var args = new GetRenderingDatasourceArgs(rendering);
   processor.Process(args);
   args.DatasourceRoots.Should().Contain(sources);
   args.Prototype.Should().Be(sourceTemplate);
 }
开发者ID:mikeedwards83,项目名称:Habitat,代码行数:15,代码来源:GetDataSourceLocationAndTemplateFromSiteTests.cs

示例12: GetFieldEditorOptions_HasFields_DescriptorForEachField

 public void GetFieldEditorOptions_HasFields_DescriptorForEachField([Content]string[] fieldNames, NameValueCollection form, Db db, DbItem item)
 {
   //Arrange
   foreach (var field in fieldNames)
   {
     item.Add(new DbField(field));
   }
   db.Add(item);
   var testItem = db.GetItem(item.ID);
   var pipedFieldNames = string.Join("|", fieldNames);
   //Act
   var result = GetFieldsToEditService.GetFieldEditorOptions(form, pipedFieldNames, testItem);
   result.Fields.Count.Should().Be(fieldNames.Length);
   //Assert      
 }
开发者ID:kamsar,项目名称:Habitat,代码行数:15,代码来源:GetFieldsToEditServiceTests.cs

示例13: BuildSiteContext

        private SiteContext BuildSiteContext(Db db, Db coreDb, ID profileId, ID interestFolder, IEnumerable<string> interests)
        {
            var contextId = ID.NewID;
              var interestItem = new DbItem("InterestsFolder", interestFolder);
              interests.Select(i => new DbItem(i) { TemplateID = Templates.Interest.ID, Fields = { new DbField("Title", Templates.Interest.Fields.Title) { Value = i } } })
            .ToList().ForEach(x=>interestItem.Add(x));

              db.Add(new DbItem("siteroot")
              {
            TemplateID = Templates.ProfileSettigs.ID,
            Fields =
            {
              new DbField("UserProfile", Templates.ProfileSettigs.Fields.UserProfile)
              {
            Value = profileId.ToString()
              },
              new DbField("InterestsFolder", Templates.ProfileSettigs.Fields.InterestsFolder)
              {
            Value = interestFolder.ToString()
              }
            },
            Children =
            {
              interestItem
            }
              });

              coreDb.Add(new DbItem("UserProfile", profileId));

              var fakeSite = new FakeSiteContext(new StringDictionary
              {
            {
              "rootPath", "/sitecore/content/siteroot"
            },
            {
              "database", "master"
            }
              }) as SiteContext;

              Context.Item =db.GetItem(interestFolder);
              return fakeSite;
        }
开发者ID:JobiJoba,项目名称:Habitat,代码行数:42,代码来源:ProfileSettingsServiceTests.cs

示例14: GetSupportedLanguages_NoneSelected_ShouldReturnEmptyList

    public void GetSupportedLanguages_NoneSelected_ShouldReturnEmptyList(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", ""
          }
        }
      };

      siteRootItem.Add(item);
      db.Add(siteRootItem);
      var contextItem = db.GetItem(item.ID);
      Context.Item = contextItem;

      var fakeSite = new FakeSiteContext(new StringDictionary()
      {
        { "name", "fake" },
        { "database", "master" },
        {"rootPath", siteRootItem.FullPath },
        { "hostName", "local" }
      });

      using (new FakeSiteContextSwitcher(fakeSite))
      {
        var supportedLanguages = LanguageRepository.GetSupportedLanguages();
        supportedLanguages.Count().Should().Be(0);
      }
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:39,代码来源:LanguageRepositoryTests.cs

示例15: CreateHomeFolderPost

    private static Db CreateHomeFolderPost([CanBeNull] string name = null, [CanBeNull] DbField field = null)
    {
      var bloggrHome = new ID();
      var dbItem = new DbItem(name ?? "01-Post");
      if (field != null)
      {
        dbItem.Add(field);
      }

      return new Db
      {
        new DbTemplate("Bloggr Home", bloggrHome),
        new DbItem("Home", new ID(), bloggrHome)
        {
          new DbItem("Folder")
          {
            dbItem
          }
        }
      };
    }
开发者ID:alienlab,项目名称:Alienlab.Bloggr,代码行数:21,代码来源:BloggrFlatStructureTests.cs


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