public void GetFieldValue_InferType_Lazy_ReturnsConcrete()
        {
            //Assign
            Item             item     = _db.GetItem(_item2Path);
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("LazyLoadedInferred"));

            _handler.ConfigureDataHandler(property);
            RootClass root = new RootClass();


            //Act
            var result = _handler.GetFieldValue(
                item.ID.ToString(),
                item,
                _service);

            root.LazyLoadedInferred = result as EmptyTemplate1;

            //Assert
            Assert.IsNotNull(root.LazyLoadedInferred);
            Assert.AreNotEqual(typeof(EmptyTemplate1), root.LazyLoadedInferred.GetType());
            Assert.AreNotEqual(typeof(EmptyTemplate2), root.LazyLoadedInferred.GetType());
            //the type is inferred so should be EmptyTemplate2
            Assert.IsTrue(root.LazyLoadedInferred is EmptyTemplate2);
        }
        private static IConfigurationLoader[] GlassLoader()
        {
            IConfigurationLoader attributes =
                new AttributeConfigurationLoader(AssemblyUtility.RelatedAssemblies.ToArray());

            return(new IConfigurationLoader[] { attributes });
        }
Esempio n. 3
0
        public static IConfigurationLoader[] GlassLoaders()
        {
            var attributes = new AttributeConfigurationLoader("Sitecore.Models");

            return(new IConfigurationLoader[] { attributes });
            //return new IConfigurationLoader[] { attributes, Models.Config.ContentConfig.Load() };
        }
Esempio n. 4
0
        public void Setup()
        {
            var loader = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });

            _db              = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _sitecore        = new SitecoreService(_db);
            _itemId          = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}");
            _item            = _db.GetItem(new ID(_itemId));
            _html            = new GlassHtml(_sitecore);
            _sltTextOriginal = _item["SingleLineText"];
            _mltTextOriginal = _item["MultiLineText"];
            _intOriginal     = _item["Integer"];
            _numberOriginal  = _item["Number"];

            using (new SecurityDisabler())
            {
                _item.Editing.BeginEdit();
                _item["SingleLineText"] = _sltContent;
                _item["MultiLineText"]  = _mltContent;
                _item["Integer"]        = _intContent;
                _item["Number"]         = _numberContent;
                _item.Editing.EndEdit();
            }
        }
Esempio n. 5
0
        public void Setup()
        {
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.SitecoreServiceFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });
        }
        public void GetPropertyAttribute_PropertyHasNoAttribute_ReturnsNull()
        {
            //Assign
            PropertyInfo propertyInfo = typeof(StubClassWithProperties).GetProperty("PropertyWithoutAttribute");

            //Act
            var result = AttributeConfigurationLoader<StubTypeConfiguration, StubPropertyConfiguration>.GetPropertyAttribute(propertyInfo);

            //Assert
            Assert.IsNull(result);
        }
Esempio n. 7
0
        public void Constructor_CreateInstance_NoErrors()
        {
            //Assign
            AttributeConfigurationLoader loader = null;

            //Act
            loader = new AttributeConfigurationLoader(new string[] { });

            //Assert
            Assert.IsNotNull(loader);
        }
Esempio n. 8
0
        public void Setup()
        {
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
                new string [] { "Glass.Sitecore.Mapper.Tests.SitecoreServiceFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] { new SitecoreIdDataHandler() });

            _sitecore = new SitecoreService("master");
            _db       = global::Sitecore.Configuration.Factory.GetDatabase("master");
        }
        public void WillHandle_LoadedClass_ReturnsTrue()
        {
            //Assign
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("LazyLoaded"));

            //Act
            var result = _handler.WillHandle(property, _service.InstanceContext.Datas, _service.InstanceContext.Classes);

            //Assert
            Assert.IsTrue(result);
        }
Esempio n. 10
0
        public void WillHandle_ReturnsFalse()
        {
            //Assign
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(ChildrenRoot).GetProperty("List"));


            //Act
            var result = _handler.WillHandle(property, null, null);

            //Assert
            Assert.IsFalse(result);
        }
Esempio n. 11
0
        public void GetProperty_AttributeInheritedFromInterface_MultipleInheritenceChain_PropertyDoesntExistOnOneInterface()
        {
            //Assign
            var prop = typeof(AttributeConfigurationLoaderFixtureNS.GetProperty.Concrete).GetProperty("Prop3");

            //Act
            var result = AttributeConfigurationLoader.GetProperty(prop);

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Attribute is SitecoreFieldAttribute);
        }
        public void GetContext_ReturnsContextWithLoadedClass()
        {
            //Act
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.ContextFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });
            InstanceContext instance = Context.GetContext();

            //Assert
            Assert.AreEqual(2, instance.Classes.Count());
        }
Esempio n. 13
0
        public void Constructor_NoParameters()
        {
            //Assign

            AttributeConfigurationLoader loader = new AttributeConfigurationLoader();

            //Act
            var result = loader.Load();

            //Result

            Assert.IsTrue(result.Count() > 0);
            Console.WriteLine("Classes loaded by assembly: " + result.Count());
        }
