• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Routing.HttpRouteData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DepositControllerTest

        public DepositControllerTest()
        {
            var aEventLog = new EventLog();
            var aMockRepo = new Mock<IAccountRepository>();
            aMockRepo.Setup(aRepo => aRepo.GetAccount()).Returns(new Account(0, aEventLog));

            /*********************************************************************************************
                build mock data for ControllerContext so that context-dependent properties can be tested
                (headers, routing, etc...)
            *********************************************************************************************/
            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/account");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/v{version}/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "Deposit" } });

            /*********************************************************************************************
                build the Controller (class under test) and initialize it with the ControllerContext
            *********************************************************************************************/
            _controller = new DepositController(aMockRepo.Object)
            {
                ControllerContext = new HttpControllerContext(config, routeData, request),
                Request = request
            };
            _controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
        }
开发者ID:gblosser,项目名称:RefactoringIterations,代码行数:25,代码来源:DepositControllerTest.cs


示例17: SetUp

        public void SetUp()
        {

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


            gameController = new GameController();
            UrlHelper urlHelper = new UrlHelper(request);
            gameController.ControllerContext = new HttpControllerContext(config, routeData, request);
            gameController.Request = request;
            gameController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            gameController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
            gameController.Url = urlHelper;
            genreController = new GenreController();
            var response = genreController.Get(1);
            var contentResult = response as OkNegotiatedContentResult<DTOGenre>;

            DTOGenre DtoGenre = contentResult.Content;
            genrefromDb = new Genre();
            genrefromDb.Name = DtoGenre.Name;
            genrefromDb.Id = DtoGenre.Id;
            game = new Game() { Name = "Integration Test Game", Genre = genrefromDb };
        }
开发者ID:theklausster,项目名称:DragonsLair,代码行数:26,代码来源:GameIntegrationTest.cs


示例18: RouteTest

        protected RouteTest(string url, HttpMethod httpMethod)
        {
            HttpRequestMessage = new HttpRequestMessage(httpMethod, url);
            HttpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, GlobalConfiguration.Configuration);


           // if (HttpRequestMessage == null)

            foreach (IHttpRoute httpRoute in GlobalConfiguration.Configuration.Routes)

                //GlobalConfiguration.Configuration.Routes.VirtualPathRoot = "sdf";
            {

         
                IHttpRouteData routeData = httpRoute.GetRouteData("http://test.com/", HttpRequestMessage);
                if (routeData != null)
                {
                    var d = routeData;
                }
            }
            var r = (IHttpRouteData)null;


           
            var route = new HttpRouteData(new HttpRoute());
            HttpRouteData = GlobalConfiguration.Configuration.Routes.GetRouteData(HttpRequestMessage);
            HttpRequestMessage.Properties[HttpPropertyKeys.HttpRouteDataKey] = HttpRouteData;
            ControllerSelector = new DefaultHttpControllerSelector(GlobalConfiguration.Configuration);
            ControllerContext = new HttpControllerContext(GlobalConfiguration.Configuration, HttpRouteData, HttpRequestMessage);
        }
开发者ID:amido,项目名称:Amido.Testing,代码行数:30,代码来源:RouteTest.cs


示例19: SetUp

        public void SetUp()
        {

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


            playerController = new PlayerController();
            UrlHelper urlHelper = new UrlHelper(request);
            playerController.ControllerContext = new HttpControllerContext(config, routeData, request);
            playerController.Request = request;
            playerController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            playerController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
            playerController.Url = urlHelper;



            var response = teamController.Get(1);
            var contentResult = response as OkNegotiatedContentResult<DTOTeam>;
            DTOTeam DtoTeam = contentResult.Content;
            Team teamFromDb = new Team();
            teamFromDb.Name = DtoTeam.Name;
            teamFromDb.Id = DtoTeam.Id;
            List<Team> teams = new List<Team>() { teamFromDb };

            player = new Player() { Name = "Integration Test Player", Teams = teams };

        }
开发者ID:theklausster,项目名称:DragonsLair,代码行数:30,代码来源:PlayerIntegrationTest.cs


示例20: Post_Registrer_Prosjekt_Ok

 public void Post_Registrer_Prosjekt_Ok()
 {
     Prosjekt nyttProsjekt = new Prosjekt()
     {
         Arbeidsplass = "TestShop"   
     };
     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 response = controller.Post(nyttProsjekt);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
     Assert.AreEqual(string.Format("http://localhost/api/ProsjektApi/{0}", nyttProsjekt.ProsjektId), response.Headers.Location.ToString());
 }
开发者ID:matslo,项目名称:Jobbplan,代码行数:31,代码来源:ProsjektApiControllerTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Routing.UrlHelper类代码示例发布时间:2022-05-26
下一篇:
C# Routing.ODataPath类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap