public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(null, content, null, false); content.Properties[propertyAlias].Value = propertyValue; //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(propertyValue, result); }
public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue() { //Assign var fieldValue = "test value"; var fieldId = new ID("{6B43481F-F129-4F53-BEEE-EA84F9B1A6D4}"); var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToProperty"); var config = new SitecoreFieldConfiguration(); config.FieldId = fieldId; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(null, item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldId] = fieldValue; item.Editing.EndEdit(); } //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(fieldValue, result); }
public void MapToCms_SetsValueByPropertyAlias_PropertyValueUpdated() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(new Stub(), content, null, false); content.Properties[propertyAlias].Value = string.Empty; //Act mapper.MapToCms(context); //Assert Assert.AreEqual(propertyValue, mapper.Value); }
public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { { "Field", "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var preValue = "some other value"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var options = new GetItemOptionsParams(); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = preValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null, options); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = fieldValue; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapCmsToProperty(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreEqual(mapper.Value, preValue); Assert.AreEqual(fieldValue, itemAfter[fieldName]); } }
public void MapPropertyToCms_FieldReadOnly_FieldNotUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { { "Field", "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = true; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; Assert.IsTrue(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapPropertyToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreNotEqual(mapper.Value, itemAfter[fieldName]); Assert.AreEqual(item[fieldName], itemAfter[fieldName]); } }
public void MapToProperty_GetsValueByFieldName_ReturnsFieldValue() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { { "Field", "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var options = new GetItemOptionsParams(); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(null, item, null, options); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = fieldValue; item.Editing.EndEdit(); } //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(fieldValue, result); } }
public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated() { //Assign var fieldValue = "test value set"; var preValue = "some other value"; var fieldName = "Field"; var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = preValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = fieldValue; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapCmsToProperty(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); Assert.AreEqual(mapper.Value, preValue); Assert.AreEqual(fieldValue, itemAfter[fieldName]); }
public void Execute_RunnerCorrectlyConfigured_CallsEachDataMapper() { //Assign var target = new Stub(); var savingContext = Substitute.For <AbstractTypeSavingContext>(); var service = Substitute.For <IAbstractService>(); var args = new ObjectSavingArgs(null, target, savingContext, service); var task = new StandardSavingTask(); var options = new GetOptions(); var dataContext = Substitute.For <AbstractDataMappingContext>(target, options); savingContext.CreateDataMappingContext(Arg.Is <IAbstractService>(x => x == service)).Returns(dataContext); var property1 = Substitute.For <AbstractPropertyConfiguration>(); var config1 = Substitute.For <AbstractPropertyConfiguration>(); var mapper1 = new StubMapper(); property1.Mapper = mapper1; config1.PropertyInfo = typeof(Stub).GetProperty("Property"); property1.PropertyInfo = config1.PropertyInfo; mapper1.Setup(new DataMapperResolverArgs(null, config1)); var property2 = Substitute.For <AbstractPropertyConfiguration>(); var config2 = Substitute.For <AbstractPropertyConfiguration>(); var mapper2 = new StubMapper(); property2.Mapper = mapper2; config2.PropertyInfo = typeof(Stub).GetProperty("Property2"); property2.PropertyInfo = config2.PropertyInfo; mapper2.Setup(new DataMapperResolverArgs(null, config2)); savingContext.Config = new AttributeConfigurationLoaderFixture.StubTypeConfiguration(); savingContext.Config.AddProperty(property1); savingContext.Config.AddProperty(property2); //Act task.Execute(args); //Assert Assert.IsTrue(mapper1.MapCalled); Assert.IsTrue(mapper2.MapCalled); }
public void MapCmsToProperty_ValueFromCms_WritesToProperty() { //Assign var obj = new StubClass(); var config = Substitute.For<AbstractPropertyConfiguration>(); var dataMapper = new StubMapper(); AbstractDataMappingContext context = Substitute.For<AbstractDataMappingContext>(obj); dataMapper.Setup(new DataMapperResolverArgs(null, config)); config.PropertyInfo = typeof(StubClass).GetProperties().First(x => x.Name == "AProperty"); //Act dataMapper.MapCmsToProperty(context); //Assert Assert.AreEqual("Hello world", obj.AProperty); Assert.AreEqual(context, dataMapper.MappingContext); }
public void MapCmsToProperty_ValueFromCms_WritesToProperty() { //Assign var obj = new StubClass(); var config = Substitute.For <AbstractPropertyConfiguration>(); var dataMapper = new StubMapper(); AbstractDataMappingContext context = Substitute.For <AbstractDataMappingContext>(obj); dataMapper.Setup(new DataMapperResolverArgs(null, config)); config.PropertyInfo = typeof(StubClass).GetProperties().First(x => x.Name == "AProperty"); //Act dataMapper.MapCmsToProperty(context); //Assert Assert.AreEqual("Hello world", obj.AProperty); Assert.AreEqual(context, dataMapper.MappingContext); }
public void Execute_RunnerCorrectlyConfigured_CallsEachDataMapper() { //Assign var target = new Stub(); var savingContext = Substitute.For<AbstractTypeSavingContext>(); var service = Substitute.For<IAbstractService>(); var args = new ObjectSavingArgs(null, target, savingContext, service); var task = new StandardSavingTask(); var dataContext = Substitute.For<AbstractDataMappingContext>(target); service.CreateDataMappingContext(savingContext).Returns(dataContext); var property1 = Substitute.For<AbstractPropertyConfiguration>(); var config1 = Substitute.For<AbstractPropertyConfiguration>(); var mapper1 = new StubMapper(); property1.Mapper = mapper1; config1.PropertyInfo = typeof (Stub).GetProperty("Property"); property1.PropertyInfo = config1.PropertyInfo; mapper1.Setup(new DataMapperResolverArgs(null, config1)); var property2 = Substitute.For<AbstractPropertyConfiguration>(); var config2 = Substitute.For<AbstractPropertyConfiguration>(); var mapper2 = new StubMapper(); property2.Mapper = mapper2; config2.PropertyInfo = typeof (Stub).GetProperty("Property2"); property2.PropertyInfo = config2.PropertyInfo; mapper2.Setup(new DataMapperResolverArgs(null, config2)); savingContext.Config = new AttributeConfigurationLoaderFixture.StubTypeConfiguration(); savingContext.Config.AddProperty(property1); savingContext.Config.AddProperty(property2); //Act task.Execute(args); //Assert Assert.IsTrue(mapper1.MapCalled); Assert.IsTrue(mapper2.MapCalled); }
public void MapToCms_SetsValueByFieldName_FieldValueUpdated() { //Assign var fieldValue = "test value set"; var fieldName = "Field"; var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); Assert.AreEqual(mapper.Value, itemAfter[fieldName]); }
public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null,config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(null, content, null); content.Properties[propertyAlias].Value = propertyValue; //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(propertyValue, result); }
public void MapToCms_SetsValueByFieldName_FieldValueUpdated() { //Assign var fieldValue = "test value set"; var fieldName = "Field"; var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null,config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapToCms(context); item.Editing.EndEdit(); } //Assert Assert.AreEqual(fieldValue, mapper.Value); }
public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue() { //Assign var fieldValue = "test value"; var fieldId = new ID("{6B43481F-F129-4F53-BEEE-EA84F9B1A6D4}"); var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToProperty"); var config = new SitecoreFieldConfiguration(); config.FieldId = fieldId; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null,config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(null, item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldId] = fieldValue; item.Editing.EndEdit(); } //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(fieldValue, result); }
public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { {"Field", ""} }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var preValue = "some other value"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = preValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = fieldValue; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapCmsToProperty(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreEqual(mapper.Value, preValue); Assert.AreEqual(fieldValue, itemAfter[fieldName]); } }
public void MapToCms_SetsValueByFieldName_FieldValueUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { {"Field", ""} }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreEqual(mapper.Value, itemAfter[fieldName]); } }
public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { {fieldId, ""} }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value"; var item = database.GetItem("/sitecore/content/Target"); var config = new SitecoreFieldConfiguration(); config.FieldId = fieldId; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; var context = new SitecoreDataMappingContext(null, item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldId] = fieldValue; item.Editing.EndEdit(); } //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(fieldValue, result); } }
public void MapToCms_SetsValueByPropertyAlias_PropertyValueUpdated() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(new Stub(), content, null); content.Properties[propertyAlias].Value = string.Empty; //Act mapper.MapToCms(context); //Assert Assert.AreEqual(propertyValue, mapper.Value); }