public void Issue254_LoadingChildrenWithFluent()
        {
            
            //Arrange
            var loader = new SitecoreFluentConfigurationLoader();


            //Act
            var stubChildren = loader.Add<StubWithChildren>();
            stubChildren.Children(x => x.BaseChildren);

            var stubInherit1 = loader.Add<StubInherit1>();
            stubInherit1.Import(stubChildren);
            stubInherit1.AutoMap();

            var stubInherit2 = loader.Add<StubInherit1>();
            stubInherit2.Import(stubInherit1);
            stubInherit2.AutoMap();

            //Assert
            Assert.IsTrue(stubChildren.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));
            Assert.IsTrue(stubInherit1.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));
            Assert.IsTrue(stubInherit2.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));


        }
        public void LazyLoading_LazyDisabledGettingParent_ReturnsConcrete()
        {
            //Arrange
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Parent") {
                    new Sitecore.FakeDb.DbItem("Target")
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());

                var fluent = new SitecoreFluentConfigurationLoader();
                var parentConfig = fluent.Add<Stub2>();
                var lazy1Config = fluent.Add<Stub1>();
                lazy1Config.Parent(x => x.Stub2).IsNotLazy();
                context.Load(fluent);

                var service = new SitecoreService(database.Database, context);

                //Act
                var target = service.GetItem<Stub1>("/sitecore/content/parent/target");
                var parent = target.Stub2;

                //Assert
                Assert.AreEqual(typeof(Stub2), parent.GetType());
                Assert.True(parent is Stub2);
            }
        }
Esempio n. 3
0
        public static SitecoreFluentConfigurationLoader Load()
        {
            var loader = new SitecoreFluentConfigurationLoader();

            var eventConfig = loader.Add<Event>().AutoMap();
            eventConfig.Field(x => x.Title);
            eventConfig.Id(x => x.Id);
            eventConfig.Info(x => x.Language).InfoType(SitecoreInfoType.Language);

            return loader;
        }
