Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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 ContextSetup()
            {
                var masterModel = new MasterModel();

                _project1 = masterModel.CreateProject(); //1
                _project2 = masterModel.CreateProject(); //2

                var server1 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/1";
                    x.Name = "1";
                });
                var server2 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/2";
                    x.Name = "2";
                });

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus())
                .Return(masterModel);

                var cruiseProjectProvider = S <ICruiseProjectModelProvider>();
                var projectResponse1      = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "1.1"
                                    }, new CcProjectViewModel {
                                        Name = "1.2"
                                    } }
                });
                var projectResponse2 = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "2.1"
                                    }, new CcProjectViewModel {
                                        Name = "2.2"
                                    } }
                });

                cruiseProjectProvider.Stub(x => x.GetProjects(server1.Id)).Return(projectResponse1);
                cruiseProjectProvider.Stub(x => x.GetProjects(server2.Id)).Return(projectResponse2);

                var mapper = new StubMapper()
                             .StubResult(new[]
                {
                    new EditProjectCruiseServerViewModel {
                        Url = "Mapped 1", Id = server1.Id
                    },
                    new EditProjectCruiseServerViewModel {
                        Url = "Mapped 2", Id = server2.Id
                    }
                });
                var provider = new AdminViewModelProvider(statusProvider, mapper, cruiseProjectProvider);

                _result = provider.GetEditProjectViewModel(null);
            }
Exemple #5
0
        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]);
            }
        }
Exemple #6
0
        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 Constructor_TypesPassed_TypesHandledSet()
        {
            //Assign
            var type1 = typeof(int);
            var type2 = typeof(string);

            //Act
            var mapper = new StubMapper(type1, type2);

            //Assert
            Assert.IsTrue(mapper.TypesHandled.Any(x => x == type1));
            Assert.IsTrue(mapper.TypesHandled.Any(x => x == type2));
        }
Exemple #8
0
        public void Constructor_TypesPassed_TypesHandledSet()
        {
            //Assign
            var type1 = typeof(int);
            var type2 = typeof(string);

            //Act
            var mapper = new StubMapper(type1, type2);

            //Assert
            Assert.IsTrue(mapper.TypesHandled.Any(x => x == type1));
            Assert.IsTrue(mapper.TypesHandled.Any(x => x == type2));
        }
        public void CanHandle_TypeIsHandledWithConfig_ReturnsTrue()
        {
            //Assign
            var config = new SitecoreFieldConfiguration();
            var type1 = typeof (string);
            var mapper = new StubMapper(type1);

            config.PropertyInfo = typeof (Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsTrue(result);
        }
Exemple #10
0
        public void CanHandle_IncorrectPropertType_ReturnsFalse()
        {
            //Assign
            var config = new UmbracoIdConfiguration();
            var type1  = typeof(int);
            var mapper = new StubMapper(type1);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsFalse(result);
        }
Exemple #11
0
        public void CanHandle_TypeIsHandledWithConfig_ReturnsTrue()
        {
            //Assign
            var config = new UmbracoPropertyConfiguration();
            var type1  = typeof(string);
            var mapper = new StubMapper(type1);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsTrue(result);
        }
Exemple #12
0
        public void CanHandle_TwoTypesAreHandledWithConfig_ReturnsTrue()
        {
            //Assign
            var config = new SitecoreFieldConfiguration();
            var type2  = typeof(string);
            var type1  = typeof(int);
            var mapper = new StubMapper(type1, type2);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsTrue(result);
        }
        public void CanHandle_TwoTypesAreHandledWithConfig_ReturnsTrue()
        {
            //Assign
            var config = new UmbracoPropertyConfiguration();
            var type2 = typeof(string);
            var type1 = typeof(int);
            var mapper = new StubMapper(type1, type2);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsTrue(result);
        }
Exemple #14
0
        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);
            }
        }
Exemple #15
0
        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);
        }
Exemple #17
0
        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_DataMapperAttributeLoadedFromMapperCollection_SetsResultToSpecifiedMapper()
        {
            //Assign

            var task = new DataMapperAttributeResolverTask();
            var configuration = Substitute.For<AbstractPropertyConfiguration>();
            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var mapper=new StubMapper();

            var args = new DataMapperResolverArgs(null, configuration);
            args.DataMappers = new AbstractDataMapper[] {mapper};
            
            //Act
            task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
        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);
        }
Exemple #21
0
        public void Execute_DataMapperAttribute_SetsResultToMatchingRegisteredMapper()
        {
            //Assign
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var mapper = new StubMapper();
            var args   = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = new List <AbstractDataMapper> {
                mapper
            };

            //Act
            _task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
        public void Execute_DataMapperAttributeLoadedFromMapperCollection_SetsResultToSpecifiedMapper()
        {
            //Assign

            var task          = new DataMapperAttributeResolverTask();
            var configuration = Substitute.For <AbstractPropertyConfiguration>();

            configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

            var mapper = new StubMapper();

            var args = new DataMapperResolverArgs(null, configuration);

            args.DataMappers = new AbstractDataMapper[] { mapper };

            //Act
            task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
Exemple #23
0
        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_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_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 Execute_DataMapperAttribute_SetsResultToMatchingRegisteredMapper()
        {
            //Assign
            var configuration = Substitute.For<AbstractPropertyConfiguration>();
            configuration.PropertyInfo = typeof (StubClass).GetProperty("StubMapperProperty");

            var mapper = new StubMapper();
            var args = new DataMapperResolverArgs(null, configuration);
            args.DataMappers = new List<AbstractDataMapper> {mapper};

            //Act
            _task.Execute(args);

            //Assert
            Assert.IsNotNull(args.Result);
            Assert.AreEqual(mapper, args.Result);
        }
        public void CanHandle_IncorrectConfigType_ReturnsFalse()
        {
            //Assign
            var config = new SitecoreIdConfiguration();
            var type2 = typeof(string);
            var type1 = typeof(int);
            var mapper = new StubMapper(type1, type2);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsFalse(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 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 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 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_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);
        }