Inheritance: IEnumerable
Esempio n. 1
0
    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);
      }
    }
    public void GetFieldsToEdit_ItemHasNoCustomFields_ReturnEmptyString(Db db, DbItem item)
    {
      db.Add(item);
      var testItem = db.GetItem(item.ID);

      GetFieldsToEditService.GetFieldsToEdit(testItem).Should().BeEmpty();
    }
    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);
    }
Esempio n. 4
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);
    }
 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);
 }
    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) });
      }
    }
Esempio n. 7
0
		public void SharedFields_ReturnsExpectedValues(Db db, DbItem item, Guid fieldId)
		{
			item.Fields.Add(new DbField(new ID(fieldId)) { Shared = true, Value = "test field" });

			var dbItem = db.CreateItem(item);

			new ItemData(dbItem).SharedFields.Any(f => f.FieldId == fieldId).Should().BeTrue();
		}
Esempio n. 8
0
		public void SharedFields_DoesNotReturnVersionedValues(Db db, DbItem item, Guid fieldId)
		{
			item.Fields.Add(new DbField(new ID(fieldId)) { Value = "test field" });

			var dbItem = db.CreateItem(item);

			new ItemData(dbItem).SharedFields.Any(f => f.FieldId == fieldId).Should().BeFalse();
		}
 public void GetDataSources_SiteInfoIsNull_ShouldReturnNull([Frozen]ISettingsProvider settingsProvider, [Greedy]ConfigurationDatasourceProvider provider, string settingName, Item contextItem, DbItem sourceDbItem, Db db)
 {
   provider.Database = db.Database;
   db.Add(sourceDbItem);
   settingsProvider.GetCurrentSiteInfo(Arg.Any<Item>()).Returns((SiteInfo)null);
   var sources = provider.GetDatasources(settingName, contextItem);
   sources.Should().HaveCount(0);
 }
Esempio n. 10
0
 public void GetSiteDefinition_ItemInSiteHierarcy_ShouldReturnHierarchicalSiteDefinition(SiteContext siteContext, DbItem item , Db db, string siteName)
 {
   var siteDefinitionId = ID.NewID;
   db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) {item});
   var contextItem = db.GetItem(item.ID);
   var definitionItem = db.GetItem(siteDefinitionId);
   var siteDefinition = siteContext.GetSiteDefinition(contextItem);
   siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
 }
Esempio n. 11
0
		public void BranchId_ReturnsExpectedValue(Db db, DbItem item, Guid branchId)
		{
			item.BranchId = new ID(branchId);
			db.Add(item);

			var dbItem = db.GetItem(item.ID);

			new ItemData(dbItem).BranchId.Should().Be(branchId);
		}
Esempio n. 12
0
    public void GetSiteDefinition_ProviderReturnsEmpty_ShouldReturnNull(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName)
    {
      db.Add(item);
      var contextItem = db.GetItem(item.ID);

      provider.GetContextSiteDefinition(Arg.Any<Item>()).Returns((SiteDefinition)null);

      var siteContext = new SiteContext(provider);
      siteContext.GetSiteDefinition(contextItem).ShouldBeEquivalentTo(null);
    }
 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 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);
    }
Esempio n. 15
0
 public void ContextItem_HasSettingsRoot_ShouldReturnSettingsRoot(Db db, DbItem rootItem, [Substitute]ISearchSettings settings)
 {
   db.Add(rootItem);
   //Arrange
   settings.Root = db.GetItem(rootItem.ID);
   var searchService = new SearchService(settings);
   //Act
   var item = searchService.ContextItem;
   //Assert      
   item.Item.ID.ShouldBeEquivalentTo(rootItem.ID);
 }
 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 GetDataSources_ShouldReturnSourceTemplateFromSiteDefinition([Frozen]ISettingsProvider settingsProvider, [Greedy]ConfigurationDatasourceProvider provider, string settingName, Item contextItem, DbItem sourceDbItem, Db db)
 {
   provider.Database = db.Database;
   db.Add(sourceDbItem);
   var sourceTemplate = db.GetItem(sourceDbItem.ID);
   var attributeName = $"{settingName}.{ConfigurationDatasourceProvider.DatasourceTemplatePostfix}";
   var siteInfo = new SiteInfo(new StringDictionary { { attributeName, sourceTemplate.ID.ToString() } });
   settingsProvider.GetCurrentSiteInfo(Arg.Any<Item>()).Returns(siteInfo);
   var sources = provider.GetDatasourceTemplate(settingName, contextItem);
   sources.Should().NotBeNull();
   sources.ID.ShouldBeEquivalentTo(sourceTemplate.ID);
 }
Esempio n. 18
0
    public void Add(DbItem item)
    {
      Assert.ArgumentNotNull(item, "item");

      this.CreateTemplate(item);
      this.SetParent(item);
      this.EnsureIsChild(item);
      this.SetFullPath(item);
      this.CreateItem(item);
      this.CreateChildren(item);
      this.SetAccess(item);
    }
Esempio n. 19
0
 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);
 }
Esempio n. 20
0
        public void Field_Value_ReturnsExpectedValue(Db db, DbItem item, Guid fieldId)
        {
            item.Fields.Add(new DbField(new ID(fieldId))
            {
                Shared = true,
                Value = "test"
            });

            var dbItem = db.CreateItem(item);

            new ItemData(dbItem).SharedFields.First(f => f.FieldId == fieldId).FieldId.Should().Be(fieldId);
        }
        public void EvaluateNewSerializedItem_LogsCreatedItem(Db db, DbItem dbItem)
        {
            db.Add(dbItem);
            var item = db.GetItem(dbItem.ID);

            var logger = Substitute.For<ISerializedAsMasterEvaluatorLogger>();
            var evaluator = CreateTestEvaluator(logger);
            var itemData = new ItemData(item);

            evaluator.EvaluateNewSerializedItem(itemData);

            logger.Received().DeserializedNewItem(itemData);
        }
    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);
    }
 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);
 }
