当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.GetLink方法代码示例

本文整理汇总了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()));
 }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:6,代码来源:UrlHelperExtensionsTests.cs

示例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);
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:37,代码来源:UrlHelperExtensionsTests.cs

示例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));
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:13,代码来源:UrlHelperExtensionsTests.cs

示例4: GetLinkThrowsExceptionForNullExpression

 public void GetLinkThrowsExceptionForNullExpression(
     [Frozen]HttpRequestMessage request,
     RouteLinker forComparison,
     UrlHelper sut)
 {
     request.AddDefaultRoute();
     Assert.Throws(typeof(ArgumentNullException), () => sut.GetLink<FooController>(null));
 }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:8,代码来源:UrlHelperExtensionsTests.cs

示例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);
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:12,代码来源:UrlHelperExtensionsTests.cs

示例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);
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:12,代码来源:UrlHelperExtensionsTests.cs

示例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);
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:12,代码来源:UrlHelperExtensionsTests.cs

示例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);
        }
开发者ID:suvroc,项目名称:Hyprlinkr,代码行数:12,代码来源:UrlHelperExtensionsTests.cs


注:本文中的System.Web.Http.Routing.UrlHelper.GetLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。