本文整理汇总了C#中GlassHtml.RenderImage方法的典型用法代码示例。如果您正苦于以下问题:C# GlassHtml.RenderImage方法的具体用法?C# GlassHtml.RenderImage怎么用?C# GlassHtml.RenderImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlassHtml
的用法示例。
在下文中一共展示了GlassHtml.RenderImage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderImage_AlternativeQuotationMarks_RendersCorrectHtml
public void RenderImage_AlternativeQuotationMarks_RendersCorrectHtml()
{
//Arrange
var expected = "<img src=\"~/media/Images/Carousel/carousel-example.ashx?h=126&w=240\" alt=\"someAlt\" width=\"380\" />";
var scContext = Substitute.For<ISitecoreContext>();
scContext.Config = new Config();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var parameters = new { Width = 380, W = 240 };
var model = new { Image = image };
GlassHtml.QuotationMark = "\"";
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, true);
//Assert
Assert.AreEqual(expected, result);
//reset GlassHtml
GlassHtml.QuotationMark = "'";
}
示例2: RenderImage_ValidImageWithParametersWidth_RendersCorrectHtmlNoWidthHeight
public void RenderImage_ValidImageWithParametersWidth_RendersCorrectHtmlNoWidthHeight()
{ //Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=126&w=240' alt='someAlt' />";
var scContext = Substitute.For<ISitecoreContext>();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var parameters = new { Width = 380, W = 240 };
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, false);
//Assert
Assert.AreEqual(expected, result);
}
示例3: RenderImage_RendersImageWithAttributes
public void RenderImage_RendersImageWithAttributes()
{
GlassHtml html = new GlassHtml("master");
//Assign
FieldTypes.Image img = new FieldTypes.Image();
img.Alt = "Some alt test";
img.Src = "/cats.jpg";
img.Class = "classy";
NameValueCollection attrs = new NameValueCollection();
attrs.Add("style", "allStyle");
//Act
var result = html.RenderImage(img, attrs);
//Assert
Assert.AreEqual("<img src='/cats.jpg' style='allStyle' class='classy' alt='Some alt test' />", result);
}
示例4: RenderImage_ValidImageWithWidthAndStretcj_RendersCorrectHtml
public void RenderImage_ValidImageWithWidthAndStretcj_RendersCorrectHtml()
{
//Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?w=900&as=True' alt='someAlt' width='900' />";
var scContext = Substitute.For<ISitecoreContext>();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var parameters = new ImageParameters { Width = 900, AllowStretch = true};
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true);
//Assert
Assert.AreEqual(expected, result);
}
示例5: RenderImage_ValidImageWithBorderHSpaceVSpace_RendersCorrectHtml
public void RenderImage_ValidImageWithBorderHSpaceVSpace_RendersCorrectHtml()
{
//Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx' alt='someAlt' border='9' hspace='10' vspace='15' />";
var scContext = Substitute.For<ISitecoreContext>();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.HSpace = 10;
image.VSpace = 15;
image.Border = "9";
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, null, true);
//Assert
Assert.AreEqual(expected, result);
}
示例6: RenderImage_MatchesSitecoreOutput_Issue133_Test3
public void RenderImage_MatchesSitecoreOutput_Issue133_Test3()
{
//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 = "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);
}
示例7: RenderImage_RemoveHeightWidthAttributes_RendersCorrectHtml
public void RenderImage_RemoveHeightWidthAttributes_RendersCorrectHtml()
{
//Arrange
var expected =
"<img src='~/media/Images/Carousel/carousel-example.ashx?h=210&w=400' vspace='15' hspace='10' border='9' alt='someAlt' />";
var scContext = Substitute.For<ISitecoreContext>();
scContext.Config = new Config();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.HSpace = 10;
image.VSpace = 15;
image.Border = "9";
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var model = new { Image = image };
var parameters = new { w = 400 };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, false);
//Assert
Assert.AreEqual(expected, result);
}
示例8: RenderImage_ValidImageWithLanguageParameterOverride_RendersCorrectHtmlWithParameterLanguage
public void RenderImage_ValidImageWithLanguageParameterOverride_RendersCorrectHtmlWithParameterLanguage()
{
//Arrange
var expected =
"<img src='~/media/Images/Carousel/carousel-example.ashx?h=210&la=en&w=400' width='200' vspace='15' height='105' hspace='10' border='9' alt='someAlt' />";
var scContext = Substitute.For<ISitecoreContext>();
scContext.Config = new Config();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.HSpace = 10;
image.VSpace = 15;
image.Border = "9";
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
image.Language = LanguageManager.GetLanguage("af-ZA");
var model = new { Image = image };
var parameters = new { w = 400, la="en" };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, true);
//Assert
Assert.AreEqual(expected, result);
}
示例9: RenderImage_ValidImageWithClass_RendersCorrectHtml
public void RenderImage_ValidImageWithClass_RendersCorrectHtml()
{
//Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=105&w=200' alt='someAlt' height='105' class='AClass' width='200' />";
var scContext = Substitute.For<ISitecoreContext>();
scContext.Config = new Config();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.Class = "AClass";
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, null, true, true);
//Assert
Assert.AreEqual(expected, result);
}
示例10: RenderImage_MaxWidthWhereWidthIsBelowMaxWidth_RendersCorrectHtml
public void RenderImage_MaxWidthWhereWidthIsBelowMaxWidth_RendersCorrectHtml()
{
//Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?mw=300&h=105&as=True&w=200' alt='someAlt' />";
var scContext = Substitute.For<ISitecoreContext>();
scContext.Config = new Config();
var html = new GlassHtml(scContext);
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 105;
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var parameters = new { mw = 300, As = true };
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, false);
//Assert
Assert.AreEqual(expected, result);
}
示例11: RenderImage_ValidImageWithParametersHeight_RendersCorrectHtml
public void RenderImage_ValidImageWithParametersHeight_RendersCorrectHtml()
{
//Arrange
var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=450&w=600' alt='someAlt' height='450' />";
var scContext = Substitute.For<ISitecoreContext>();
var html = new GlassHtml(scContext);
scContext.Config = new Config();
var image = new Fields.Image();
image.Alt = "someAlt";
image.Width = 200;
image.Height = 150;
image.Src = "~/media/Images/Carousel/carousel-example.ashx";
var parameters = new { Height = 450, H=450};
var model = new { Image = image };
//Act
var result = html.RenderImage(model, x => x.Image, parameters, true, true);
//Assert
Assert.AreEqual(expected, result);
}