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


C# Routing.HttpRouteData类代码示例

本文整理汇总了C#中System.Web.Http.Routing.HttpRouteData的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteData类的具体用法?C# HttpRouteData怎么用?C# HttpRouteData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRouteData类属于System.Web.Http.Routing命名空间,在下文中一共展示了HttpRouteData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post_Legg_til_prosjekt_Bad_Request

 public void Post_Legg_til_prosjekt_Bad_Request()
 {
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjekt(It.IsAny<Prosjekt>(), It.IsAny<string>())).Returns(true);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "ProsjektApi" } });
     var controller = new ProsjektApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var pros = new Prosjekt();
     pros.Arbeidsplass = "";
     // The ASP.NET pipeline doesn't run, so validation don't run. 
     controller.ModelState.AddModelError("Arbeidsplass", "mock error message");
     var response = controller.Post(pros);
     // Assert
     Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
 }
开发者ID:matslo,项目名称:Jobbplan,代码行数:29,代码来源:ProsjektApiControllerTest.cs

示例2: Post_Bruker_Bad_request

        public void Post_Bruker_Bad_request()
        {

            var commandBus = new Mock<IBrukerLogikk>();
            commandBus.Setup(c => c.RegistrerBruker(It.IsAny<Registrer>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
            var controller = new BrukerApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/BrukerApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            Registrer nyBruker = new Registrer();
            nyBruker.Email = "";
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            controller.ModelState.AddModelError("Email", "mock error message");
            var response = controller.Post(nyBruker);
            // Assert
            commandBus.Verify(e => e.RegistrerBruker(nyBruker), Times.Never);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            // Act

        }
开发者ID:matslo,项目名称:Jobbplan,代码行数:32,代码来源:BrukerApiControllerTest.cs

示例3: GetSlotPageById_WithSlotHavingAnImage_ReturnedSlotHasImageUrl

        public void GetSlotPageById_WithSlotHavingAnImage_ReturnedSlotHasImageUrl()
        {
            //Arrange
            HttpConfiguration config = new HttpConfiguration();
            var route = config.Routes.MapHttpRoute
            (
               name: "GetMediaContentById",
               routeTemplate: "mediacontent/{id}"
            );

            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "id", "1" } });

            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, "http://localhost:80/slotpage/1");
            req.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, config);
            req.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData);

            _urlHelper = new TWG.EASDataService.Api.Helpers.UrlHelper(new System.Web.Http.Routing.UrlHelper(req));
            _objectUnderTest = new SlotController(_slotService, _urlHelper);
            _objectUnderTest.Request = req;

            var slot = new Slot() { Id = 1, Headline = "test slot", Image = new Image() { Name = "dummy image", Id = 1000, Extension = "jpg" } };
            SlotPage sp = new SlotPage() { Id = 1, PageName = "Test", Slots = { slot } };
            _slotRepository.Stub(r => r.GetSlotPageById(Arg<int>.Is.Anything)).Return(sp);

            //Act
            var result = _objectUnderTest.GetSlotPageById(1);

            //Assert
            Image img = result.Slots.FirstOrDefault().Image;
            Assert.AreNotEqual(string.Empty,img.Url);
        }
开发者ID:tvsuneeth,项目名称:easds,代码行数:31,代码来源:SlotControllerTests.cs

示例4: SelectAction_WithDirectRoutes_RespectsRouteOrder

        public void SelectAction_WithDirectRoutes_RespectsRouteOrder()
        {
            // Arrange
            var actionSelector = new ApiControllerActionSelector();
            HttpControllerContext context = ContextUtil.CreateControllerContext();
            context.Request = new HttpRequestMessage { Method = HttpMethod.Get };
            var controllerDescriptor = new HttpControllerDescriptor(context.Configuration, "MultipleGet", typeof(MultipleGetController));
            context.ControllerDescriptor = controllerDescriptor;
            ReflectedHttpActionDescriptor firstDirectRouteAction = (ReflectedHttpActionDescriptor)actionSelector.GetActionMapping(controllerDescriptor)["GetA"].Single();
            HttpRouteData[] subRouteData = new HttpRouteData[2];
            subRouteData[0] = new HttpRouteData(new HttpRoute());
            subRouteData[1] = new HttpRouteData(new HttpRoute());
            context.RouteData.Values.Add(RouteCollectionRoute.SubRouteDataKey, subRouteData);
            subRouteData[0].Route.DataTokens.Add("actions", new ReflectedHttpActionDescriptor[] { firstDirectRouteAction });
            subRouteData[0].Route.DataTokens.Add("order", 1);
            ReflectedHttpActionDescriptor secondDirectRouteAction = (ReflectedHttpActionDescriptor)actionSelector.GetActionMapping(controllerDescriptor)["GetB"].Single();
            subRouteData[1].Route.DataTokens.Add("actions", new ReflectedHttpActionDescriptor[] { secondDirectRouteAction });
            subRouteData[1].Route.DataTokens.Add("order", 2);

            // Act
            HttpActionDescriptor actionDescriptor = actionSelector.SelectAction(context);

            // Assert
            Assert.Same(secondDirectRouteAction, actionDescriptor);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:25,代码来源:ApiControllerActionSelectorTest.cs

示例5: Post_Bruker_Ok

 public void Post_Bruker_Ok()
 {
     Registrer nyBruker = new Registrer()
     {
         Fornavn = "Mats",
         Etternavn = "Lokken",
         Email = "[email protected]",
         Telefonnummer = "93686771",
         BekreftPassord = "password"
     };
     var commandBus = new Mock<IBrukerLogikk>();
     commandBus.Setup(c => c.RegistrerBruker(It.IsAny<Registrer>())).Returns(true);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
     var controller = new BrukerApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/BrukerApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyBruker);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
     Assert.AreEqual(string.Format("http://localhost/api/BrukerApi/{0}", nyBruker.id), response.Headers.Location.ToString());
 }