Esempio n. 4
0
        public void InferredTypeParentWithCache()
        {
            //Arrange
            var templateId1 = new ID(TemplateId1);
            var templateId2 = new ID(TemplateId2);
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId1)
                {
                    new Sitecore.FakeDb.DbItem("Child1", ID.NewID,templateId2)
                    {
                        new Sitecore.FakeDb.DbItem("Child2", ID.NewID,templateId1)
                    }
                }
            })
            {
                var resolver = Utilities.CreateStandardResolver();
                resolver.DataMapperFactory.Insert(0, () => new Issue145.Issue145.StubDataMapper());

                var context = Context.Create(resolver);
                var service = new SitecoreService(database.Database, context);

                var loader = new SitecoreFluentConfigurationLoader();
                var inferBase = loader.Add<InterfaceBase>();
                inferBase.Parent(x => x.Parent).InferType();
                var type1 = loader.Add<Type1>();
                type1.TemplateId(templateId1);
                type1.Import(inferBase);
                var type2 = loader.Add<Type2>();
                type2.TemplateId(templateId1);
                type2.Import(inferBase);

                context.Load(loader);

                //Act

                var child = service.GetItem<InterfaceBase>("/sitecore/content/target/child1/child2");
                int count = 0;

                while (child != null)
                {
                    count++;
                    child = child.Parent;

                }


                //Assert
                Assert.AreEqual(3, count);

            }


        }
        public static SitecoreFluentConfigurationLoader Load()
        {
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<SendTweetOptions>().Fields(x=>
            {
                x.Field(y => y.Status);
                x.Field(y => y.Lat);
                x.Field(y => y.Long);
                x.Field(y => y.DisplayCoordinates);
                x.Field(y => y.TrimUser);
            });

            return loader;
        }
        public void General_RetrieveItemAndFieldsFromSitecore_ReturnPopulatedClass()
        {
            //Assign
            string fieldValue = "test field value";
            Guid id = new Guid("{A544AE18-BC21-457D-8852-438F53AAE7E1}");
            string name = "Target";

            var db = Factory.GetDatabase("master");
            
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            var stubConfig = loader.Add<Stub>();
            stubConfig.Configure(x =>
                                     {
                                         x.Id(y => y.Id);
                                         x.Field(y => y.Field);
                                         x.Info(y => y.Name).InfoType(SitecoreInfoType.Name);
                                         x.Delegate(y => y.Delegated).GetValue(GetDelegatedValue);
                                     });

            context.Load(loader);

            var item = db.GetItem(new ID(id));

            using (new ItemEditing(item, true))
            {
                item["Field"] = fieldValue;
            }

            var service = new SitecoreService(db, context);

            //Act
            var result = service.GetItem<Stub>(id);

            //Assert
            Assert.AreEqual(fieldValue, result.Field);
            Assert.AreEqual(id, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.AreEqual("happy", result.Delegated);

        }
        public void Private_RecursiveIndirect_ThrowsException()
        {
            //Arrange
            Guid   id       = Guid.NewGuid();
            string expected = "Field Value";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", new ID(id))
                {
                    { "Field1", id.ToString() }
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                var loader  = new SitecoreFluentConfigurationLoader();
                loader.Add(PrivateModelRecursive.Load());
                loader.Add(PrivateModelIndirectRecursive.Load());
                context.Load(loader);



                var service = new SitecoreService(database.Database, context);

                //Act
                //Arrange
                var exception = Assert.Throws(typeof(MapperException), () =>
                {
                    var result = service.GetItem <PrivateModelIndirectRecursive>(id, x => { });
                });

                while ((exception is MapperStackException) == false && exception.InnerException != null)
                {
                    exception = exception.InnerException;
                }

                Assert.IsTrue(exception is MapperStackException);
            }
        }
Esempio n. 8
0
        public void Execute()
        {
            if (Disabled)
            return;
            var loader = new SitecoreFluentConfigurationLoader();

            var isitecoreItemConfig = loader.Add<ISitecoreItem>().TemplateId(new Guid("{1930BBEB-7805-471A-A3BE-4858AC7CF696}")).AutoMap();
            isitecoreItemConfig.Info(x => x.TemplateId).InfoType(SitecoreInfoType.TemplateId);
            isitecoreItemConfig.Info(x => x.SitecorePath).InfoType(SitecoreInfoType.FullPath);
            isitecoreItemConfig.Info(x => x.Name).InfoType(SitecoreInfoType.Name);
            isitecoreItemConfig.Info(x => x.BaseTemplateIds).InfoType(SitecoreInfoType.BaseTemplateIds);
            isitecoreItemConfig.Info(x => x.Language).InfoType(SitecoreInfoType.Language);
            isitecoreItemConfig.Field(x => x.SortOrder).FieldId(new Guid("{BA3F86A2-4A1C-4D78-B63D-91C2779C1B5E}")).FieldType(SitecoreFieldType.Integer).SectionName("Name");
            isitecoreItemConfig.Field(x => x.Icon).FieldId(new Guid("{06D5295C-ED2F-4A54-9BF2-26228D113318}")).Configuration.CodeFirst = false;

            loader.Add<ISearchable>().CodeFirst().TemplateId(new Guid("{41d82537-4720-409b-903e-2bb2f64312f2}"));

            var sitecoreItemConfig  = loader.Add<SitecoreItem>().TemplateId(new Guid("{1930BBEB-7805-471A-A3BE-4858AC7CF696}")).AutoMap();
            sitecoreItemConfig.Import(isitecoreItemConfig);

            _resolver.RegisterInstance<IConfigurationLoader>(loader);
        }
Esempio n. 9
0
        public void OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored()
        {
            //Assign
            string path     = "/sitecore/content/Tests/Misc/FieldConfigOrder";
            string expected = "Hello space";


            var fluentConfig = new SitecoreFluentConfigurationLoader();

            var typeConfig = fluentConfig.Add <FieldOrderOnIgnore>();

            typeConfig.AutoMap();
            typeConfig.Field(x => x.ConfiguredTitle).FieldName("Title");
            typeConfig.Ignore(x => x.Title);

            var context = Context.Create(Utilities.CreateStandardResolver());

            context.Load(fluentConfig);

            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            var item = db.GetItem(path);

            using (new ItemEditing(item, true))
            {
                item["Title"] = expected;
            }

            var scContext = new SitecoreContext(db);


            //Act
            var instance = scContext.GetItem <FieldOrderOnIgnore>(path);


            //Assert
            Assert.AreEqual(expected, instance.ConfiguredTitle);
            Assert.IsNullOrEmpty(instance.Title);
        }
        public void GlassDataProvider_ReturnsTemplate()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add <CodeFirstClass1>()
            .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
            .TemplateName("CodeFirstClass1")
            .CodeFirst();

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
        }
        public void ModelCounter_ConcreteModelCount_Cached()
        {
            //Arrange
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var config = new Config();
                config.Debug.Enabled = true;

                var context = Context.Create(Utilities.CreateStandardResolver(config));
                var fluentloader = new SitecoreFluentConfigurationLoader();
                var stubLoader = fluentloader.Add<StubClass>();
                stubLoader.Cachable();

                context.Load(fluentloader);

                var service = new SitecoreService(database.Database);
                var modelCounter = context.DependencyResolver.GetModelCounter();
                modelCounter.Reset();

                //Act
                var item1 = service.GetItem<StubClass>("/sitecore/content/target");
                var item2 = service.GetItem<StubClass>("/sitecore/content/target");



                //Assert
                Assert.AreEqual(1, modelCounter.ConcreteModelCreated);
                Assert.AreEqual(0, modelCounter.ProxyModelsCreated);
                Assert.AreEqual(1, modelCounter.CachedModels);
                Assert.AreEqual(1, modelCounter.ModelsMapped);
                Assert.AreEqual(2, modelCounter.ModelsRequested);
            }
        }