Esempio n. 14
0
        public void Load_SingleClass_LoadsClassNoMembers()
        {
            //Assign
            Type testType   = typeof(AttributeConfigurationLoaderFixtureNS.TestSet1.TestSet1);
            var  namespaces = new string [] { string.Format("{0},{1}", testType.Namespace, testType.Assembly) };
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(namespaces);

            //Act
            var result = loader.Load();

            //Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(testType, result.First().Type);
        }
Esempio n. 15
0
        public void Load_TwoClassesInNamespace_OnlyOneShouldLoad()
        {
            //Assign
            Type testType   = typeof(AttributeConfigurationLoaderFixtureNS.TestSet2.TestSet2);
            var  namespaces = new string[] { string.Format("{0},{1}", testType.Namespace, testType.Assembly) };
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(namespaces);

            //Act
            var result = loader.Load();

            //Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(testType, result.First().Type);
        }
Esempio n. 16
0
        public void Constructor_LoadClassesByAssembly()
        {
            //Assign

            AttributeConfigurationLoader loader = new AttributeConfigurationLoader("Glass.Sitecore.Mapper.Tests");

            //Act
            var result = loader.Load();

            //Result

            Assert.IsTrue(result.Count() > 0);
            Console.WriteLine("Classes loaded by assembly: " + result.Count());
        }
Esempio n. 17
0
        public void Load_LoadsInheritedFromClass()
        {
            //Assign
            Type testType   = typeof(AttributeConfigurationLoaderFixtureNS.TestSet6.TestSet6);
            var  namespaces = new string[] { string.Format("{0},{1}", testType.Namespace, testType.Assembly) };
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(namespaces);

            //Act
            var result = loader.Load();

            //Assert
            Assert.AreEqual(2, result.Count());
            Assert.IsTrue(result.Any(x => x.Type == testType));
            Assert.AreEqual(2, result.First(x => x.Type == testType).Properties.Count());
        }
        public void SetFieldValue_ValidClass_ReturnsGuid()
        {
            //Assign
            EmptyTemplate1 target = new EmptyTemplate1();

            target.Id = Guid.NewGuid();
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("LazyLoaded"));

            _handler.ConfigureDataHandler(property);

            //Act
            var result = _handler.SetFieldValue(target, _service);

            //Assert
            Assert.AreEqual(target.Id, new Guid(result));
        }
Esempio n. 19
0
        public void Setup()
        {
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.MiscFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] {});
            global::Sitecore.Context.Site = global::Sitecore.Configuration.Factory.GetSite("website");

            _sitecore = new SitecoreService("master");
            _db       = global::Sitecore.Configuration.Factory.GetDatabase("master");

            _test1 = _db.GetItem("/sitecore/content/Glass/Test1");
            _test2 = _db.GetItem("/sitecore/content/Glass/Test2");
            _test3 = _db.GetItem("/sitecore/content/Glass/Test1/Test3");
            _demo  = _db.GetItem("/sitecore/content/Glass/Demo");
        }
        public void GetContext_MutlipleConfigLoadersSameNamespace_ThrowsException()
        {
            //Act
            AttributeConfigurationLoader loader1 = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.ContextFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            AttributeConfigurationLoader loader2 = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.ContextFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader1, loader2);
            InstanceContext instance = Context.GetContext();

            //Assert
            Assert.AreEqual(2, instance.Classes.Count());
        }
        public void GetContext_MutlipleConfigLoadersDifferentNamespace_ReturnsContextWithLoadedClasses()
        {
            //Act
            AttributeConfigurationLoader loader1 = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.ContextFixtureNS, Glass.Sitecore.Mapper.Tests" }
                );

            AttributeConfigurationLoader loader2 = new AttributeConfigurationLoader(
                new string[] { "Glass.Sitecore.Mapper.Tests.ContextFixtureNS2, Glass.Sitecore.Mapper.Tests" }
                );

            _context = new Context(loader1, loader2);
            InstanceContext instance = Context.GetContext();

            //Assert
            Assert.AreEqual(4, instance.Classes.Count());
        }
        public void SetFieldValue_NotLoadedClass_ThrowsException()
        {
            //Assign
            NotLoadedClass target = new NotLoadedClass();

            target.Id = Guid.NewGuid();

            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("NotLoaded"));

            _handler.ConfigureDataHandler(property);


            //Act
            var result = _handler.SetFieldValue(target, _service);

            //Assert
            Assert.AreEqual(target.Id, new Guid(result));
        }
Esempio n. 23
0
        public static void Start()
        {
            //create config
            var config = new Config();

            //create the resolver
            var resolver = DependencyResolver.CreateStandardResolver();

            resolver.Container.Install(new SitecoreInstaller(config));

            //create a context
            var context = Glass.Mapper.Context.Create(resolver, GlassRazorSettings.ContextName);

            var loader = new AttributeConfigurationLoader("Glass.Mapper.Sc.Razor");

            context.Load(
                loader
                );
        }
