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


C# SitecoreService类代码示例

本文整理汇总了C#中SitecoreService的典型用法代码示例。如果您正苦于以下问题:C# SitecoreService类的具体用法?C# SitecoreService怎么用?C# SitecoreService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CustomDataMapper

        public void CustomDataMapper()
        {
            //Arrange
            var templateId = ID.NewID;
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId)
                {
                    new Sitecore.FakeDb.DbItem("Child1")
                }
            })
            {
                var resolver = Utilities.CreateStandardResolver();
                resolver.DataMapperFactory.Insert(0, () => new StubDataMapper());

                var context = Context.Create(resolver);
                var service = new SitecoreService(database.Database, context);

                //Act
                var result = service.GetItem<Stub>("/sitecore");

                //Assert
                Assert.AreEqual("property test", result.Property1.Value);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:25,代码来源:Issue145.cs

示例2: Cache_CachableItemRequestedInTwoLanguagesThatDontHaveVersions_ReturnsToSeparateInstances

        public void Cache_CachableItemRequestedInTwoLanguagesThatDontHaveVersions_ReturnsToSeparateInstances()
        {
            //Arrange
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreService(database.Database);
                var lang1 = Language.Parse("fr-Fr");
                var lang2 = Language.Parse("nl-BE");
                var lang3 = Language.Parse("en");

                //Act
                using (new VersionCountDisabler())
                {
                    var langItem1 = service.GetItem<StubClass>("/sitecore/content/target", lang1);
                    var langItem2 = service.GetItem<StubClass>("/sitecore/content/target", lang2);
                    var langItem3 = service.GetItem<StubClass>("/sitecore/content/target", lang3);
                

                //Assert
                Assert.NotNull(langItem1);
                Assert.NotNull(langItem2);
                Assert.NotNull(langItem3);
                Assert.AreNotEqual(langItem2, langItem3);
                Assert.AreNotEqual(langItem2, langItem1);
                }
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:35,代码来源:CacheFixtures.cs

示例3: Cache_CachableItemRequestedTwiceReturnsTheSameInstance

        public void Cache_CachableItemRequestedTwiceReturnsTheSameInstance()
        {
            //Arrange
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreService(database.Database);
                var lang1 = Language.Parse("en");


                //Act
                var item1 = service.GetItem<StubClass>("/sitecore/content/target", lang1);
                var item2 = service.GetItem<StubClass>("/sitecore/content/target", lang1);

                //Assert
                Assert.AreEqual(item1, item2);

            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:26,代码来源:CacheFixtures.cs

示例4: ModelCounter_ConcreteModelCount_Created

        public void ModelCounter_ConcreteModelCount_Created()
        {
            //Arrange
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var config = new Config();
                config.Debug.Enabled = true;

                var context = Context.Create(Utilities.CreateStandardResolver(config));
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreService(database.Database);
                var modelCounter = context.DependencyResolver.GetModelCounter();
                modelCounter.Reset();

                //Act
                var item = service.GetItem<StubClass>("/sitecore/content/target");


                
                //Assert
                Assert.AreEqual(1, modelCounter.ConcreteModelCreated);
                Assert.AreEqual(0, modelCounter.ProxyModelsCreated);
                Assert.AreEqual(0, modelCounter.CachedModels);
                Assert.AreEqual(1, modelCounter.ModelsMapped);
                Assert.AreEqual(1, modelCounter.ModelsRequested);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:33,代码来源:ModelCounterFixture.cs

示例5: Setup

        public void Setup()
        {
            if (_hasRun)
            {
                return;
            }
            else
                _hasRun = true;

            _glassWatch = new Stopwatch();
            _rawWatch= new Stopwatch();
            

            _expected = "hello world";
            _id = new Guid("{59784F74-F830-4BCD-B1F0-1A08616EF726}");

            _context = Context.Create(Utilities.CreateStandardResolver());


            _context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

            _db = Factory.GetDatabase("master");

            //       service.Profiler = new SimpleProfiler();

            _service = new SitecoreService(_db);

            var item = _db.GetItem(new ID(_id));
            using (new ItemEditing(item, true))
            {
                item["Field"] = _expected;
            }
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:33,代码来源:PerformanceTests.cs

示例6: CreatesItem

        public void CreatesItem()
        {
            //Arrange
            var context = Context.Create(Utilities.CreateStandardResolver());

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var scContext = new SitecoreService(db);

            var parentItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue");
            var parent = scContext.GetItem<CommentPage>("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue");

            using (new SecurityDisabler())
            {
                parentItem.DeleteChildren();
            }

            var newItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue/TestName");
            Assert.IsNull(newItem);

            //Act
        //    scContext.GlassContext.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(Comment)));
            var newClass = new Comment();
            newClass.Name = "TestName";
            using (new SecurityDisabler())
            {
                scContext.Create(parent, newClass);
            }

            //Asset

            newItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue/TestName");
            Assert.IsNotNull(newItem);
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:33,代码来源:AlexGriciucCreateItemIssueFixture.cs

示例7: LazyLoading_LazyDisabledGettingParent_ReturnsConcrete

        public void LazyLoading_LazyDisabledGettingParent_ReturnsConcrete()
        {
            //Arrange
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Parent") {
                    new Sitecore.FakeDb.DbItem("Target")
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());

                var fluent = new SitecoreFluentConfigurationLoader();
                var parentConfig = fluent.Add<Stub2>();
                var lazy1Config = fluent.Add<Stub1>();
                lazy1Config.Parent(x => x.Stub2).IsNotLazy();
                context.Load(fluent);

                var service = new SitecoreService(database.Database, context);

                //Act
                var target = service.GetItem<Stub1>("/sitecore/content/parent/target");
                var parent = target.Stub2;

                //Assert
                Assert.AreEqual(typeof(Stub2), parent.GetType());
                Assert.True(parent is Stub2);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:29,代码来源:LazyLoadingFixture.cs

示例8: AddVersion_NewVersionCreated

        public void AddVersion_NewVersionCreated()
        {
            //Assign
            string path = "/sitecore/content/Tests/SitecoreService/AddVersion/Target2";
            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var service = new SitecoreService(db);

            //clean up everything 
            using (new SecurityDisabler())
            {
                var item = db.GetItem(path);
                item.Versions.RemoveAll(true);
                var firstVersion = item.Versions.AddVersion();
                Assert.AreEqual(1, firstVersion.Version.Number);
            }

            var oldVersion = service.GetItem<StubClass>(path);

            //Act
            using (new SecurityDisabler())
            {
                var newVersion = service.AddVersion(oldVersion);

                //clean up
                var item = db.GetItem(path, newVersion.Language, new Sitecore.Data.Version(newVersion.Version));
                item.Versions.RemoveVersion();
                //Assert
                Assert.AreEqual(oldVersion.Version + 1, newVersion.Version);
            }
        }
开发者ID:uv20,项目名称:Glass.Mapper,代码行数:33,代码来源:SitecoreServiceFixture.cs

示例9: Paths

        public AbstractView Paths(string term)
        {
            IEnumerable<PathQuery> result = new PathQuery[0];

            term = term.ToLower();

            if (term.StartsWith("/sitecore"))
            {
                ISitecoreService service = new SitecoreService("master");

                if (term.EndsWith("/"))
                {
                    result = service.Query<PathQuery>(term + "*");
                }
                else
                {
                    var parts = term.Split('/');

                    var query = parts.Take(parts.Length - 1).Aggregate((x, y) => "{0}/{1}".Formatted(x, y));

                    result = service.Query<PathQuery>(query + "/*");

                    result = result.Where(x => x.value.ToLower().StartsWith(term));
                        
                }
            }

            return new JsonView(result);
        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:29,代码来源:QueryController.cs

示例10: InferredTypeParentWithCache

        public void InferredTypeParentWithCache()
        {
            //Arrange
            var templateId1 = new ID(TemplateId1);
            var templateId2 = new ID(TemplateId2);
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId1)
                {
                    new Sitecore.FakeDb.DbItem("Child1", ID.NewID,templateId2)
                    {
                        new Sitecore.FakeDb.DbItem("Child2", ID.NewID,templateId1)
                    }
                }
            })
            {
                var resolver = Utilities.CreateStandardResolver();
                resolver.DataMapperFactory.Insert(0, () => new Issue145.Issue145.StubDataMapper());

                var context = Context.Create(resolver);
                var service = new SitecoreService(database.Database, context);

                var loader = new SitecoreFluentConfigurationLoader();
                var inferBase = loader.Add<InterfaceBase>();
                inferBase.Parent(x => x.Parent).InferType();
                var type1 = loader.Add<Type1>();
                type1.TemplateId(templateId1);
                type1.Import(inferBase);
                var type2 = loader.Add<Type2>();
                type2.TemplateId(templateId1);
                type2.Import(inferBase);

                context.Load(loader);

                //Act

                var child = service.GetItem<InterfaceBase>("/sitecore/content/target/child1/child2");
                int count = 0;

                while (child != null)
                {
                    count++;
                    child = child.Parent;

                }


                //Assert
                Assert.AreEqual(3, count);

            }


        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:54,代码来源:Issue247.cs

示例11: Setup

        public void Setup()
        {

            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
                new string []{"Glass.Sitecore.Mapper.Tests.SitecoreServiceFixtureNS, Glass.Sitecore.Mapper.Tests"}
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[]{new SitecoreIdDataHandler() });

            _sitecore = new SitecoreService("master");
            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");
        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:12,代码来源:SitecoreServiceFixture.cs

示例12: Execute_RequestInstanceOfClassWithServiceButLazy_ReturnsInstanceWithService

        public void Execute_RequestInstanceOfClassWithServiceButLazy_ReturnsInstanceWithService()
        {
            //Assign

            SimpleInjectorTask.Container = new Container();
            SimpleInjectorTask.Container.Register<StubServiceInterface, StubService>(); 
            
            var path = "/sitecore/content/Tests/ThirdParties/SimpleInjector/Target";

            var resolver = Utilities.CreateStandardResolver() as DependencyResolver;
            resolver.ObjectConstructionFactory.Insert(0, () => new SimpleInjectorTask());


            var context = Context.Create(resolver);
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var service = new SitecoreService(db, context);
            
            var item = db.GetItem(path);
            
            string field1Expected = "hello world";
            string field2 = item.ID.ToString();

            using (new ItemEditing(item, true))
            {
                item["Field1"] = field1Expected;
                item["Field2"] = field2;
            }

            
            //Act
            var result = service.GetItem<StubClassWithService>(path, true);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is StubClassWithService);
            Assert.AreNotEqual(typeof(StubClassWithService), result.GetType());

            var stub = result as StubClassWithService;


            Assert.AreEqual(field1Expected, stub.Field1);
            Assert.IsNotNull(stub.Service);
            Assert.IsTrue(stub.Service is StubService);


            var field2Class = stub.Field2;
            Assert.AreEqual(field1Expected, field2Class.Field1);
            Assert.IsNotNull(field2Class.Service);
            Assert.IsTrue(field2Class.Service is StubService);


        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:52,代码来源:SimpleConstructionFixture.cs

示例13: Execute_RequestInstanceOfClassWithServiceButLazy_ReturnsInstanceWithService

        public void Execute_RequestInstanceOfClassWithServiceButLazy_ReturnsInstanceWithService()
        {
            //Assign
            var path = "/sitecore/content/Tests/Pipelines/ObjectConstruction/WindsorConstruction/Target";
            var resolver = Utilities.CreateStandardResolver(true) as DependencyResolver;
            var context = Context.Create(resolver);
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var service = new SitecoreService(db, context);
            
            var item = db.GetItem(path);
            
            string field1Expected = "hello world";
            string field2 = item.ID.ToString();

            using (new ItemEditing(item, true))
            {
                item["Field1"] = field1Expected;
                item["Field2"] = field2;
            }
            

            resolver.Container.Register(
                Component.For<StubServiceInterface>().ImplementedBy<StubService>().LifestyleTransient()
                );
            
            //Act
            var result = service.GetItem<StubClassWithService>(path, true);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is StubClassWithService);
            Assert.AreNotEqual(typeof(StubClassWithService), result.GetType());

            var stub = result as StubClassWithService;


            Assert.AreEqual(field1Expected, stub.Field1);
            Assert.IsNotNull(stub.Service);
            Assert.IsTrue(stub.Service is StubService);


            var field2Class = stub.Field2;
            Assert.AreEqual(field1Expected, field2Class.Field1);
            Assert.IsNotNull(field2Class.Service);
            Assert.IsTrue(field2Class.Service is StubService);


        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:48,代码来源:WindsorConstructionFixture.cs

示例14: Setup

        public void Setup()
        {
            _context = new Context(
                new AttributeConfigurationLoader(
                    "Glass.Sitecore.Mapper.Tests.InterfaceFixtureNS, Glass.Sitecore.Mapper.Tests"), null);

            global::Sitecore.Context.Site = global::Sitecore.Configuration.Factory.GetSite("website");

            _sitecore = new SitecoreService("master");

            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");

            _test1 = _db.GetItem("/sitecore/content/Glass/Test1");
            _test2 = _db.GetItem("/sitecore/content/Glass/Test2");
            _test3 = _db.GetItem("/sitecore/content/Glass/Test1/Test3");
        }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:16,代码来源:InterfaceFixture.cs

示例15: GetAttributeField

        public void GetAttributeField()
        {
            ISitecoreService service = new SitecoreService("web");
            string fieldName = GlassSitecoreExtensions.GetFieldName<GlassAttributeTestClass>(x => x.Text, service);
            Console.Write(fieldName);
            Assert.AreEqual("Text", fieldName);

            fieldName = GlassSitecoreExtensions.GetFieldName<GlassAttributeTestClass>(x => x.Language, service);
            Assert.AreEqual(SitecoreFields.Language, fieldName);

            fieldName = GlassSitecoreExtensions.GetFieldName<GlassAttributeTestClass>(x => x.DifferentName, service);
            Assert.AreEqual("Different Name", fieldName);

            fieldName = GlassSitecoreExtensions.GetFieldName<GlassAttributeTestClass>(x => x.Id, service);
            Assert.AreEqual(SitecoreFields.Id, fieldName);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:16,代码来源:GlassIntegrationTests.cs


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