Add() публичный Метод

Adds a new DbField to the item.
public Add ( DbField field ) : void
field DbField The field.
Результат void
    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) });
      }
    }
Пример #2
0
    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);
    }
    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, $@"<image mediapath="""" src="""" height=""{maxHeight}"" mediaid="""" ></image>" } });
      modelItem.Add(new DbItem("Inner item 2", new ID(), Templates.TeaserHeadline.ID) { { Templates.TeaserContent.Fields.Image, $@"<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);
    }
    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);
    }
Пример #5
0
 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);
 }
Пример #6
0
    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);
    }
Пример #7
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);
    }
Пример #8
0
        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 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 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();
 }
 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);
 }
Пример #12
0
 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      
 }
        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;
        }
Пример #14
0
    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);
      }
    }
    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
          }
        }
      };
    }
Пример #16
0
 public void HasFieldValue_FieldIsNull_ShouldReturnFalse(Db db, DbItem item, DbField field)
 {
   //Arrange
   field.Value = null;
   item.Add(field);
   db.Add(item);
   var testItem = db.GetItem(item.ID);
   //Act
   testItem.FieldHasValue(field.ID).Should().BeFalse();
 }
Пример #17
0
 public void HasFieldValue_FieldHasValue_ShouldReturnTrue(Db db, DbItem item, DbField field, string value)
 {
   //Arrange
   field.Value = value;
   item.Add(field);
   db.Add(item);
   var testItem = db.GetItem(item.ID);
   //Act
   testItem.FieldHasValue(field.ID).Should().BeTrue();
 }