Esempio n. 25
0
        public void Field_NameHint_ReturnsExpectedValue(Db db, DbItem item, Guid fieldId)
        {
            item.Fields.Add(new DbField(new ID(fieldId))
            {
                Name = "Foo",
                Shared = true,
                Value = "foo"
            });

            var dbItem = db.CreateItem(item);

            new ItemData(dbItem).SharedFields.First(f => f.FieldId == fieldId).NameHint.Should().Be("Foo");
        }
        public void EvaluateNewSerializedItem_DeserializesItem(Db db, DbItem dbItem)
        {
            db.Add(dbItem);
            var item = db.GetItem(dbItem.ID);

            var deserializer = Substitute.For<IDeserializer>();
            var evaluator = CreateTestEvaluator(deserializer: deserializer);
            var itemData = new ItemData(item);

            evaluator.EvaluateNewSerializedItem(itemData);

            deserializer.Received().Deserialize(itemData);
        }
        public Item CreateFakeItem(ID id = null, ID parentId = null, string layoutValue = null,
            string finalLayoutValue = null,
            ID baseLayoutId = null,
            bool addBaseLayoutField = true)
        {
            if (ID.IsNullOrEmpty(id))
            {
                id = new ID();
            }

            if (ID.IsNullOrEmpty(parentId))
            {
                parentId = ItemIDs.ContentRoot;
            }

            if (layoutValue == null)
            {
                layoutValue =
                    "<r xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><d id=\"{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}\" l=\"{14030E9F-CE92-49C6-AD87-7D49B50E42EA}\"><r id=\"{885B8314-7D8C-4CBB-8000-01421EA8F406}\" ph=\"main\" uid=\"{43222D12-08C9-453B-AE96-D406EBB95126}\" /><r id=\"{CE4ADCFB-7990-4980-83FB-A00C1E3673DB}\" ph=\"/main/centercolumn\" uid=\"{CF044AD9-0332-407A-ABDE-587214A2C808}\" /></d></r>";
            }

            if (finalLayoutValue == null)
            {
                finalLayoutValue =
                    "<r xmlns:p=\"p\" xmlns:s=\"s\" p:p=\"1\"><d id=\"{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}\"><r uid=\"{BC07E3F3-046F-4742-AF4A-E0D22C9B600A}\" s:id=\"{493B3A83-0FA7-4484-8FC9-4680991CF743}\" s:ph=\"/main/centercolumn/content\" /></d></r>";
            }

            var dbItem = new DbItem(id.ToShortID().ToString(), id)
            {
                ParentID = parentId,
                Fields =
                {
                    {FieldIDs.LayoutField, layoutValue}
#if FINAL_LAYOUT
                    ,
                    {FieldIDs.FinalLayoutField, finalLayoutValue}
#endif
                }
            };

            if (addBaseLayoutField)
            {
                dbItem.Fields.Add(BaseLayoutItem.BaseLayoutFieldId,
                    ID.IsNullOrEmpty(baseLayoutId) ? null : baseLayoutId.ToString());
            }

            _db.Add(dbItem);

            var item = _db.GetItem(id);
            return item;
        }
		public void CreateItem_ShouldSerializeItem_TransparentSyncIsEnabled(Db db)
		{
			var target = Substitute.For<ITargetDataStore>();

			using (var provider = CreateTestProvider(db.Database, targetDataStore: target, enableTransparentSync: true))
			{
				var parent = new DbItem("Parent");
				db.Add(parent);

				provider.CreateItem(CreateTestDefinition(), ID.NewID, CreateTestDefinition(id: parent.ID), CreateTestCallContext(db.Database));

				target.Received().Save(Arg.Any<IItemData>());
			}
		}
		public void CreateItem_ShouldNotSerializeItem_WhenPredicateExcludesItem(Db db)
		{
			var target = Substitute.For<ITargetDataStore>();

			using (var provider = CreateTestProvider(db.Database, targetDataStore: target, predicate:CreateExclusiveTestPredicate()))
			{
				var parent = new DbItem("Parent");
				db.Add(parent);

				provider.CreateItem(CreateTestDefinition(), ID.NewID, CreateTestDefinition(id: parent.ID), CreateTestCallContext(db.Database));

				target.DidNotReceive().Save(Arg.Any<IItemData>());
			}
		}
 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);
 }
Esempio n. 31
0
 public void Add(DbItem child)
 {
     this.Children.Add(child);
 }
Esempio n. 32
0
        /// <summary>
        /// Adds a <see cref="DbItem" /> to the current database.
        /// </summary>
        /// <param name="item">The item to add.</param>
        public void Add(DbItem item)
        {
            Assert.ArgumentNotNull(item, "item");

            this.DataStorage.AddFakeItem(item);
        }
Esempio n. 33
0
        /// <summary>
        /// Adds a child <see cref="DbItem"/> to the item.
        /// </summary>
        /// <param name="child">The child item.</param>
        public void Add(DbItem child)
        {
            Assert.ArgumentNotNull(child, "child");

            this.Children.Add(child);
        }