开发者ID:matslo,项目名称:Jobbplan,代码行数:35,代码来源:BrukerApiControllerTest.cs

示例6: PostData_SendInvalidJson_BadRequest

        public async Task PostData_SendInvalidJson_BadRequest()
        {
            try
            {
                var config = new HttpConfiguration();
                var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
                var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "RequestData" } });

                var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/");
                request.Content = new StringContent(invalidRequestJson, Encoding.UTF8, "application/json");
                request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

                RequestDataController controller = new RequestDataController();

                controller.ControllerContext = new HttpControllerContext(config, routeData, request);
                controller.Request = request;
                controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

                // Act
                var response = await controller.PostData(request);
                //var jsonString = await response.Content.ReadAsStringAsync();

                // Assert
                Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            }
            catch (Exception ex)
            {

                Assert.Fail(ex.Message);
            }
        }
开发者ID:whitebaek,项目名称:MyJsonParser,代码行数:31,代码来源:RequestDataControllerTests.cs

示例7: Post_HttpStatus_should_be_created_and_header_should_contains_the_location

        public void Post_HttpStatus_should_be_created_and_header_should_contains_the_location()
        {
            Mock<IPostRepository> repository = new Mock<IPostRepository>();

            PostsController controller = new PostsController(repository.Object);

            HttpConfiguration config = new HttpConfiguration();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/");
            IHttpRoute route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            HttpRouteData routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "posts" } });
            controller.ControllerContext = new HttpControllerContext(config, routeData, request);
            controller.Request = request;
            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            controller.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;

            HttpResponseMessage response = controller.Post(new Post()
                                                               {
                                                                   Title = "test",
                                                                   Date = DateTime.Today,
                                                                   Body = "blablabla"
                                                               });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(response.Headers.Location);
        }
开发者ID:emadb,项目名称:WebApiSamples,代码行数:25,代码来源:PostsControllerTests.cs

示例8: Post_MAl_Bad_request_Modelstate

        [TestMethod] public void Post_MAl_Bad_request_Modelstate()
        {

            var commandBus = new Mock<IVaktLogikk>();
            commandBus.Setup(c => c.RegistrerMal(It.IsAny<MalerSkjema>(),It.IsAny<string>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
            var controller = new MalerController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Maler/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            MalerSkjema nyMal = new MalerSkjema();
            nyMal.startTid = "";
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            controller.ModelState.AddModelError("startTIid", "mock error message");
            var response = controller.Post(nyMal);
            // Assert
            commandBus.Verify(e => e.RegistrerMal(nyMal,"brukernavn"), Times.Never);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            // Act

        }
开发者ID:matslo,项目名称:Jobbplan,代码行数:32,代码来源:MalerApiController.cs

示例9: TopicsController_Post

        public void TopicsController_Post()
        {
            //a
            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/v1/topics");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{content}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { {"controller", "topics"} });

            _controller.ControllerContext = new HttpControllerContext(config, routeData, request);
            _controller.Request = request;
            _controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            var newTopic = new Topic()
            {
                Title = "test",
                Body = "testtest"
            };

            //a
            var result = _controller.Post(newTopic);

            var json = result.Content.ReadAsStringAsync().Result;
            var topic = JsonConvert.DeserializeObject<Topic>(json);

            //a
            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);

            Assert.IsNotNull(topic);
            Assert.IsTrue(topic.Id > 0);
            Assert.IsTrue(topic.Created > DateTime.MinValue);
        }
开发者ID:jasonjackowiak,项目名称:MessageBoardDemo,代码行数:31,代码来源:TopicControllerTests.cs

示例10: TopicsControllerPost

        public void TopicsControllerPost()
        {
            // Testing POST is harder than it should be but we need to do some work:

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/v1/topics");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "topics" } });

            _controller.ControllerContext = new HttpControllerContext(config, routeData, request);
            _controller.Request = request;
            _controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            var newTopic = new Topic()
            {
                Title = "Test title",
                Body = "Test body"
            };
            var result = _controller.Post(newTopic);
            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);

            var json = result.Content.ReadAsStringAsync().Result;
            var topic = JsonConvert.DeserializeObject<Topic>(json);

            Assert.IsNotNull(topic);
            Assert.AreEqual("Test title", topic.Title);
            Assert.AreEqual("Test body", topic.Body);
            Assert.AreNotEqual(0, topic.Id);
        }
