本文整理汇总了C#中System.Web.Http.Routing.UrlHelper.GetLink方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.GetLink方法的具体用法?C# UrlHelper.GetLink怎么用?C# UrlHelper.GetLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Routing.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.GetLink方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLinkForNoRouteDataThrows
public void GetLinkForNoRouteDataThrows([Frozen]HttpRequestMessage request,
UrlHelper sut)
{
request.RequestUri = new Uri(request.RequestUri, "api/foo/");
Assert.Throws<InvalidOperationException>(() => sut.GetLink<FooController>(r => r.GetDefault()));
}
示例2: GetLinkWithCustomRouteAndDispatcherReturnsCorrectResult
public void GetLinkWithCustomRouteAndDispatcherReturnsCorrectResult(
[Frozen]HttpRequestMessage request,
[Frozen(As = typeof(IRouteValuesQuery))]ScalarRouteValuesQuery dummyQuery,
[Frozen]Mock<IRouteDispatcher> dispatcherStub,
string routeName,
[Greedy]RouteLinker forComparison,
UrlHelper sut,
int ploeh,
string fnaah)
{
// Arrange
request.AddDefaultRoute();
request.AddRoute(
name: routeName,
routeTemplate: "foo/{ploeh}/{fnaah}",
defaults: new { });
var method = Reflect<FooController>
.GetMethod(c => c.GetWithPloehAndFnaah(ploeh, fnaah));
dispatcherStub
.Setup(d =>
d.Dispatch(
It.Is<MethodCallExpression>(exp => method.Equals(exp.Method)),
It.IsAny<IDictionary<string, object>>()))
.Returns((MethodCallExpression _, IDictionary<string, object> routeValues) =>
new Rouple(routeName, routeValues));
var expected = forComparison.GetUri<FooController>(r =>
r.GetWithPloehAndFnaah(ploeh, fnaah));
// Act
var actual = sut.GetLink<FooController>(r =>
r.GetWithPloehAndFnaah(ploeh, fnaah), dispatcherStub.Object);
//Assert
Assert.Equal(expected, actual);
}
示例3: GetLinkDoesNotMutateExistingRouteData
public void GetLinkDoesNotMutateExistingRouteData(
[Frozen]HttpRequestMessage request,
UrlHelper sut)
{
request.AddDefaultRoute();
var expected = new HashSet<KeyValuePair<string, object>>(
request.GetRouteData().Values);
sut.GetLink<FooController>(r => r.GetDefault());
var actual = request.GetRouteData().Values.ToList();
Assert.True(expected.SetEquals(actual));
}
示例4: GetLinkThrowsExceptionForNullExpression
public void GetLinkThrowsExceptionForNullExpression(
[Frozen]HttpRequestMessage request,
RouteLinker forComparison,
UrlHelper sut)
{
request.AddDefaultRoute();
Assert.Throws(typeof(ArgumentNullException), () => sut.GetLink<FooController>(null));
}
示例5: GetLinkReturnsCorrectUriForExpressionOfFuncWithSingleParameter
public void GetLinkReturnsCorrectUriForExpressionOfFuncWithSingleParameter(
[Frozen]HttpRequestMessage request,
RouteLinker forComparison,
UrlHelper sut, int id)
{
request.AddDefaultRoute();
var expected = forComparison.GetUri<FooController>(a => a.GetById(id));
var actual = sut.GetLink<FooController>(a => a.GetById(id));
Assert.Equal(expected, actual);
}
示例6: GetLinkReturnsCorrectUriForExpressionOfFuncWithComplexParameter
public void GetLinkReturnsCorrectUriForExpressionOfFuncWithComplexParameter(
[Frozen]HttpRequestMessage request,
RouteLinker forComparison,
UrlHelper sut, SomeModel someModel)
{
request.AddDefaultRoute();
var expected = forComparison.GetUri<ModelController, object>(a => a.Get(someModel));
var actual = sut.GetLink<ModelController, object>(a => a.Get(someModel));
Assert.Equal(expected, actual);
}
示例7: GetLinkReturnsCorrectUriForExpressionOfActionWithMultipleParameters
public void GetLinkReturnsCorrectUriForExpressionOfActionWithMultipleParameters(
[Frozen]HttpRequestMessage request,
RouteLinker forComparison,
UrlHelper sut, int id, int bar)
{
request.AddDefaultRoute();
var expected = forComparison.GetUri<FooBarController>(a => a.GetBar(id, bar));
var actual = sut.GetLink<FooBarController>(a => a.GetBar(id, bar));
Assert.Equal(expected, actual);
}
示例8: GetLinkFromBaseActionMethodReturnsCorrectResponse
public void GetLinkFromBaseActionMethodReturnsCorrectResponse(
[Frozen]HttpRequestMessage request,
RouteLinker forComparison,
UrlHelper sut)
{
request.AddDefaultRoute();
var expected = forComparison.GetUri<DerivedController>(c => c.BaseMethod());
var actual = sut.GetLink<DerivedController>(c => c.BaseMethod());
Assert.Equal(expected, actual);
}