Esempio n. 12
0
        public void ModelCounter_ConcreteModelCount_Cached()
        {
            //Arrange
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var config = new Config();
                config.Debug.Enabled = true;

                var context      = Context.Create(Utilities.CreateStandardResolver(config));
                var fluentloader = new SitecoreFluentConfigurationLoader();
                var stubLoader   = fluentloader.Add <StubClass>();
                stubLoader.Cachable();

                context.Load(fluentloader);

                var service      = new SitecoreService(database.Database);
                var modelCounter = context.DependencyResolver.GetModelCounter();
                modelCounter.Reset();

                //Act
                var item1 = service.GetItem <StubClass>("/sitecore/content/target");
                var item2 = service.GetItem <StubClass>("/sitecore/content/target");



                //Assert
                Assert.AreEqual(1, modelCounter.ConcreteModelCreated);
                Assert.AreEqual(0, modelCounter.ProxyModelsCreated);
                Assert.AreEqual(1, modelCounter.CachedModels);
                Assert.AreEqual(1, modelCounter.ModelsMapped);
                Assert.AreEqual(2, modelCounter.ModelsRequested);
            }
        }
        public void GlassDataProvider_TemplateInNamespaceTwoDeep_ReturnsTemplate()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add <Templates.Level1.Level2.CodeFirstClass3>()
            .TemplateId("E33F1C58-FAB2-475A-B2FE-C26F5D7565A2")
            .TemplateName("CodeFirstClass2")
            .CodeFirst();

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/Level1/Level2/CodeFirstClass2";

            _dataProvider.Initialise(_db);

            //Act
            var    folder = _db.GetItem(path);
            string xml    = Sitecore.Configuration.Factory.GetConfiguration().OuterXml;

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass2");
        }
Esempio n. 14
0
        public void GlassDataProvider_ReturnsTemplate()
        {
            //Assign

            var db      = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add <CodeFirstClass1>()
            .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
            .TemplateName("CodeFirstClass1")
            .CodeFirst();

            context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            var dataProvider = new GlassDataProvider("master", Context.DefaultContextName);

            dataProvider.Initialise(db);

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            InjectionDataProvider(master, dataProvider);


            //Act
            var folder = db.GetItem(path);


            string xml = Sitecore.Configuration.Factory.GetConfiguration().OuterXml;

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
        }
Esempio n. 15
0
        public void GlassDataProvider_TemplateInNamespace_ReturnsTemplate()
        {
            //Assign

            var db      = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add <CodeFirstClass2>()
            .TemplateId("E33F1C58-FAB2-475A-B2FE-C26F5D7565A2")
            .TemplateName("CodeFirstClass2")
            .CodeFirst();

            context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/GlassDataProvider/CodeFirstClass2";

            var dataProvider = new GlassDataProvider("master", Context.DefaultContextName);

            dataProvider.Initialise(db);

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            InjectionDataProvider(master, dataProvider);


            //Act
            var folder = db.GetItem(path);


            string xml = Sitecore.Configuration.Factory.GetConfiguration().OuterXml;

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass2");
        }
        public void GlassDataProvider_ReturnsTemplateWithSectionAndField_AllPropertiesSet()
        {
            //Assign

            var loader = new SitecoreFluentConfigurationLoader();

            var fieldId             = new ID("32FE1520-EAD4-4CF8-A69F-A4717E2F07F6");
            var sectionName         = "TestSection";
            var fieldSortOrder      = 123;
            var fieldName           = "FieldName";
            var fieldTitle          = "TestTitle";
            var fieldSource         = "/source";
            var fieldType           = SitecoreFieldType.Date;
            var sectionSortOrder    = 456;
            var validationErrorText = "TextValidation";
            var validationRegEx     = "testregex";

            loader.Add <CodeFirstClass1>()
            .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
            .TemplateName("CodeFirstClass1")
            .CodeFirst()
            .Fields(x =>
                    x.Field(y => y.Field1)
                    .IsCodeFirst()
                    .FieldId(fieldId.ToString())
                    .SectionName(sectionName)
                    .FieldSortOrder(fieldSortOrder)
                    .FieldName(fieldName)
                    .FieldSource(fieldSource)
                    .FieldTitle(fieldTitle)
                    .FieldType(fieldType)
                    .IsRequired()
                    .IsShared()
                    .IsUnversioned()
                    .SectionSortOrder(sectionSortOrder)
                    .ValidationErrorText(validationErrorText)
                    .ValidationRegularExpression(validationRegEx)
                    );

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
            var section = folder.Children.FirstOrDefault(x => x.Name == sectionName);

            Assert.IsNotNull(section);
            Assert.AreEqual(sectionSortOrder.ToString(), section[FieldIDs.Sortorder]);

            var field = section.Children.FirstOrDefault(x => x.Name == fieldName);

            Assert.IsNotNull(field);
            Assert.AreEqual(fieldSortOrder.ToString(), field[FieldIDs.Sortorder]);
            Assert.AreEqual(fieldId, field.ID);
            Assert.AreEqual(fieldSource, field[TemplateFieldIDs.Source]);
            Assert.AreEqual(fieldTitle, field[TemplateFieldIDs.Title]);
            Assert.AreEqual(fieldType.ToString(), field[TemplateFieldIDs.Type]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.ValidateButtonFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.WorkflowFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.ValidatorBarFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.QuickActionBarFieldId]);
            Assert.AreEqual("1", field[TemplateFieldIDs.Shared]);
            Assert.AreEqual("1", field[TemplateFieldIDs.Unversioned]);
            Assert.AreEqual(validationErrorText, field[TemplateFieldIDs.ValidationText]);
            Assert.AreEqual(validationRegEx, field[TemplateFieldIDs.Validation]);
        }
        public void GlassDataProvider_ReturnsTemplate()
        {
            //Assign

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass1>()
                  .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
                  .TemplateName("CodeFirstClass1")
                  .CodeFirst();

            context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            var dataProvider = new GlassDataProvider("master", Context.DefaultContextName);

            dataProvider.Initialise(db);

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            InjectionDataProvider(master, dataProvider);


            //Act
            var folder = db.GetItem(path);


            string xml = Sitecore.Configuration.Factory.GetConfiguration().OuterXml;
            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");

        }