开发者ID:rprouse,项目名称:MessageBoard,代码行数:29,代码来源:TopicsControllerTests.cs

示例11: Post_Mal_Ok

 public void Post_Mal_Ok()
 {
     MalerSkjema nyMal = new MalerSkjema()
     {
         ProsjektId = 1,
         Tittel = "Dagvakt1",
         startTid = "07.30",
         sluttTid = "14.45"
     };
     var commandBus = new Mock<IVaktLogikk>();
     commandBus.Setup(c => c.RegistrerMal(It.IsAny<MalerSkjema>(), It.IsAny<string>())).Returns(true);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "Maler" } });
     var controller = new MalerController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Maler/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyMal);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
      Assert.AreEqual(string.Format("http://localhost/api/Maler"), response.Headers.Location.ToString());
 }
开发者ID:matslo,项目名称:Jobbplan,代码行数:33,代码来源:MalerApiController.cs

示例12: InitController

 public InitController(String controllerName)
 {
     this.config = new HttpConfiguration();
     this.request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/"+controllerName+"Controller");
     this.route = config.Routes.MapHttpRoute(controllerName, "api/{controller}/{id}");
     this.routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", controllerName } });
 }
开发者ID:Pamplemousse09,项目名称:offerservice3,代码行数:7,代码来源:InitController.cs

示例13: ClassInit

 public static void ClassInit(TestContext testContext)
 {
     Configuration = new HttpConfiguration();
     GetRequest = new HttpRequestMessage(HttpMethod.Get, "https://localhost/FACCTS.Server/api/CourtCase");
     var route = Configuration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
     RouteData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "CourtCase" } });
 }
开发者ID:KonstantinDavidov,项目名称:mytestRep,代码行数:7,代码来源:CourtCaseControllerTest.cs

示例14: TestCreatePlan

        public void TestCreatePlan()
        {
            var plandto = CA<PlanDto>();
              var plan = CA<Plan>();
              var config = new HttpConfiguration();
              using (var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/plans")) {
            var routeData = new HttpRouteData(config.Routes.MapHttpRoute("defaultapi", "api/{controller}/{id}"), new HttpRouteValueDictionary {{"controller", "plans"}});
            mController.ControllerContext = new HttpControllerContext(config, routeData, request);
            mController.Request = request;
            mController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            mController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;

            mMapper.Setup(m => m.Map<Plan>(plandto)).Returns(plan);
            mRepo.Setup(r => r.Add(It.Is<Plan>(s => IsEqual(s, plan))));
            mMapper.Setup(m => m.Map<PlanDto>(plan)).Returns(plandto);
            using (var response = mController.PostPlan(plandto)) {
              Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));
              Assert.That(response.Headers.Location.AbsoluteUri, Is.EqualTo("http://localhost/api/plans/" + plandto.ID));
              var result = response.Content.ReadAsStringAsync();
              result.Wait();
              var actual = JsonConvert.DeserializeObject<PlanDto>(result.Result);
              Compare(actual, plandto);
            }
              }
        }
开发者ID:asipe,项目名称:Nucs,代码行数:25,代码来源:PlanControllerTest.cs

示例15: PostTest

        public async Task PostTest()
        {
            var config = new HttpConfiguration();
            var httpRequest = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/links");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "links" } });

            var mockSettings = new Mock<IApplicationSettings>(MockBehavior.Strict);
            const string accessToken = "foo";
            mockSettings.Setup(m => m.PostLinkAccessToken).Returns(accessToken);

            var controller = new LinksController(mockSettings.Object);
            controller.ControllerContext = new HttpControllerContext(config, routeData, httpRequest);
            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            controller.Request.Headers.Add("Linx-Access-Token", accessToken);

            var request = new LinkModel()
                                  {
                                      Channel = "#foobar",
                                      Url = "http://mnd.fi/",
                                      User = "Tom"
                                  };
            HttpResponseMessage response = await controller.PostLink(request);
            Assert.IsNotNull(response.Headers.Location);
        }
开发者ID:htuomola,项目名称:linx,代码行数:25,代码来源:LinksControllerTests.cs


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