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();
        }
Exemple #2
0
        public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate()
        {
            // arrange
            var template = new DbTemplate("Sample", this.templateId)
            {
                this.fieldId
            };
            var originalItem = new DbItem("original item", this.itemId, this.templateId);

            this.dataStorage.GetFakeItem(this.itemId).Returns(originalItem);
            this.dataStorage.GetFakeTemplate(this.templateId).Returns(template);
            this.dataStorage.FakeItems.Add(this.itemId, originalItem);

            var fields = new FieldList {
                { this.fieldId, "updated title" }
            };
            var updatedItem = ItemHelper.CreateInstance(this.database, "updated item", this.itemId, ID.NewID, ID.Null, fields);

            this.command.Initialize(updatedItem);

            // act
            this.command.DoExecute();

            // assert
            dataStorage.FakeItems[this.itemId].Name.Should().Be("updated item");
            dataStorage.FakeItems[this.itemId].Fields[this.fieldId].Value.Should().Be("updated title");
        }
Exemple #3
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 supportedLanguages = LanguageRepository.GetSupportedLanguages();

            supportedLanguages.Count().Should().Be(0);
        }
    protected string FindStandardValueInTheTemplate(DbTemplate template, ID fieldId)
    {
      if (template.StandardValues.ContainsKey(fieldId))
      {
        return template.StandardValues[fieldId].Value;
      }

      if (template.BaseIDs == null || template.BaseIDs.Length <= 0)
      {
        return null;
      }

      foreach (var baseId in template.BaseIDs)
      {
        if (ID.IsNullOrEmpty(baseId))
        {
          continue;
        }

        var baseTemplate = this.DataStorage.GetFakeTemplate(baseId);
        if (baseTemplate == null)
        {
          throw new TemplateNotFoundException("The template \"{0}\" was not found.".FormatWith(baseId.ToString()));
        }

        var value = this.FindStandardValueInTheTemplate(baseTemplate, fieldId);
        if (value != null)
        {
          return value;
        }
      }

      return null;
    }
Exemple #5
0
        public void ShouldHaveStandardBaseTemplate([Greedy] FakeDataProvider sut, [NoAutoProperties] DbTemplate template)
        {
            sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
            var result = sut.GetTemplates(null).First();

            result.BaseIDs.Single().Should().Be(TemplateIDs.StandardTemplate);
        }
Exemple #6
0
        public void ShouldUseTheClosestStandardValue()
        {
            // arrange
            var baseTemplate = new DbTemplate()
            {
                { "Title", "Default" }
            };
            var myTemplate = new DbTemplate()
            {
                BaseIDs = new ID[] { baseTemplate.ID }
            };

            myTemplate.Add("Title", "New Default");

            using (var db = new Db
            {
                baseTemplate,
                myTemplate,
                new DbItem("home", ID.NewID, myTemplate.ID)
            })
            {
                // act
                var home = db.GetItem("/sitecore/content/home");

                // assert
                home["Title"].Should().Be("New Default");
            }
        }
Exemple #7
0
        public void Items_ItemTemplateSet_FiltersByTemplateId(Db db, [Content] DbTemplate templateItem, [Content] DbItem[] contentItems, ISearchIndex index, [ReplaceSearchProvider] SearchProvider searchProvider, string indexName, [Content] Item renderingItem)
        {
            //arrange
            var dbItem = new DbItem("templated", ID.NewID, templateItem.ID);

            db.Add(dbItem);
            var dbItems = contentItems.ToList();

            dbItems.Add(dbItem);
            var results = GetResults(dbItems);

            InitIndexes(index, searchProvider, results);


            var renderingModel = new QueryableDatasourceRenderingModel()
            {
                Rendering = new Rendering()
                {
                    DataSource = "notEmpty"
                }
            };

            renderingModel.DatasourceTemplate = db.GetItem(templateItem.ID);

            //act
            var items = renderingModel.Items;

            //assert
            items.Count().Should().Be(1);
            index.CreateSearchContext().ReceivedWithAnyArgs(1);
        }