Esempio n. 24
0
        public void Load_LoadContextWithGenericTypeWithAutoMap_CanGetTypeConfigsFromContext()
        {
            //Assign
            var type = typeof(SampleAuto);

            //Act
            var context = Context.Create(Utilities.CreateStandardResolver());
            var loader  = new AttributeConfigurationLoader("Glass.Mapper.Sc.Integration");

            loader.AllowedNamespaces = new[] { "Glass.Mapper.Sc.Integration.ContextFixture" };

            context.Load(loader);

            //Assert
            Assert.IsNotNull(Context.Default);
            Assert.AreEqual(Context.Contexts[Context.DefaultContextName], Context.Default);
            Assert.IsNotNull(Context.Default.TypeConfigurations[type]);
            Assert.AreEqual(4, Context.Default.TypeConfigurations[type].Properties.Count());
        }
        public void GetFieldValue_InvalidData_ReturnsNull()
        {
            //Assign
            //Assign
            Item             item     = _db.GetItem(_item1Path);
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("LazyLoaded"));

            _handler.ConfigureDataHandler(property);
            RootClass root = new RootClass();

            //Act
            var result = _handler.GetFieldValue(
                "random value",
                item,
                _service);

            root.LazyLoaded = result as EmptyTemplate1;

            //Assert
            Assert.IsNull(root.LazyLoaded);
        }
Esempio n. 26
0
        public void InferringType_ReturnsClasses()
        {
            //Assign
            Item item = _db.GetItem(_itemPath);

            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(ChildrenRoot).GetProperty("Children"));

            property.Attribute.CastTo <SitecoreChildrenAttribute>().IsLazy    = true;
            property.Attribute.CastTo <SitecoreChildrenAttribute>().InferType = true;

            _handler.ConfigureDataHandler(property);

            //Act
            var results = _handler.GetValue(item, _service) as IEnumerable <EmptyTemplate1>;

            //Assert
            Assert.AreEqual(item.Children.Count, results.Count());


            //two of the item should be of type EmptyTemplate2

            Assert.AreEqual(2, results.Count(x => x is EmptyTemplate2));
        }
        public void GetFieldValue_IsLazyFalse_ReturnsConcrete()
        {
            //Assign
            Item             item     = _db.GetItem(_item1Path);
            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("NotLazyLoaded"));

            _handler.ConfigureDataHandler(property);
            RootClass root = new RootClass();


            //Act
            var result = _handler.GetFieldValue(
                item.ID.ToString(),
                item,
                _service);

            root.LazyLoaded = result as EmptyTemplate1;

            //Assert
            Assert.IsNotNull(root.LazyLoaded);
            //should not be equal because of proxy class
            Assert.AreEqual(typeof(EmptyTemplate1), root.LazyLoaded.GetType());
        }
Esempio n. 28
0
        public void GetValue_ReturnsChildren_UsingLazy()
        {
            //Assign
            Item item = _db.GetItem(_itemPath);

            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(ChildrenRoot).GetProperty("Children"));

            _handler.ConfigureDataHandler(property);

            //Act
            var          result     = _handler.GetValue(item, _service) as Enumerable <EmptyTemplate1>;
            ChildrenRoot assignTest = new ChildrenRoot();

            assignTest.Children = result;

            //Assert
            Assert.AreEqual(item.Children.Count, result.Count());
            Assert.AreEqual(result, assignTest.Children);
            //if classes are being loaded lazy they should be of the proxy type and not the concrete type
            Assert.AreNotEqual(typeof(EmptyTemplate1), result.First().GetType());
            //but the proxy inherits from the concrete
            Assert.IsTrue(result.First() is EmptyTemplate1);
        }
Esempio n. 29
0
        public void GetValue_ReturnsChildren_NotLazy()
        {
            //Assign
            Item item = _db.GetItem(_itemPath);

            SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(ChildrenRoot).GetProperty("Children"));

            property.Attribute.CastTo <SitecoreChildrenAttribute>().IsLazy = false;

            _handler.ConfigureDataHandler(property);

            //Act
            var          result     = _handler.GetValue(item, _service) as IEnumerable <EmptyTemplate1>;
            ChildrenRoot assignTest = new ChildrenRoot();

            assignTest.Children = result;
            //Assert
            Assert.AreEqual(item.Children.Count, result.Count());
            Assert.AreEqual(result, assignTest.Children);

            //if not lazy loaded then the type loaded should be the concrete type
            Assert.AreEqual(typeof(EmptyTemplate1), result.First().GetType());
            Assert.IsTrue(result.First() is EmptyTemplate1);
        }
Esempio n. 30
0
 private static void CreateContext(AttributeConfigurationLoader loader)
 {
     Assert.ArgumentNotNull(loader, "loader");
     var context = new Glass.Sitecore.Mapper.Context(loader, new GlassModuleLoader());
 }