상속: IEnumerable
예제 #1
0
		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);
			}
		}
예제 #2
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);
    }
예제 #3
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);
        }
예제 #4
0
파일: Program.cs 프로젝트: nlkl/Butterfly
        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();
    }
예제 #6
0
    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();
    }
예제 #7
0
    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);
    }
예제 #8
0
    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);
    }