Exemple #8
0
        public void ShouldAddFieldById([NoAutoProperties] DbTemplate template, ID fieldId)
        {
            template.Add(fieldId);

            template.Fields[fieldId].Should().NotBeNull();
            template.Fields[fieldId].Name.Should().Be(fieldId.ToShortID().ToString());
        }
        public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
        {
            // arrange
            var template = new DbTemplate("Sample", templateId)
            {
                fieldId
            };
            var originalItem = new DbItem("original item", itemId, templateId);

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(templateId).Returns(template);

            var fields = new FieldList {
                { fieldId, "updated title" }
            };
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

            sut.Initialize(updatedItem);

            // act
            ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            originalItem.Name.Should().Be("updated item");
            originalItem.Fields[fieldId].Value.Should().Be("updated title");
        }
Exemple #10
0
        public void DataGenerator_Generate_DefaultsForPriorityEtcIfNotAvailable()
        {
            var template = new DbTemplate("ContentTemplate");
            var home     = new DbItem("home");

            using (Db db = new Db
            {
                template,
                home
            })
            {
                var sfd = FileDefinition.Empty;
                sfd.FilenameToGenerate = "sitemap.xml";
                sfd.RootItem           = home.ID.ToGuid();
                sfd.SourceDatabase     = "master";
                sfd.ResolveLanguages(db.Database);

                DataGenerator sc     = new DataGenerator();
                var           urlSet = sc.Generate(sfd);

                Assert.IsNotNull(urlSet);
                Assert.AreEqual(1, urlSet.Count);

                var url = urlSet.First();
                Assert.AreEqual(0.5f, url.Priority);
                Assert.AreEqual(ChangeFrequency.Daily, url.ChangeFrequency);
            }
        }
Exemple #11
0
        public void DataGenerator_Generate_CorrectLastModifiedFieldExtracted()
        {
            var template = new DbTemplate("ContentTemplate")
            {
                new DbField("__Updated", Sitecore.FieldIDs.Updated)
            };
            var home = new DbItem("home")
            {
                { "__Updated", "15 Feb 2017 01:17:20" }
            };

            using (Db db = new Db
            {
                template,
                home
            })
            {
                var sfd = FileDefinition.Empty;
                sfd.FilenameToGenerate = "sitemap.xml";
                sfd.RootItem           = home.ID.ToGuid();
                sfd.SourceDatabase     = "master";
                sfd.ResolveLanguages(db.Database);

                DataGenerator sc     = new DataGenerator();
                var           urlSet = sc.Generate(sfd);

                Assert.IsNotNull(urlSet);
                Assert.AreEqual(1, urlSet.Count);

                var url = urlSet.First();
                Assert.IsTrue(url.LastModified.HasValue);
                Assert.AreEqual(15, url.LastModified.Value.Day);
                Assert.AreEqual(2, url.LastModified.Value.Month);
            }
        }
        protected string FindStandardValueInTheTemplate(DbTemplate template, Field field)
        {
            if (template.StandardValues.ContainsKey(field.ID))
            {
                return(template.StandardValues[field.ID].Value);
            }

            if (template.BaseIDs == null || template.BaseIDs.Length <= 0)
            {
                return(null);
            }

            foreach (var baseId in template.BaseIDs)
            {
                if (ID.IsNullOrEmpty(baseId))
                {
                    continue;
                }

                var baseTemplate = this.DataStorage(field.Database).GetFakeTemplate(baseId);
                if (baseTemplate == null)
                {
                    throw new TemplateNotFoundException("The template \"{0}\" was not found.".FormatWith(baseId.ToString()));
                }

                var value = this.FindStandardValueInTheTemplate(baseTemplate, field);
                if (value != null)
                {
                    return(value);
                }
            }

            return(null);
        }
        public static List <DbTemplate> Get(List <DbItem> items)
        {
            var templateItems = items.Where(i => i.TemplateID == TemplateIDs.Template);
            var templates     = new List <DbTemplate>();

            foreach (var templateItem in templateItems)
            {
                var template = new DbTemplate(templateItem.Name, templateItem.ID);
                template.ParentID = templateItem.ParentID;
                template.FullPath = templateItem.FullPath;

                var ids = BaseTemplateIds(templateItem, items);
                if (ids != null)
                {
                    template.BaseIDs = ids;
                }

                GetFields(items, template);

                if (!items.Any(t => t.ID == template.ParentID))
                {
                    template.ParentID = ItemIDs.TemplateRoot;
                }

                templates.Add(template);
            }

            AddMissing(items, templates, GetAllFields(templates));

            return(templates);
        }