Esempio n. 18
0
        public void BasicTemplate_LoadedByAttributeLoader()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            Map(loader);


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

            //Assert
            var basicTemplate = configs.First(x => x.Type == typeof(BasicTemplate));
            var subClass      = configs.First(x => x.Type == typeof(SubClass));

            Assert.IsNotNull(basicTemplate);
            Assert.IsNotNull(subClass);

            #region SitecoreId

            CheckProperty(basicTemplate, "Id", typeof(SitecoreIdConfiguration));

            #endregion
            #region Fields
            #region Simple Types

            CheckProperty(basicTemplate, "Checkbox", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Date", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DateTime", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "File", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Image", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Integer", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Float", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Double", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Decimal", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "MultiLineText", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Number", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Password", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "RichText", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "SingleLineText", typeof(SitecoreFieldConfiguration));

            #endregion
            #region List Types

            CheckProperty(basicTemplate, "CheckList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DropList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GroupedDropLink", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GroupedDropList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "MultiList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Treelist", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "TreeListEx", typeof(SitecoreFieldConfiguration));

            #endregion
            #region Link Types

            CheckProperty(basicTemplate, "DropLink", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DropTree", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GeneralLink", typeof(SitecoreFieldConfiguration));

            #endregion
            #region Developer Types

            CheckProperty(basicTemplate, "Icon", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "TriState", typeof(SitecoreFieldConfiguration));

            #endregion
            #region SystemType

            CheckProperty(basicTemplate, "Attachment", typeof(SitecoreFieldConfiguration));

            #endregion
            #endregion

            #region SitecoreInfo

            CheckProperty(basicTemplate, "ContentPath", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "DisplayName", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "FullPath", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Key", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "MediaUrl", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Path", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "TemplateId", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "TemplateName", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Url", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Version", typeof(SitecoreInfoConfiguration));

            #endregion

            #region SitecoreChildren

            CheckProperty(basicTemplate, "Children", typeof(SitecoreChildrenConfiguration));

            #endregion

            #region SitecoreParent

            CheckProperty(basicTemplate, "Parent", typeof(SitecoreParentConfiguration));

            #endregion

            #region SitecoreQuery

            CheckProperty(basicTemplate, "Query", typeof(SitecoreQueryConfiguration));

            #endregion
        }
Esempio n. 19
0
        public static void Map(SitecoreFluentConfigurationLoader loader)
        {
            var basic = new SitecoreClass<BasicTemplate>()
            .Fields(x =>
            {
                x.Field(y => y.Checkbox);
                x.Field(y => y.Date);
            })
            .Infos(x =>
            {
                x.Info(y => y.ContentPath).InfoType(SitecoreInfoType.ContentPath);
                x.Info(y => y.DisplayName).InfoType(SitecoreInfoType.DisplayName);
            })
            .Queries(x =>
            {
                x.Query(y => y.Query).Query("/sitecore/content/Configuration/Fluent/GeneralFluent/Query/*[@@TemplateName='BasicTemplate']");

            });


            basic.Id(x => x.Id);

            //basic.Field(x => x.Checkbox);
            //basic.Field(x => x.Date);
            basic.Field(x => x.DateTime);
            basic.Field(x => x.File);
            basic.Field(x => x.Image);
            basic.Field(x => x.Integer);
            basic.Field(x => x.Float);
            basic.Field(x => x.Double);
            basic.Field(x => x.Decimal);
            basic.Field(x => x.MultiLineText);
            basic.Field(x => x.Number);
            basic.Field(x => x.Password);
            basic.Field(x => x.RichText).Setting(SitecoreFieldSettings.RichTextRaw);
            basic.Field(x => x.SingleLineText);

            basic.Field(x => x.CheckList);
            basic.Field(x => x.DropList);
            basic.Field(x => x.GroupedDropLink);
            basic.Field(x => x.GroupedDropList);
            basic.Field(x => x.MultiList);
            basic.Field(x => x.Treelist);
            basic.Field(x => x.TreeListEx);

            basic.Field(x => x.DropLink);
            basic.Field(x => x.DropTree);
            basic.Field(x => x.GeneralLink);

            basic.Field(x => x.Icon);
            basic.Field(x => x.TriState);

            basic.Field(x => x.Attachment);


            basic.Info(x => x.FullPath).InfoType(SitecoreInfoType.FullPath);
            basic.Info(x => x.Key).InfoType(SitecoreInfoType.Key);
            basic.Info(x => x.MediaUrl).InfoType(SitecoreInfoType.MediaUrl);
            basic.Info(x => x.Path).InfoType(SitecoreInfoType.Path);
            basic.Info(x => x.TemplateId).InfoType(SitecoreInfoType.TemplateId);
            basic.Info(x => x.TemplateName).InfoType(SitecoreInfoType.TemplateName);
            basic.Info(x => x.Url).InfoType(SitecoreInfoType.Url);
            basic.Info(x => x.Version).InfoType(SitecoreInfoType.Version);

            basic.Children(x => x.Children);

            basic.Parent(x => x.Parent);


            var subClass = new SitecoreClass<SubClass>();
            subClass.Id(x => x.Id);

            loader.Add(subClass);
            loader.Add(basic);
        }
