Exemplo n.º 1
0
        public void RenderImage_MatchesSitecoreOutput_Issue133()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/Target";

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
            var service = new SitecoreContext(db);

            var html = new GlassHtml(service);


            string fieldValue= "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

            var item = db.GetItem(targetPath);
            var field = item.Fields["Image"];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            var model = service.GetItem<StubClassWithImage>(targetPath);


            var scControl = new Sitecore.Web.UI.WebControls.Image();
            scControl.Item = item;
            scControl.Field = "Image";
            scControl.Parameters = "mw=200";
           
            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 SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Normal);

            Sitecore.Context.Site = siteContext;

            StringBuilder sb = new StringBuilder();
            HtmlTextWriter writer  = new HtmlTextWriter(new StringWriter(sb));
            //Act
            scControl.RenderControl(writer);
            var scResult = sb.ToString();
            var result = html.RenderImage(model, x => x.Image, new {mw=200});

            //Assert
            Assert.AreEqual(result,scResult);




        }
Exemplo n.º 2
0
        public void RenderImage_MatchesSitecoreOutput_Issue133()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/Target";

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

            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
            var service = new SitecoreContext(db);

            var html = new GlassHtml(service);


            string fieldValue = "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

            var item  = db.GetItem(targetPath);
            var field = item.Fields["Image"];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            var model = service.GetItem <StubClassWithImage>(targetPath);


            var scControl = new Sitecore.Web.UI.WebControls.Image();

            scControl.Item       = item;
            scControl.Field      = "Image";
            scControl.Parameters = "mw=200";

            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 SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Normal);

            Sitecore.Context.Site = siteContext;

            StringBuilder  sb     = new StringBuilder();
            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));

            //Act
            scControl.RenderControl(writer);
            var scResult = sb.ToString();
            var result   = html.RenderImage(model, x => x.Image, new { mw = 200 });

            //Assert
            Assert.AreEqual(result, scResult);
        }
        public void RenderImage_MatchesSitecoreOutput_Issue133_Test3()
        {
            //Assign
            string targetPath = "/sitecore/content/target";
            var mediaID = new ID("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}");

            var templateId = ID.NewID;
            using (Db database = new Db
            {
                new DbTemplate("MediaTemplate", templateId)
                {
                    new DbField("Image")
                    {
                        Type = "image"
                    }
                },
                new Sitecore.FakeDb.DbItem("Target", new ID(), templateId)
                {
                    {"Image", ""}
                },
                new Sitecore.FakeDb.DbItem("media", mediaID)
                {
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreContext(database.Database);
                var html = GetGlassHtml(service);

                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    NSubstitute.Substitute.For<Sitecore.Resources.Media.MediaProvider>();

                mediaProvider
                    .GetMediaUrl(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaID))
                    .Returns("/myimage");

                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {


                    string fieldValue =
                        "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

                    var item = database.GetItem(targetPath);
                    var field = item.Fields["Image"];

                    using (new ItemEditing(item, true))
                    {
                        field.Value = fieldValue;
                    }

                    var model = service.GetItem<StubClassWithImage>(targetPath);


                    var scControl = new Sitecore.Web.UI.WebControls.Image();
                    scControl.Item = item;
                    scControl.Field = "Image";
                    scControl.Parameters = "width=200&as=true";

                    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 SiteContextStub(
                        new SiteInfo(
                            doc.FirstChild
                            )
                        );

                    siteContext.SetDisplayMode(DisplayMode.Normal);

                    Sitecore.Context.Site = siteContext;

                    StringBuilder sb = new StringBuilder();
                    HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));
                    //Act
                    scControl.RenderControl(writer);
                    var scResult = sb.ToString();
                    var result = html.RenderImage(model, x => x.Image, new { width = 200 });

                    //Assert
                    Assert.AreEqual(result, scResult);
                }

            }
        }