Exemple #14
0
        public void FileDefinition_Constructor_PassingEmptyRootWorks()
        {
            var cfgTemplate = new DbTemplate("SitemapFileDefinition", FileDefinition.SitemapFileDefinitionID)
            {
                "FilenameToGenerate", "SourceDatabase", "RootItem", "LanguagesToInclude", "TemplatesToInclude"
            };
            var cfgItem = new DbItem("ExampleSitemapFileDefinition")
            {
                TemplateID = FileDefinition.SitemapFileDefinitionID,
                Fields     =
                {
                    { "FilenameToGenerate", "xyz" },
                    { "SourceDatabase",     ""    },
                    { "RootItem",           ""    },
                    { "LanguagesToInclude", ""    },
                    { "TemplatesToInclude", ""    }
                }
            };

            using (Db db = new Db
            {
                cfgTemplate,
                cfgItem
            })
            {
                Item cfg = db.GetItem("/sitecore/content/ExampleSitemapFileDefinition");
                Assert.IsNotNull(cfg);

                var sfd = new FileDefinition(cfg);

                Assert.AreEqual(Guid.Empty, sfd.RootItem);
            }
        }
Exemple #15
0
        public void FileDefinition_Constructor_LanguagesResolvedStartsFalseWhenParsing()
        {
            var cfgTemplate = new DbTemplate("SitemapFileDefinition", FileDefinition.SitemapFileDefinitionID)
            {
                "FilenameToGenerate", "SourceDatabase", "RootItem", "LanguagesToInclude", "TemplatesToInclude"
            };
            var home    = new DbItem("Home");
            var cfgItem = new DbItem("ExampleSitemapFileDefinition")
            {
                TemplateID = FileDefinition.SitemapFileDefinitionID,
                Fields     =
                {
                    { "FilenameToGenerate", "xyz"              },
                    { "SourceDatabase",     ""                 },
                    { "RootItem",           home.ID.ToString() },
                    { "LanguagesToInclude", ""                 },
                    { "TemplatesToInclude", ""                 }
                }
            };

            using (Db db = new Db
            {
                cfgTemplate,
                home,
                cfgItem
            })
            {
                Item cfg = db.GetItem("/sitecore/content/ExampleSitemapFileDefinition");
                Assert.IsNotNull(cfg);

                var sfd = new FileDefinition(cfg);

                Assert.AreEqual(false, sfd.LanguagesResolved);
            }
        }
Exemple #16
0
        public void DataGenerator_Generate_NoItemsOfRightTemplateReturnsNothing()
        {
            var template = new DbTemplate("ContentTemplate");
            var home     = new DbItem("home");

            using (Db db = new Db
            {
                template,
                home
            })
            {
                var sfd = FileDefinition.Empty;
                sfd.FilenameToGenerate = "sitemap.xml";
                sfd.RootItem           = home.ID.ToGuid();
                sfd.SourceDatabase     = "master";
                sfd.TemplatesToInclude.Add(template.ID.ToGuid());
                sfd.ResolveLanguages(db.Database);

                DataGenerator sc     = new DataGenerator();
                var           urlSet = sc.Generate(sfd);

                Assert.IsNotNull(urlSet);
                Assert.AreEqual(0, urlSet.Count);
            }
        }
        protected string FindStandardValueInTheTemplate(DbTemplate template, ID fieldId)
        {
            if (template.StandardValues.ContainsKey(fieldId))
            {
                return(template.StandardValues[fieldId].Value);
            }

            if (template.BaseIDs == null || template.BaseIDs.Length <= 0)
            {
                return(null);
            }

            foreach (var baseId in template.BaseIDs)
            {
                var baseTemplate = this.storage.GetFakeTemplate(baseId);
                var value        = this.FindStandardValueInTheTemplate(baseTemplate, fieldId);

                if (value != null)
                {
                    return(value);
                }
            }

            return(null);
        }