Esempio n. 20
0
        public void OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored()
        {
            //Assign
            string path = "/sitecore/content/Tests/Misc/FieldConfigOrder";
            string expected = "Hello space";


            var fluentConfig = new SitecoreFluentConfigurationLoader();

            var typeConfig = fluentConfig.Add<FieldOrderOnIgnore>();
            typeConfig.AutoMap();
            typeConfig.Field(x => x.ConfiguredTitle).FieldName("Title");
            typeConfig.Ignore(x => x.Title);

            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(fluentConfig);

            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            var item = db.GetItem(path);

            using (new ItemEditing(item, true))
            {
                item["Title"] = expected;
            }

            var scContext = new SitecoreContext(db);


            //Act
            var instance = scContext.GetItem<FieldOrderOnIgnore>(path);


            //Assert
            Assert.AreEqual(expected, instance.ConfiguredTitle);
            Assert.IsNullOrEmpty(instance.Title);
        }
Esempio n. 21
0
        public static void Map(SitecoreFluentConfigurationLoader loader)
        {
            var basic = new SitecoreClass <BasicTemplate>()
                        .Fields(x =>
            {
                x.Field(y => y.Checkbox);
                x.Field(y => y.Date);
            })
                        .Infos(x =>
            {
                x.Info(y => y.ContentPath).InfoType(SitecoreInfoType.ContentPath);
                x.Info(y => y.DisplayName).InfoType(SitecoreInfoType.DisplayName);
            })
                        .Queries(x =>
            {
                x.Query(y => y.Query).Query("/sitecore/content/Configuration/Fluent/GeneralFluent/Query/*[@@TemplateName='BasicTemplate']");
            });


            basic.Id(x => x.Id);

            //basic.Field(x => x.Checkbox);
            //basic.Field(x => x.Date);
            basic.Field(x => x.DateTime);
            basic.Field(x => x.File);
            basic.Field(x => x.Image);
            basic.Field(x => x.Integer);
            basic.Field(x => x.Float);
            basic.Field(x => x.Double);
            basic.Field(x => x.Decimal);
            basic.Field(x => x.MultiLineText);
            basic.Field(x => x.Number);
            basic.Field(x => x.Password);
            basic.Field(x => x.RichText).Setting(SitecoreFieldSettings.RichTextRaw);
            basic.Field(x => x.SingleLineText);

            basic.Field(x => x.CheckList);
            basic.Field(x => x.DropList);
            basic.Field(x => x.GroupedDropLink);
            basic.Field(x => x.GroupedDropList);
            basic.Field(x => x.MultiList);
            basic.Field(x => x.Treelist);
            basic.Field(x => x.TreeListEx);

            basic.Field(x => x.DropLink);
            basic.Field(x => x.DropTree);
            basic.Field(x => x.GeneralLink);

            basic.Field(x => x.Icon);
            basic.Field(x => x.TriState);

            basic.Field(x => x.Attachment);


            basic.Info(x => x.FullPath).InfoType(SitecoreInfoType.FullPath);
            basic.Info(x => x.Key).InfoType(SitecoreInfoType.Key);
            basic.Info(x => x.MediaUrl).InfoType(SitecoreInfoType.MediaUrl);
            basic.Info(x => x.Path).InfoType(SitecoreInfoType.Path);
            basic.Info(x => x.TemplateId).InfoType(SitecoreInfoType.TemplateId);
            basic.Info(x => x.TemplateName).InfoType(SitecoreInfoType.TemplateName);
            basic.Info(x => x.Url).InfoType(SitecoreInfoType.Url);
            basic.Info(x => x.Version).InfoType(SitecoreInfoType.Version);

            basic.Children(x => x.Children);

            basic.Parent(x => x.Parent);


            var subClass = new SitecoreClass <SubClass>();

            subClass.Id(x => x.Id);

            loader.Add(subClass);
            loader.Add(basic);
        }
