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


C# Content.SetupFromSchema方法代码示例

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


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

示例1: Create_Dynamic_Search_With_Results

        public void Create_Dynamic_Search_With_Results()
        {

            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            // Ensure parent exists for this test
            Hive.AutoCommitTo<IContentStore>(x => x.Repositories.Schemas.AddOrUpdate(new ContentRootSchema()));

            // Create schema
            var schema1 = Hive.Cms().NewContentType<EntitySchema, IContentStore>("homePage")
                .Define("pageTitle", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Define("pageContent", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Commit();
            var schema2 = Hive.Cms().NewContentType<EntitySchema, IContentStore>("contentPage")
                .Define("pageTitle", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Define("pageContent", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Commit();

            Assert.True(schema1.Success);
            Assert.True(schema2.Success);

            var item1 = new Content();
            item1.SetupFromSchema(schema1.Item);
            item1.Id = new HiveId(Guid.NewGuid());
            item1["pageTitle"] = "Hello There";
            item1["pageContent"] = "some page content";

            var item2 = new Content();
            item2.SetupFromSchema(schema2.Item);
            item2.Id = new HiveId(Guid.NewGuid());
            item2["pageTitle"] = "Title 1";
            item2["pageContent"] = "this is some page content. hi, hello, goodbye.";

            var item3 = new Content();
            item3.SetupFromSchema(schema1.Item);
            item3.Id = new HiveId(Guid.NewGuid());
            item3["pageTitle"] = "Another page";
            item3["pageContent"] = "Say hello to my little friend.";

            var writerResult = Hive.AutoCommitTo<IContentStore>(x =>
            {
                x.Repositories.AddOrUpdate(item1);
                x.Repositories.AddOrUpdate(item2);
                x.Repositories.AddOrUpdate(item3);
            });
            Assert.True(writerResult.WasCommitted);
            AddRevision(item1, FixedStatusTypes.Published);
            AddRevision(item2, FixedStatusTypes.Published);
            AddRevision(item3, FixedStatusTypes.Published);

            // Check can get the items normally
            using (var uow = Hive.OpenReader<IContentStore>())
            {
                Assert.True(uow.Repositories.Exists<Content>(item1.Id));
                Assert.True(uow.Repositories.Exists<Content>(item2.Id));
                Assert.True(uow.Repositories.Exists<Content>(item3.Id));
            }

            //Create a dynamic search

            var docTypes = new[] { "homePage", "contentPage" };
            var fields = new[] { "pageTitle", "pageContent" };
            var searchTerm = "hello";
            
            using (var uow = GroupUnitFactory.Create())
            {
                var predicate = ExpressionExtensions.False<TypedEntity>();
                var query = uow.Repositories.Query();
                foreach (var d in docTypes)
                {
                    //this will add an 'AND' clause, not an 'OR' clause
                    //query = query.Where(x => x.EntitySchema.Alias == d);
                    var d1 = d;
                    predicate = predicate.Or(x => x.EntitySchema.Alias == d1);
                }
                foreach (var f in fields)
                {
                    //this will add an 'AND' clause, not an 'OR' clause
                    //query = query.Where(x => x.Attribute<string>(f) == searchTerm);
                    var f1 = f;
                    predicate = predicate.Or(x => x.Attribute<string>(f1) == searchTerm);
                }

                var result = query.Where(predicate).ToArray();

                Assert.AreEqual(3, result.Count());
            }

            
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:90,代码来源:AbstractProviderQueryTests.cs

示例2: WhenTypedEntity_QueriedWithStringEquals_AndOrderBy_ResultsAreOrdered

        public void WhenTypedEntity_QueriedWithStringEquals_AndOrderBy_ResultsAreOrdered()
        {
            var item1Id = Guid.NewGuid();
            var item2Id = Guid.NewGuid();
            var item3Id = Guid.NewGuid();
            var parentId = Guid.NewGuid();

            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            // Ensure parent exists for this test
            Hive.AutoCommitTo<IContentStore>(x => x.Repositories.Schemas.AddOrUpdate(new ContentRootSchema()));

            // Create schema
            var schema = Hive.Cms().NewContentType<EntitySchema, IContentStore>("withTitle")
                .Define("title", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Define("random", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Define("tag", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup)
                .Define("bodyText", type => type.UseExistingType("richTextEditor"), FixedGroupDefinitions.GeneralGroup)
                .Commit();

            Assert.True(schema.Success);

            var item1 = new Content();
            item1.SetupFromSchema(schema.Item);
            item1.Id = new HiveId(item1Id);
            item1["title"] = "Item1";
            item1["random"] = "Random3";
            item1["tag"] = "apple";

            var item2 = new Content();
            item2.SetupFromSchema(schema.Item);
            item2.Id = new HiveId(item2Id);
            item2["title"] = "Item2";
            item2["random"] = "Random1";
            item2["tag"] = "blueberry";

            var item3 = new Content();
            item3.SetupFromSchema(schema.Item);
            item3.Id = new HiveId(item3Id);
            item3["title"] = "Item3";
            item3["random"] = "Random2";
            item3["tag"] = "apple";

            var writerResult = Hive.AutoCommitTo<IContentStore>(x =>
                {
                    x.Repositories.AddOrUpdate(item1);
                    x.Repositories.AddOrUpdate(item2);
                    x.Repositories.AddOrUpdate(item3);
                });

            Assert.True(writerResult.WasCommitted);

            // Check can get the items normally
            using (var uow = Hive.OpenReader<IContentStore>())
            {
                Assert.True(uow.Repositories.Exists<Content>(item1.Id));
                Assert.True(uow.Repositories.Exists<Content>(item2.Id));
                Assert.True(uow.Repositories.Exists<Content>(item3.Id));
            }

            // query all with sortorder - first check is actually order of insertion anyway
            var allQuery_NaturalSort = Hive.QueryContent().OrderBy(x => x.Attribute<string>("title")).ToArray();
            Assert.That(allQuery_NaturalSort.Any());
            Assert.That(allQuery_NaturalSort[0]["title"], Is.EqualTo("Item1"));
            Assert.That(allQuery_NaturalSort[1]["title"], Is.EqualTo("Item2"));
            Assert.That(allQuery_NaturalSort[2]["title"], Is.EqualTo("Item3"));

            var allQuerySortByTag = Hive.QueryContent().OrderBy(x => x.Attribute<string>("tag")).ToArray();
            Assert.That(allQuerySortByTag.Any());
            Assert.That(allQuerySortByTag[0]["tag"], Is.EqualTo("apple"));
            Assert.That(allQuerySortByTag[0]["random"], Is.EqualTo("Random3").Or.EqualTo("Random2"));
            Assert.That(allQuerySortByTag[1]["tag"], Is.EqualTo("apple"));
            Assert.That(allQuerySortByTag[1]["random"], Is.EqualTo("Random3").Or.EqualTo("Random2"));
            Assert.That(allQuerySortByTag[2]["tag"], Is.EqualTo("blueberry"));
            Assert.That(allQuerySortByTag[2]["random"], Is.EqualTo("Random1"));

            var allQuerySortByTagThenRandom = Hive.QueryContent().OrderBy(x => x.Attribute<string>("tag")).ThenBy(x => x.Attribute<string>("random")).ToArray();
            Assert.That(allQuerySortByTagThenRandom.Any());
            Assert.That(allQuerySortByTagThenRandom[0]["tag"], Is.EqualTo("apple"));
            Assert.That(allQuerySortByTagThenRandom[0]["random"], Is.EqualTo("Random2"));
            Assert.That(allQuerySortByTagThenRandom[1]["tag"], Is.EqualTo("apple"));
            Assert.That(allQuerySortByTagThenRandom[1]["random"], Is.EqualTo("Random3"));
            Assert.That(allQuerySortByTagThenRandom[2]["tag"], Is.EqualTo("blueberry"));
            Assert.That(allQuerySortByTagThenRandom[2]["random"], Is.EqualTo("Random1"));

            // query invoking the executesingle methods
            var firstByTagDescending = Hive.QueryContent().OrderByDescending(x => x.Attribute<string>("tag")).FirstOrDefault();
            Assert.NotNull(firstByTagDescending);
            Assert.That(firstByTagDescending["tag"], Is.EqualTo("blueberry"));

            var singleByTagDescending = Hive.QueryContent().OrderByDescending(x => x.Attribute<string>("tag")).SingleOrDefault(x => x.Attribute<string>("random") == "Random2");
            Assert.NotNull(singleByTagDescending);
            Assert.That(singleByTagDescending["tag"], Is.EqualTo("apple"));
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:94,代码来源:AbstractProviderQueryTests.cs


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