本文整理汇总了C#中System.Web.Mvc.UrlHelper.CurrentUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.CurrentUrl方法的具体用法?C# UrlHelper.CurrentUrl怎么用?C# UrlHelper.CurrentUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.CurrentUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CurrentUrlAndCurrentAbsoluteUrl_UrlHelperRequestContextIsNull_ThrowsException
public void CurrentUrlAndCurrentAbsoluteUrl_UrlHelperRequestContextIsNull_ThrowsException()
{
var urlHelper = new UrlHelper();
// It is not possible to set UrlHelper.RequestContext to null and at the same time to have RouteCollection being not null.
// Therefor this little trick to pass the null check for the urlHelper.RouteCollection.
urlHelper.GetType().GetProperty("RouteCollection").GetSetMethod(true).Invoke(urlHelper, new object[] { new RouteCollection() });
Assert.That(urlHelper.RouteCollection, Is.Not.Null);
var parameterName = Assert.Throws<ArgumentNullException>(() => urlHelper.CurrentUrl(new Func<object, object>[0])).ParamName;
Assert.That(parameterName, Is.EqualTo("urlHelper.RequestContext"));
parameterName = Assert.Throws<ArgumentNullException>(() => urlHelper.CurrentAbsoluteUrl(Protocol.Http, new Func<object, object>[0])).ParamName;
Assert.That(parameterName, Is.EqualTo("urlHelper.RequestContext"));
}
示例2: CurrentUrlAndCurrentAbsoluteUrl_NewRouteAndQueryStringParametersIsNull_ThrowsException
public void CurrentUrlAndCurrentAbsoluteUrl_NewRouteAndQueryStringParametersIsNull_ThrowsException()
{
var urlHelper = new UrlHelper(new RequestContext(), new RouteCollection());
var parameterName = Assert.Throws<ArgumentNullException>(() => urlHelper.CurrentUrl(null)).ParamName;
Assert.That(parameterName, Is.EqualTo("newRouteAndQueryStringParameters"));
parameterName = Assert.Throws<ArgumentNullException>(() => urlHelper.CurrentAbsoluteUrl(Protocol.Http, null)).ParamName;
Assert.That(parameterName, Is.EqualTo("newRouteAndQueryStringParameters"));
}