Esempio n. 22
0
        public void BasicTemplate_LoadedByAttributeLoader()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();
            Map(loader);


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

            //Assert
            var basicTemplate = configs.First(x => x.Type == typeof(BasicTemplate));
            var subClass = configs.First(x => x.Type == typeof(SubClass));
            Assert.IsNotNull(basicTemplate);
            Assert.IsNotNull(subClass);

            #region SitecoreId

            CheckProperty(basicTemplate, "Id", typeof(SitecoreIdConfiguration));

            #endregion
            #region Fields
            #region Simple Types

            CheckProperty(basicTemplate, "Checkbox", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Date", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DateTime", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "File", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Image", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Integer", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Float", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Double", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Decimal", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "MultiLineText", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Number", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Password", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "RichText", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "SingleLineText", typeof(SitecoreFieldConfiguration));

            #endregion
            #region List Types

            CheckProperty(basicTemplate, "CheckList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DropList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GroupedDropLink", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GroupedDropList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "MultiList", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "Treelist", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "TreeListEx", typeof(SitecoreFieldConfiguration));

            #endregion
            #region Link Types

            CheckProperty(basicTemplate, "DropLink", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "DropTree", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "GeneralLink", typeof(SitecoreFieldConfiguration));

            #endregion
            #region Developer Types

            CheckProperty(basicTemplate, "Icon", typeof(SitecoreFieldConfiguration));
            CheckProperty(basicTemplate, "TriState", typeof(SitecoreFieldConfiguration));

            #endregion
            #region SystemType

            CheckProperty(basicTemplate, "Attachment", typeof(SitecoreFieldConfiguration));

            #endregion
            #endregion

            #region SitecoreInfo

            CheckProperty(basicTemplate, "ContentPath", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "DisplayName", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "FullPath", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Key", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "MediaUrl", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Path", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "TemplateId", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "TemplateName", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Url", typeof(SitecoreInfoConfiguration));
            CheckProperty(basicTemplate, "Version", typeof(SitecoreInfoConfiguration));

            #endregion

            #region SitecoreChildren

            CheckProperty(basicTemplate, "Children", typeof(SitecoreChildrenConfiguration));

            #endregion

            #region SitecoreParent

            CheckProperty(basicTemplate, "Parent", typeof(SitecoreParentConfiguration));

            #endregion

            #region SitecoreQuery

            CheckProperty(basicTemplate, "Query", typeof(SitecoreQueryConfiguration));

            #endregion
        }
        public void LazyLoading_LazyOnPrimaryDisabledButSecondaryEnabledGettingParent_ReturnsProxy()
        {
            //Arrange
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Parent") {
                    new Sitecore.FakeDb.DbItem("Target")
                    {
                        new Sitecore.FakeDb.DbItem("Child1"),
                    }
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());

                var fluent = new SitecoreFluentConfigurationLoader();
                var stub1Config = fluent.Add<Stub1>();
                stub1Config.Children(x => x.Stub3s).IsNotLazy();
                var stub2Config = fluent.Add<Stub2>();
                var stub3Config = fluent.Add<Stub3>();
                stub3Config.Parent(x => x.Stub2);


                context.Load(fluent);

                var service = new SitecoreService(database.Database, context);

                //Act
                var target = service.GetItem<Stub1>("/sitecore/content/parent/target");

                //Assert
                foreach (var child in target.Stub3s)
                {
                    Assert.IsTrue(child is Stub3);
                    Assert.AreEqual(typeof(Stub3), child.GetType());
                    Assert.IsTrue(child.Stub2 is Stub2);
                    Assert.AreNotEqual(typeof(Stub2), child.Stub2.GetType());
                }
            }
        }
        public void GlassDataProvider_ReturnsTemplateWithSectionAndField()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass1>()
                  .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
                  .TemplateName("CodeFirstClass1")
                  .CodeFirst()
                  .Fields(x =>
                          x.Field(y => y.Field1)
                           .IsCodeFirst()
                           .FieldId("32FE1520-EAD4-4CF8-A69F-A4717E2F07F6")
                           .SectionName("TestSection")
                );

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);
            
            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
            var section = folder.Children.FirstOrDefault(x => x.Name == "TestSection");
            Assert.IsNotNull(section);
            var field = section.Children.FirstOrDefault(x => x.Name == "Field1");
            Assert.IsNotNull(field);
             
        }
        public void GlassDataProvider_TemplateInNamespaceTwoDeep_ReturnsTemplate()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass3>()
                  .TemplateId("E33F1C58-FAB2-475A-B2FE-C26F5D7565A2")
                  .TemplateName("CodeFirstClass2")
                  .CodeFirst();

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/Level1/Level2/CodeFirstClass2";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);
            string xml = Factory.GetConfiguration().OuterXml;

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass2");

        }
        public void GlassDataProvider_ReturnsTemplateWithSectionAndField()
        {
            //Assign

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass1>()
                  .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
                  .TemplateName("CodeFirstClass1")
                  .CodeFirst()
                  .Fields(x =>
                          x.Field(y => y.Field1)
                           .IsCodeFirst()
                           .FieldId("32FE1520-EAD4-4CF8-A69F-A4717E2F07F6")
                           .SectionName("TestSection")
                );



            context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";



            var dataProvider = new GlassDataProvider("master", Context.DefaultContextName);

            dataProvider.Initialise(db);

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            InjectionDataProvider(master, dataProvider);


            //Act
            var folder = db.GetItem(path);
            
            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
            var section = folder.Children.FirstOrDefault(x => x.Name == "TestSection");
            Assert.IsNotNull(section);
            var field = section.Children.FirstOrDefault(x => x.Name == "Field1");
            Assert.IsNotNull(field);
             
        }
        public void GlassDataProvider_ReturnsTemplate()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass1>()
                  .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
                  .TemplateName("CodeFirstClass1")
                  .CodeFirst();

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");

        }
