本文整理汇总了C#中SitecoreService.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreService.GetItem方法的具体用法?C# SitecoreService.GetItem怎么用?C# SitecoreService.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitecoreService
的用法示例。
在下文中一共展示了SitecoreService.GetItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例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);
}
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: 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);
}
示例10: 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);
}
示例11: Execute
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull((object) context, "context");
if (context.Items.Length != 1)
return;
Item item = context.Items[0];
var scService = new SitecoreService(item.Database);
var settings = scService.GetItem<TwitterSettings>(SettingsPath);
TwitterService twitterService = new TwitterService(settings.ConsumerKey, settings.ConsumerSecret);
twitterService.AuthenticateWith(settings.AccessToken, settings.AccessTokenSecret);
TwitterUser user = twitterService.VerifyCredentials(new VerifyCredentialsOptions());
var tweet = scService.CreateType<SendTweetOptions>(item);
twitterService.SendTweet(tweet);
}
示例12: GetNavigationItems
public static IEnumerable<NavigationItem> GetNavigationItems()
{
var service = new SitecoreService(Context.ContentDatabase ?? Context.Database);
var root = service.GetItem<NavigationItem>(_rootId);
var navItems = new List<NavigationItem>();
//we can assume the root must always be shown
navItems.Add(root);
navItems.AddRange(root.SubItems);
//we have to reset the subitems on root to stop the
//rendering thinking that it should be active with child items
root.SubItems = new NavigationItem[]{};
return navItems;
}
示例13: CreatesItem
public void CreatesItem()
{
//Arrange
var templateId = ID.NewID;
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId)
{
new Sitecore.FakeDb.DbItem("Child1")
}
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
var scContext = new SitecoreService(database.Database);
var parentItem = database.GetItem("/sitecore/content/Target");
var parent = scContext.GetItem<CommentPage>("/sitecore/content/Target");
using (new SecurityDisabler())
{
parentItem.DeleteChildren();
}
var newItem = database.GetItem("/sitecore/content/Target/Child1");
Assert.IsNull(newItem);
//Act
// scContext.GlassContext.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(Comment)));
var newClass = new Comment();
newClass.Name = "Child1";
using (new SecurityDisabler())
{
scContext.Create(parent, newClass);
}
//Asset
newItem = database.GetItem("/sitecore/content/Target/Child1");
Assert.IsNotNull(newItem);
}
}
示例14: CustomDataMapper
public void CustomDataMapper()
{
//Arrange
var db = Factory.GetDatabase("master");
var resolver = Utilities.CreateStandardResolver();
resolver.DataMapperFactory.Insert(0,()=> new StubDataMapper());
var context = Context.Create(resolver);
var service = new SitecoreService(db, context);
//Act
var result = service.GetItem<Stub>("/sitecore");
//Assert
Assert.AreEqual("property test", result.Property1.Value);
}
示例15: General_RetrieveItemAndFieldsFromSitecore_ReturnPopulatedClass
public void General_RetrieveItemAndFieldsFromSitecore_ReturnPopulatedClass()
{
//Assign
string fieldValue = "test field value";
Guid id = new Guid("{A544AE18-BC21-457D-8852-438F53AAE7E1}");
string name = "Target";
var db = Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
var loader = new SitecoreFluentConfigurationLoader();
var stubConfig = loader.Add<Stub>();
stubConfig.Configure(x =>
{
x.Id(y => y.Id);
x.Field(y => y.Field);
x.Info(y => y.Name).InfoType(SitecoreInfoType.Name);
x.Delegate(y => y.Delegated).GetValue(GetDelegatedValue);
});
context.Load(loader);
var item = db.GetItem(new ID(id));
using (new ItemEditing(item, true))
{
item["Field"] = fieldValue;
}
var service = new SitecoreService(db, context);
//Act
var result = service.GetItem<Stub>(id);
//Assert
Assert.AreEqual(fieldValue, result.Field);
Assert.AreEqual(id, result.Id);
Assert.AreEqual(name, result.Name);
Assert.AreEqual("happy", result.Delegated);
}