public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var item = database.GetItem("/sitecore/content/TestItem");
                var service = Substitute.For<ISitecoreService>();
                var scContext = new SitecoreDataMappingContext(null, item, service);

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

                var mapper = new SitecoreParentMapper();
                mapper.Setup(new DataMapperResolverArgs(null, config));

                //Act
                var result = mapper.MapToProperty(scContext);

                //Assert

                //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
                service.Received()
                    .CreateType(config.PropertyInfo.PropertyType, Arg.Is<Item>(x => x.ID == item.Parent.ID), true, false,
                        null);
            }
        }
        public void ReadOnly_ReturnsTrue()
        {
            //Assign
            var mapper = new SitecoreParentMapper();

            //Act
            var result = mapper.ReadOnly;

            //Assert
            Assert.IsTrue(result);
        }
        public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy()
        {
            //Assign
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var item = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem");
            var service = Substitute.For<ISitecoreService>();
            var scContext = new SitecoreDataMappingContext(null, item, service);

            var config = new SitecoreParentConfiguration();
            config.PropertyInfo = typeof(Stub).GetProperty("Property");
            config.IsLazy = true;

            var mapper = new SitecoreParentMapper();
            mapper.Setup(new DataMapperResolverArgs(null,config));

            //Act
            var result = mapper.MapToProperty(scContext);

            //Assert

            //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
            service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is<Item>(x => x.ID == item.Parent.ID), true, false);
        }
        public void MapToCms_ThrowsException()
        {
            //Assign
            var mapper = new SitecoreParentMapper();

            //Act
            mapper.MapToCms(null);
        }
        public void CanHandle_ConfigurationIsSitecoreInfo_ReturnsFalse()
        {
            //Assign
            var config = new SitecoreInfoConfiguration();
            var mapper = new SitecoreParentMapper();

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

            //Assert
            Assert.IsFalse(result);
        }
        public void MapToCms_ThrowsException()
        {
            //Assign
            var mapper = new SitecoreParentMapper();

            //Act
            Assert.Throws<NotSupportedException>(()=> mapper.MapToCms(null));
        }
        public void MapToProperty_ParentDoesNotHaveLanguageVersion_ReturnsNull()
        {
            //Assign
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var language = LanguageManager.GetLanguage("af-ZA");
            var item = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem", language);

            //parent mustn't have a version
            Assert.AreEqual(0, item.Parent.Versions.Count);

            var service = Substitute.For<ISitecoreService>();
            var scContext = new SitecoreDataMappingContext(null, item, service);

            var config = new SitecoreParentConfiguration();
            config.PropertyInfo = typeof(Stub).GetProperty("Property");
            config.InferType = true;

            var mapper = new SitecoreParentMapper();
            mapper.Setup(new DataMapperResolverArgs(null, config));

            //Act
            var result = mapper.MapToProperty(scContext);

            //Assert

            //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
            service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is<Item>(x => x.ID == item.Parent.ID), true, true, null);
            Assert.IsNull(result);
        }