Esempio n. 28
0
        public void LazyLoadTest_LazyIsTrueAndServiceIsDisposed_ThrowsException()
        {
            //Assign
            var database = Factory.GetDatabase("master");

            var fluentConfig = new SitecoreFluentConfigurationLoader();

            var typeConfig = fluentConfig.Add<LazyLoadParent>();
            typeConfig.AutoMap();
            typeConfig.Children(x => x.Children);

            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(fluentConfig);

            var service = new SitecoreService(database, context);

            //Act
            var result = service.GetItem<LazyLoadParent>("/sitecore/content/Tests/DataMappers/SitecoreChildrenMapper/Parent");
            service.Dispose();

            //Assert

            Assert.AreEqual(3, result.Children.Count());

            foreach (var child in result.Children)
            {
                Assert.AreNotEqual(Guid.Empty, child.Id);
            }

        }
        public void GlassDataProvider_TemplateInNamespaceTwoDeep_ReturnsTemplateTwoTemplates()
        {
            //Assign
            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass3>()
                  .TemplateId("E33F1C58-FAB2-475A-B2FE-C26F5D7565A2")
                  .TemplateName("CodeFirstClass3")
                  .CodeFirst();

            loader.Add<CodeFirstClass4>()
                 .TemplateId("{42B45E08-20A4-434B-8AC7-ED8ABCE5B3BE}")
                 .TemplateName("CodeFirstClass4")
                 .CodeFirst();

            _context.Load(loader);

            var path1 = "/sitecore/templates/glasstemplates/Level1/Level2/CodeFirstClass3";
            var path2 = "/sitecore/templates/glasstemplates/Level1/Level2/CodeFirstClass4";

            _dataProvider.Initialise(_db);

            //Act
            var template1 = _db.GetItem(path1);
            var template2 = _db.GetItem(path2);

            //Assert
            Assert.AreEqual(template1.Name, "CodeFirstClass3");
            Assert.AreEqual(template2.Name, "CodeFirstClass4");

        }
        public void LazyLoadingWithCaching_LazyLoadingLoop_ThrowsException()
        {
            //Arrange
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Parent") {
                    new Sitecore.FakeDb.DbItem("Target")
                    {
                        new Sitecore.FakeDb.DbItem("Child1"),
                    }
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());

                var fluent = new SitecoreFluentConfigurationLoader();
                var stub4Config = fluent.Add<Stub4>();
                stub4Config.Parent(x => x.Stub5).IsNotLazy();
                stub4Config.Cachable();
                var stub5Config = fluent.Add<Stub5>();
                stub5Config.Children(x => x.Stub4s);

                context.Load(fluent);

                var service = new SitecoreService(database.Database, context);

                //Act
                Exception ex = Assert.Throws<MapperStackException>(() =>
                {
                    var target = service.GetItem<Stub4>("/sitecore/content/parent/target");
                });

                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Assert.IsTrue(ex.Message.StartsWith(Constants.Errors.ErrorLazyLoop.Replace("{0}","")));
                //Assert

            }
        }
        public void GlassDataProvider_ReturnsTemplateWithSectionAndField_AllPropertiesSet()
        {
            //Assign

            var loader = new SitecoreFluentConfigurationLoader();

            var fieldId = new ID("32FE1520-EAD4-4CF8-A69F-A4717E2F07F6");
            var sectionName = "TestSection";
            var fieldSortOrder = 123;
            var fieldName = "FieldName";
            var fieldTitle = "TestTitle";
            var fieldSource = "/source";
            var fieldType = SitecoreFieldType.Date;
            var sectionSortOrder = 100;
            var validationErrorText = "TextValidation";
            var validationRegEx = "testregex";

            loader.Add<CodeFirstClass1>()
                  .TemplateId("D3595652-AC29-4BD4-A8D7-DD2120EE6460")
                  .TemplateName("CodeFirstClass1")
                  .CodeFirst()
                  .Fields(x =>
                          x.Field(y => y.Field1)
                           .IsCodeFirst()
                           .FieldId(fieldId.ToString())
                           .SectionName(sectionName)
                           .FieldSortOrder(fieldSortOrder)
                           .FieldName(fieldName)
                           .FieldSource(fieldSource)
                           .FieldTitle(fieldTitle)
                           .FieldType(fieldType)
                           .IsRequired()
                           .IsShared()
                           .IsUnversioned()
                           .SectionSortOrder(sectionSortOrder)
                           .ValidationErrorText(validationErrorText)
                           .ValidationRegularExpression(validationRegEx)
                );

            _context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/CodeFirstClass1";

            _dataProvider.Initialise(_db);

            //Act
            var folder = _db.GetItem(path);

            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass1");
            var section = folder.Children.FirstOrDefault(x => x.Name == sectionName);
            Assert.IsNotNull(section);
            Assert.AreEqual(sectionSortOrder.ToString(), section[FieldIDs.Sortorder]); 

            var field = section.Children.FirstOrDefault(x => x.Name == fieldName);
            Assert.IsNotNull(field);
            Assert.AreEqual(fieldSortOrder.ToString(), field[FieldIDs.Sortorder]); 
            Assert.AreEqual(fieldId, field.ID);
            Assert.AreEqual(fieldSource, field[TemplateFieldIDs.Source]);
            Assert.AreEqual(fieldTitle, field[TemplateFieldIDs.Title]);
            Assert.AreEqual(fieldType.ToString(), field[TemplateFieldIDs.Type]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.ValidateButtonFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.WorkflowFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.ValidatorBarFieldId]);
            Assert.AreEqual(Global.IDs.TemplateFieldIds.IsRequiredId, field[Global.IDs.TemplateFieldIds.QuickActionBarFieldId]);
            Assert.AreEqual("1", field[TemplateFieldIDs.Shared]);
            Assert.AreEqual("1", field[TemplateFieldIDs.Unversioned]);
            Assert.AreEqual(validationErrorText, field[TemplateFieldIDs.ValidationText]);
            Assert.AreEqual(validationRegEx, field[TemplateFieldIDs.Validation]);
        }
 public static SitecoreFluentConfigurationLoader LoadGlassMapperModels(SitecoreFluentConfigurationLoader fluentLoader)
 {
     fluentLoader.Add(TripleM.Feature.SearchUI.Models.SearchUI.Load());
     return(fluentLoader);
 }