Exemple #18
0
        public MailDao()
        {
            QMailConfigurationSection config = (QMailConfigurationSection)ConfigurationManager.GetSection("qmailConfiguration");
            MailTableElement mailTable = config.MailTable;
            MailTableElement archiveMailTable = config.ArchiveMailTable;

            tableName = mailTable.TableName; // ConfigHelper.DefaultString("qmail.data.table", "qmail");
            archiveTableName = archiveMailTable.TableName; // ConfigHelper.DefaultString("qmail.data.archive", "archive");
            idColumn = mailTable.Id; // ConfigHelper.DefaultString("qmail.data.id", "id");
            toColumn = mailTable.To; // ConfigHelper.DefaultString("qmail.data.to", "to");
            fromColumn = mailTable.From; // ConfigHelper.DefaultString("qmail.data.from", "from");
            subjectColumn = mailTable.Subject; // ConfigHelper.DefaultString("qmail.data.subject", "subject");
            bodyColumn = mailTable.Body; // ConfigHelper.DefaultString("qmail.data.body", "body");
            createdColumn = mailTable.Created; // ConfigHelper.DefaultString("qmail.data.created", "created");
            sendingColumn = mailTable.Sending; // ConfigHelper.DefaultString("qmail.data.sending", "sending");
            sentColumn = mailTable.Sent; // ConfigHelper.DefaultString("qmail.data.sent", "sent");
            failedColumn = mailTable.Failed; // ConfigHelper.DefaultString("qmail.data.failed", "failed");

            string allColumnsAs = idColumn + " as [id], " + toColumn + " as [to], " + fromColumn + " as [from], " + subjectColumn + " as [subject], " + bodyColumn + " as [body], " + createdColumn + " as [created]";
            string allColumnsAsFromTable = allColumnsAs + " from " + tableName;
            getNextMail = "SELECT top 1 "+allColumnsAsFromTable+" where "+sendingColumn+" is null order by "+createdColumn+" asc, "+idColumn+" asc ";

            dbTemplate = new DbTemplate("qmail.database");

            verifyTables();
        }
        public TemplateInputTestFixture()
        {
            AliceTemplate       = CreateTemplate("Alice", "Hello", TemplateFieldTypes.TEXT_FIELD);
            BobTemplate         = CreateTemplate("Bob", "Hi", TemplateFieldTypes.TEXT_FIELD);
            AllisonTemplate     = CreateTemplate("Allison", "Child", TemplateFieldTypes.TEXT_FIELD, new[] { AliceTemplate.ID, BobTemplate.ID });
            FlowerChildTemplate = CreateTemplate("FlowerChild", "Grandchild", TemplateFieldTypes.TEXT_FIELD, new[] { AllisonTemplate.ID });

            _db = new Db("master")
            {
                new DbTemplate(TemplateIDs.TemplateFolder),
                new DbItem(TestingContants.TEMPLATE_FOLDER, TestingContants.TestTemplateFolderId)
                {
                    ParentID = ItemIDs.TemplateRoot, TemplateID = TemplateIDs.TemplateFolder
                },
                AliceTemplate,
                BobTemplate,
                AllisonTemplate,
                FlowerChildTemplate
            };

            _linkDbSwitcher = new LinkDatabaseSwitcher(_linkDb);
            var templateFieldTemplate = new TemplateItem(_db.GetItem(TemplateIDs.TemplateField));

            _linkDb.GetReferrers(templateFieldTemplate.InnerItem).Returns(new[]
            {
                MakeLink(AliceTemplate),
                MakeLink(BobTemplate),
                MakeLink(AllisonTemplate),
                MakeLink(FlowerChildTemplate)
            });
        }
