本文整理汇总了C#中System.Web.Mvc.HtmlHelper.Image方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.Image方法的具体用法?C# HtmlHelper.Image怎么用?C# HtmlHelper.Image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.Image方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HtmlHelperExtensionsImageAbsoultePathAndClassTest
public void HtmlHelperExtensionsImageAbsoultePathAndClassTest()
{
// Przekazany url
const string Url = "test.com/someimg.jpg";
// Oczekiwany tag html
var expected =
new MvcHtmlString(
"<img alt=\"" + AlternateText + "\" class=\"" + Class + "\" id=\"" + Id + "\" src=\"" + Url
+ "\" />");
// stworzenie instancji HtmlHelper
var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());
// Wykonanie helpera Image
var tag = htmlHelper.Image(Id, Url, AlternateText, new { @class = Class });
// Sprawdzenie
Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
}
示例2: HtmlHelperExtensionsImageRelativePathTest
public void HtmlHelperExtensionsImageRelativePathTest()
{
// Przekazany url
const string Url = "~/someimg.jpg";
// Oczekiwany url
const string ExpectedUrl = "/app/someimg.jpg";
// Oczekiwany tag html
var expected =
new MvcHtmlString("<img alt=\"" + AlternateText + "\" id=\"" + Id + "\" src=\"" + ExpectedUrl + "\" />");
// stworzenie instancji HtmlHelper
var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());
// Mokowanie HttpContextBase
var fakeHttpContext = Substitute.ForPartsOf<HttpContextBase>();
// Ustawienie właściwośći readonly Request
// ReSharper disable once UnusedVariable
fakeHttpContext.When(x => { var get = x.Request; }).DoNotCallBase();
fakeHttpContext.Request.Returns(Substitute.ForPartsOf<HttpRequestBase>());
// Ustawienie właściwośći readonly ApplicaitonPath
// ReSharper disable once UnusedVariable
fakeHttpContext.Request.When(x => { var get = x.ApplicationPath; }).DoNotCallBase();
fakeHttpContext.Request.ApplicationPath.Returns("/app/");
// Podststawienie i wykonanie helpera Image
htmlHelper.ViewContext.HttpContext = fakeHttpContext;
var tag = htmlHelper.Image(Id, Url, AlternateText);
// Sprawdzenie
Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
}