public void ItemPropertySave_SavesItemOnProperty_SetsField() { /* * Tests that we can save to an item property. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); string path = "/sitecore/content/Tests/Misc/ItemPropertySave"; var expected = "some expected value"; var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field1"] = string.Empty; } var instance = scContext.GetItem <ItemPropertySaveStub>(path); //Act instance.Field1 = expected; using (new SecurityDisabler()) { scContext.Save(instance); } //Assert Assert.AreEqual(expected, instance.Item["Field1"]); }
public void DropSave() { ISitecoreContext context = new SitecoreContext(); DemoItem current = context.GetCurrentItem<DemoItem>(); OtherItem other = context.GetItem<OtherItem>("/sitecore/content/home/someOtherItem"); current.Drop = other; context.Save(current); }
public void Editable_InEditModeWithStandardOutput_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target"; var db = Sitecore.Configuration.Factory.GetDatabase("master"); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var service = new SitecoreContext(db); var html = new GlassHtml(service); var model = service.GetItem <StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue; using (new SecurityDisabler()) { service.Save(model); } var doc = new XmlDocument(); doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Edit); Sitecore.Context.Site = siteContext; //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.StringField, x => x.StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); Console.WriteLine("result " + result); }
public void Editable_InEditMode_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target"; var db = Sitecore.Configuration.Factory.GetDatabase("master"); var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var service = new SitecoreContext(db); var html = new GlassHtml(service); var model = service.GetItem<StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue ; using (new SecurityDisabler()) { service.Save(model); } var doc = new XmlDocument(); doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); siteContext.SetDisplayMode(DisplayMode.Edit); Sitecore.Context.Site = siteContext; //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); Console.WriteLine("result "+result); }
public void ItemPropertySave_SavesItemOnProperty_SetsField() { /* * Tests that we can save to an item property. */ //Assign var templateId = ID.NewID; var targetId = ID.NewID; var fieldName = "Field1"; using (Db database = new Db { new DbTemplate(templateId) { { fieldName, "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var context = Context.Create(Utilities.CreateStandardResolver()); var db = database.Database; var scContext = new SitecoreContext(db); string path = "/sitecore/content/Target"; var expected = "some expected value"; var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field1"] = string.Empty; } var instance = scContext.GetItem <ItemPropertySaveStub>(path); //Act instance.Field1 = expected; using (new SecurityDisabler()) { scContext.Save(instance); } //Assert Assert.AreEqual(expected, instance.Item["Field1"]); } }
public void MultiTreeRead() { ISitecoreContext context = new SitecoreContext(); DemoItem current = context.GetCurrentItem<DemoItem>(); OtherItem forRemoval = current.Multi.First(); current.Multi.Remove(forRemoval); OtherItem toAdd = context.GetItem<OtherItem>("/sitecore/content/home/someOtherItem"); current.Multi.Add(toAdd); context.Save(current); }
public void ItemPropertySave_SavesItemOnProperty_SetsField() { /* * Tests that we can save to an item property. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); var db = Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); string path = "/sitecore/content/Tests/Misc/ItemPropertySave"; var expected = "some expected value"; var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field1"] = string.Empty; } var instance = scContext.GetItem<ItemPropertySaveStub>(path); //Act instance.Field1 = expected; using (new SecurityDisabler()) { scContext.Save(instance); } //Assert Assert.AreEqual(expected, instance.Item["Field1"]); }
public void Editable_ComplexLambdaInEditMode_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/target"; var templateId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { new DbField("StringField") { Type = "text" } }, new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId) { {"StringField", ""} } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreContext(database.Database); var html = GetGlassHtml(service); var model = service.GetItem<StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue; using (new SecurityDisabler()) { service.Save(model); } var doc = new XmlDocument(); doc.LoadXml( "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />"); var siteContext = new SiteContextStub( new SiteInfo( doc.FirstChild ) ); using (new EnableWebEditMode()) { using (new SiteContextSwitcher(siteContext)) { //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.EnumerableSubStub.First().StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); Console.WriteLine("result " + result); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); } } } }