Exemple #20
0
        public void Items_ItemTemplateSet_FiltersByTemplateId(Db db, [Content] DbTemplate templateItem, [Content] DbItem[] contentItems, ISearchIndex index, [Frozen] SearchProvider searchProvider, Switcher <SearchProvider> searchProviderSwitcher, string indexName, [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
        {
            //arrange
            var dbItem = new DbItem("templated", ID.NewID, templateItem.ID);

            db.Add(dbItem);
            var dbItems = contentItems.ToList();

            dbItems.Add(dbItem);
            var results = GetResults(dbItems);

            renderingPropertiesRepository.Get <QueryableDatasourceRenderingSettings>()
            .Returns(new QueryableDatasourceRenderingSettings
            {
                SearchResultsLimit = 10
            });

            InitIndexes(index, searchProvider, results);


            var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
            {
                Rendering          = new Rendering(),
                DatasourceString   = "notEmpty",
                DatasourceTemplate = db.GetItem(templateItem.ID)
            };

            //act
            var items = renderingModel.Items;

            //assert
            items.Count().Should().Be(1);
            index.CreateSearchContext().ReceivedWithAnyArgs(1);
        }
Exemple #21
0
        public void Initialize_TemplateResolved_DatasourceTemplateShouldBeSet([Content] DbTemplate templateItem, [Content] Item renderingItem,
                                                                              [Greedy] QueryableDatasourceRenderingModel renderingModel)
        {
            //arrange
            renderingItem = renderingItem.Database.GetItem(templateItem.ID);
            renderingModel.CorePipeline
            .When(cp => cp.Run("getRenderingDatasource", Arg.Is <GetRenderingDatasourceArgs>(a => a.RenderingItem == renderingItem)))
            .Do(ci => ci.Arg <GetRenderingDatasourceArgs>().Prototype = renderingItem);

            var rendering = new Rendering
            {
                DataSource    = "ds",
                RenderingItem = new RenderingItem(renderingItem)
            };

            ContextService.Get().Push(new PageContext());
            PageContext.Current.Item = renderingItem;

            //act
            renderingModel.Initialize(rendering);

            //assert
            renderingModel.DatasourceTemplate.Should().NotBeNull();
            renderingModel.DatasourceTemplate.ID.Should().Be(templateItem.ID);
        }
Exemple #22
0
        public void ShouldInstantiateStandardValuesCollection()
        {
            // arrange & act
            var template = new DbTemplate();

            // assert
            template.StandardValues.Should().NotBeNull();
        }
Exemple #23
0
        public void ShouldCreateTemplateFieldsUsingNamesAsLowercaseKeys()
        {
            var template = new DbTemplate {
                "Title", "Description"
            };

            template.Fields.Where(f => !f.Name.StartsWith("__")).Select(f => f.Name).ShouldBeEquivalentTo(new[] { "Title", "Description" });
        }
Exemple #24
0
        public void ShouldBeEmptyBaseIds()
        {
            // arrange
            var template = new DbTemplate();

            // act & assert
            template.BaseIDs.Should().BeEmpty();
        }
    public void ShouldAddTemplateSection(TemplateTreeBuilder sut, DbTemplate template)
    {
      sut.Build(template);

      template.Children.Should().HaveCount(1);
      template.Children.Single().Name.Should().Be("Data");
      template.Children.Single().TemplateID.Should().Be(TemplateIDs.TemplateSection);
    }
Exemple #26
0
        public void ShouldGetTemplateFields([Greedy] FakeDataProvider sut, DbTemplate template)
        {
            sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
            template.Fields.Add("Title");
            var result = sut.GetTemplates(null).First();

            result.GetField("Title").Should().NotBeNull();
        }
    public void ShouldCreateEmptyStandardValuesCollection()
    {
      // arrange & act
      var template = new DbTemplate();

      // assert
      template.StandardValues.Should().BeEmpty();
    }
    public void ShouldCreateTemplateFieldsUsingNamesAsLowercaseKeys()
    {
      // arrange
      var template = new DbTemplate { "Title", "Description" };

      // assert
      template.Fields.Select(f => f.Name).ShouldBeEquivalentTo(new[] { "Title", "Description" });
    }
    public void ShouldCreateEmptyFieldsCollectionWhenSetNameAndId()
    {
      // arrange
      var template = new DbTemplate("t", ID.NewID);

      // act & assert
      template.Fields.Should().BeEmpty();
    }
Exemple #30
0
        public void ShouldAddTemplateSection(TemplateTreeBuilder sut, DbTemplate template)
        {
            sut.Build(template);

            template.Children.Should().HaveCount(1);
            template.Children.Single().Name.Should().Be("Data");
            template.Children.Single().TemplateID.Should().Be(TemplateIDs.TemplateSection);
        }
    public void ShouldGetTemplatesWithDefaultDataSectionFromDataStorage([Greedy]FakeDataProvider sut, DbTemplate template)
    {
      sut.DataStorage.GetFakeTemplates().Returns(new[] { template });

      var result = sut.GetTemplates(null).First();

      result.GetSection("Data").Should().NotBeNull();
    }
Exemple #32
0
        public void ShouldBeAnItem()
        {
            // arrange
            var template = new DbTemplate();

            // assert
            template.Should().BeAssignableTo <DbItem>();
        }
    public void ShouldCreateEmptyFieldsCollection()
    {
      // arrange
      var template = new DbTemplate();

      // act & assert
      template.Fields.Should().BeEmpty();
    }
        private DbTemplate CreateTestTemplateInDataStorage()
        {
            var templateId = ID.NewID;
            var template   = new DbTemplate(templateId.ToString(), templateId);

            this.dataStorage.FakeTemplates.Add(template.ID, template);

            return(template);
        }
 public DbTemplateInheritanceTest()
 {
   this.baseTemplateOne = new DbTemplate("Base One", ID.NewID) { "Title" };
   this.baseTemplateTwo = new DbTemplate("Base Two", ID.NewID) { "Description" };
   this.baseTemplateThree = new DbTemplate("Base Three", ID.NewID)
     {
       BaseIDs = new[] { this.baseTemplateTwo.ID }
     };
 }
    public void ShouldNotCreateTemplateFieldItemIfStandardField(TemplateTreeBuilder sut, DbTemplate template)
    {
      template.Add("__Created");

      sut.Build(template);

      var section = template.Children.Single();
      section.Children.Should().BeEmpty();
    }
Exemple #37
0
        public void ShouldSetStandardValues([NoAutoProperties] DbTemplate template)
        {
            template.Add("Title", "$name");

            var id = template.Fields.Single(f => f.Name == "Title").ID;

            template.Fields[id].Value.Should().Be(string.Empty);
            template.StandardValues[id].Value.Should().Be("$name");
        }
Exemple #38
0
 public TemplateInputProviderTests()
 {
     _fixture             = new TemplateInputTestFixture();
     _aliceTemplate       = _fixture.AliceTemplate;
     _bobTemplate         = _fixture.BobTemplate;     // the bob template is a parent template with fields "Hi"
     _allisonTemplate     = _fixture.AllisonTemplate; // the allison template is  child template that inherits from alice and bob with fields "Child"
     _flowerChildTemplate = _fixture.FlowerChildTemplate;
     db = _fixture._db;
 }
    public void ShouldAddTemplateFieldItemsToDefaultSection(TemplateTreeBuilder sut, DbTemplate template, DbField field1, DbField field2)
    {
      template.Add(field1);
      template.Add(field2);

      sut.Build(template);

      var section = template.Children.Single();
      section.Children.Should().HaveCount(2);
    }
Exemple #40
0
        internal DbField CreateTemplateField(DbTemplate template, string name, string type)
        {
            var field = new DbField(name)
            {
                Type = type
            };

            template.Fields.Add(field);
            return(field);
        }
    public void ShouldSetStandardValues()
    {
      // arrange & act
      var template = new DbTemplate { { "Title", "$name" } };

      // assert
      var id = template.Fields.Single().ID;
      template.Fields[id].Value.Should().Be(string.Empty);
      template.StandardValues[id].Value.Should().Be("$name");
    }
Exemple #42
0
        public void ShouldAddStandardSharedFields()
        {
            // arrange & act
            var template = new DbTemplate();

            // assert
            template.Fields[FieldIDs.BaseTemplate].Shared.Should().BeTrue("__Base template");
            template.Fields[FieldIDs.Lock].Shared.Should().BeTrue("__Lock");
            template.Fields[FieldIDs.Security].Shared.Should().BeTrue("__Security");
        }
    public void ShouldSaveFieldSource(TemplateTreeBuilder sut, DbTemplate template, DbField field)
    {
      field.Source = "/sitecore/content";
      template.Add(field);

      sut.Build(template);

      var section = template.Children.Single();
      var fieldItem = section.Children.Single();
      fieldItem.Fields[TemplateFieldIDs.Source].Value.Should().Be("/sitecore/content");
    }
    public void ShouldSaveFieldType(TemplateTreeBuilder sut, DbTemplate template, DbField field)
    {
      field.Type = "General Link";
      template.Add(field);

      sut.Build(template);

      var section = template.Children.Single();
      var fieldItem = section.Children.Single();
      fieldItem.Fields[TemplateFieldIDs.Type].Value.Should().Be("General Link");
    }
    public void ShouldAddFieldCopyToStandardValues(DbTemplate template, DbField field, string standardValue)
    {
      template.Add(field, standardValue);

      template.StandardValues.Should().Contain(
        f => f.Name == field.Name &&
             f.ID == field.ID &&
             f.Shared == field.Shared &&
             f.Source == field.Source &&
             f.Type == field.Type &&
             f.Value == standardValue);
    }
    public void ShouldSetTemplateFieldItemData(TemplateTreeBuilder sut, DbTemplate template, DbField field)
    {
      template.Add(field);

      sut.Build(template);

      var section = template.Children.Single();
      var fieldItem = section.Children.Single();
      fieldItem.ID.Should().Be(field.ID);
      fieldItem.Name.Should().Be(field.Name);
      fieldItem.TemplateID.Should().Be(TemplateIDs.TemplateField);
    }
    private bool IsTemplateField(DbTemplate template, ID fieldId)
    {
      var isField = template.Fields.ContainsKey(fieldId);
      if (isField)
      {
        return true;
      }

      foreach (var baseTemplate in template.BaseIDs
        .Where(b => b != TemplateIDs.StandardTemplate)
        .Select(baseId => this.dataStorage.GetFakeTemplate(baseId)))
      {
        return this.IsTemplateField(baseTemplate, fieldId);
      }

      var standardTemplate = this.dataStorage.GetFakeTemplate(TemplateIDs.StandardTemplate);
      return standardTemplate.Fields.ContainsKey(fieldId);
    }
    public virtual void Process(AddDbItemArgs args)
    {
      var item = args.DbItem;
      var dataStorage = args.DataStorage;

      var isResolved = this.ResolveTemplate(item, dataStorage);
      if (isResolved)
      {
        new TemplateTreeBuilder().Build(item);

        return;
      }

      if (!ID.IsNullOrEmpty(item.TemplateID) && dataStorage.GetFakeTemplate(item.TemplateID) != null)
      {
        return;
      }

      if (item.TemplateID == ID.Null)
      {
        item.TemplateID = ID.NewID;
      }

      var template = new DbTemplate(item.Name, item.TemplateID)
      {
        Generated = true
      };

      foreach (var itemField in item.Fields)
      {
        var templatefield = new DbField(itemField.Name, itemField.ID)
                              {
                                Shared = itemField.Shared,
                                Type = itemField.Type,
                                Source = itemField.Source
                              };
        template.Add(templatefield);
      }

      new TemplateTreeBuilder().Build(item);

      dataStorage.AddFakeItem(template);
    }
    public void ShouldUseTheClosestStandardValue()
    {
      // arrange
      var baseTemplate = new DbTemplate { { "Title", "Default" } };
      var myTemplate = new DbTemplate { BaseIDs = new[] { baseTemplate.ID } };
      myTemplate.Add("Title", "New Default");

      using (var db = new Db
                        {
                          baseTemplate,
                          myTemplate,
                          new DbItem("home", ID.NewID, myTemplate.ID)
                        })
      {
        // act
        var home = db.GetItem("/sitecore/content/home");

        // assert
        home["Title"].Should().Be("New Default");
      }
    }
    public void ShouldGetTemplateFieldIsShared([Greedy]FakeDataProvider sut, DbTemplate template)
    {
      sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
      template.Fields.Add(new DbField("Title") { Shared = true });

      var result = sut.GetTemplates(null).First();

      result.GetField("Title").IsShared.Should().BeTrue();
    }
    public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
    {
      // arrange
      var template = new DbTemplate("Sample", templateId) { fieldId };
      var originalItem = new DbItem("original item", itemId, templateId);

      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(templateId).Returns(template);

      var fields = new FieldList { { fieldId, "updated title" } };
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

      sut.Initialize(updatedItem);

      // act
      ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      originalItem.Name.Should().Be("updated item");
      originalItem.Fields[fieldId].Value.Should().Be("updated title");
    }
    public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate()
    {
      // arrange
      var template = new DbTemplate("Sample", this.templateId) { this.fieldId };
      var originalItem = new DbItem("original item", this.itemId, this.templateId);

      this.dataStorage.GetFakeItem(this.itemId).Returns(originalItem);
      this.dataStorage.GetFakeTemplate(this.templateId).Returns(template);
      this.dataStorage.FakeItems.Add(this.itemId, originalItem);

      var fields = new FieldList { { this.fieldId, "updated title" } };
      var updatedItem = ItemHelper.CreateInstance(this.database, "updated item", this.itemId, ID.NewID, ID.Null, fields);

      this.command.Initialize(updatedItem);

      // act
      this.command.DoExecute();

      // assert
      dataStorage.FakeItems[this.itemId].Name.Should().Be("updated item");
      dataStorage.FakeItems[this.itemId].Fields[this.fieldId].Value.Should().Be("updated title");
    }
Exemple #53
0
    public void ShouldGenerateTemplateIdIfNotSet()
    {
      // arrange
      var template = new DbTemplate((ID)null);

      // act
      using (new Db { template })
      {
        // assert
        template.ID.Should().NotBeNull();
        template.ID.Should().NotBe(ID.Null);
      }
    }
    public void ShouldGetTemplateFieldType([Greedy]FakeDataProvider sut, DbTemplate template)
    {
      sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
      template.Fields.Add(new DbField("Link") { Type = "General Link" });

      var result = sut.GetTemplates(null).First();

      result.GetField("Link").Type.Should().Be("General Link");
    }
    public void ShouldGetTemplateFields([Greedy]FakeDataProvider sut, DbTemplate template)
    {
      sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
      template.Fields.Add("Title");

      var result = sut.GetTemplates(null).First();

      result.GetField("Title").Should().NotBeNull();
    }
 public void ShouldGetTemplatesFromDataStorage([Greedy]FakeDataProvider sut, DbTemplate template)
 {
   sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
   sut.GetTemplates(null).Should().HaveCount(1);
 }
 public void ShouldGetTemplateIds([Greedy]FakeDataProvider sut, DbTemplate template)
 {
   sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
   sut.GetTemplateItemIds(null).Should().Contain(template.ID);
 }
    public void ShouldGetItemFields([Greedy] FakeDataProvider sut, DbTemplate template, DbItem item, DbField field, Language language, Version version,
      CallContext context)
    {
      template.Fields.Add(field);
      item.Fields.Add(field); // ?
      item.TemplateID = template.ID;

      sut.DataStorage.GetFakeTemplate(template.ID).Returns(template);
      sut.DataStorage.GetFakeItem(item.ID).Returns(item);

      var def = new ItemDefinition(item.ID, item.Name, item.TemplateID, item.BranchId);
      var versionUri = new VersionUri(language, version);

      sut.GetItemFields(def, versionUri, context).Should().HaveCount(1);
    }
    public void ShouldGetTemplateFieldSource([Greedy]FakeDataProvider sut, DbTemplate template)
    {
      sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
      template.Fields.Add(new DbField("Multilist") { Source = "/sitecore/content" });

      var result = sut.GetTemplates(null).First();

      result.GetField("Multilist").Source.Should().Be("/sitecore/content");
    }
    protected void AddFieldsFromTemplate(FieldList allFields, DbItem fakeItem, DbTemplate fakeTemplate, Language language, Version version)
    {
      var sourceItem = this.GetSourceItem(fakeItem);

      foreach (var templateField in fakeTemplate.Fields)
      {
        var fieldId = templateField.ID;

        var itemField = this.FindItemDbField(fakeItem, templateField);
        if (itemField == null)
        {
          continue;
        }

        var value = itemField.GetValue(language.Name, version.Number);
        if (sourceItem != null && string.IsNullOrWhiteSpace(value))
        {
          continue;
        }

        if (value != null)
        {
          allFields.Add(fieldId, value);
        }
      }

      foreach (var template in fakeTemplate.BaseIDs.Select(this.GetFakeTemplate).Where(t => t != null))
      {
        this.AddFieldsFromTemplate(allFields, fakeItem, template, language, version);
      }

      if (fakeTemplate.BaseIDs.Any() || fakeTemplate.ID == TemplateIDs.StandardTemplate)
      {
        return;
      }

      var standardTemplate = this.GetFakeTemplate(TemplateIDs.StandardTemplate);
      this.AddFieldsFromTemplate(allFields, fakeItem, standardTemplate, language, version);
    }