Esempio n. 33
0
        public void ItemWithTwoNamedFieldsTheSame_UsingIds_ReturnsFirstField()
        {
            //Arrange

            var templateId = ID.NewID;
            var fieldId11  = ID.NewID;
            var filedId12  = ID.NewID;
            var fieldName  = "Field1";

            using (Db db = new Db()
            {
                new DbTemplate("Base", templateId)
                {
                    new DbField(fieldName, fieldId11)
                    {
                        Type = SitecoreFieldStringMapper.RichTextKey
                    },
                    new DbField(fieldName, filedId12)
                    {
                        Type = SitecoreFieldStringMapper.RichTextKey
                    }
                },

                new DbItem("Target", ID.NewID, templateId)
                {
                    { fieldId11, "Field 1 content" },
                    { filedId12, "Field 2 content" }
                }
            })
            {
                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 GlassHtmlFixture.SiteContextStub(
                    new SiteInfo(
                        doc.FirstChild
                        )
                    );

                siteContext.SetDisplayMode(DisplayMode.Normal);

                Sitecore.Context.Site = siteContext;

                var loader = new SitecoreFluentConfigurationLoader();
                var stub   = loader.Add <StubClass>();
                stub.Field(x => x.Test1).FieldId(fieldId11);
                stub.Field(x => x.Test2).FieldId(filedId12);


                var resolver = Utilities.CreateStandardResolver();
                resolver.DataMapperFactory.Insert(0, () => new Issue145.Issue145.StubDataMapper());

                var context = Context.Create(resolver);

                context.Load(loader);

                var service = new SitecoreService(db.Database, context);

                //Act
                var result = service.GetItem <StubClass>("/sitecore/content/Target");

                //Assert
                Assert.AreEqual("Field 1 content", result.Test1);
                Assert.AreEqual("Field 2 content", result.Test2);
            }
        }
        public void GlassDataProvider_TemplateInNamespace_ReturnsTemplate()
        {
            //Assign

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());

            var loader = new SitecoreFluentConfigurationLoader();

            loader.Add<CodeFirstClass2>()
                  .TemplateId("E33F1C58-FAB2-475A-B2FE-C26F5D7565A2")
                  .TemplateName("CodeFirstClass2")
                  .CodeFirst();

            context.Load(loader);

            var path = "/sitecore/templates/glasstemplates/GlassDataProvider/CodeFirstClass2";

            var dataProvider = new GlassDataProvider("master", Context.DefaultContextName);

            dataProvider.Initialise(db);

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            InjectionDataProvider(master, dataProvider);


            //Act
            var folder = db.GetItem(path);


            string xml = Sitecore.Configuration.Factory.GetConfiguration().OuterXml;
            //Assert
            Assert.AreEqual(folder.Name, "CodeFirstClass2");

        }