コード例 #1
0
        public async Task OwinToHttpRoutingGet()
        {
            // in order to review what are the routing rules
            // used by the router look at the Owin startup routine

            // start a web server that holds our owin pipeline (which has the router in it)
            var OwinWebServer = new TestWebServer();

            OwinWebServer.Start <TestOwinRouterStartUp>(OwinRouterSrvAddress);
            // run a test

            var path = "api/values/0"; // this address doesn't exist  on
                                       // the router but it will be routed anyway
                                       // because we have rules configured for that

            var hrm = new HttpRequestMessage();

            // call the router endpoint
            hrm.RequestUri = new System.Uri(string.Concat(OwinRouterSrvAddress, path));
            hrm.Method     = HttpMethod.Get;
            var httpClient   = new HttpClient();
            var httpResponse = await httpClient.SendAsync(hrm);


            var responseString = await httpResponse.Content.ReadAsStringAsync();


            httpResponse.EnsureSuccessStatusCode();

            // stop the server
            OwinWebServer.Stop();
        }
コード例 #2
0
        public void InitTests()
        {
            Trace.WriteLine(" ***** #define ENABLE_LONGRUNNING_TESTS for long running tests **** ");

            mApiServer01 = new TestWebServer();
            mApiServer02 = new TestWebServer();
            mApiServer03 = new TestWebServer();

            mApiServer01.Start <ApiAppStartUp>(srv01Address);
            mApiServer02.Start <ApiAppStartUp>(srv02Address);
            mApiServer03.Start <ApiAppStartUp>(srv03Address);

            ServicePointManager.DefaultConnectionLimit = 10; // default is 2
        }
コード例 #3
0
        public async Task WebSocketsMapToHttp02()
        {
            // in order to review what are the routing rules
            // used by the router look at the Owin startup routine

            // start a web server that holds our owin pipeline (which has the router in it)
            var SocketWebServer = new TestWebServer();

            SocketWebServer.Start <OwinWebSocketStartup>(OwinSocketRouterSrvAddress);



            var InMessage = new MessageIn()
            {
                MessageType = "AddModels"
            };

            InMessage.theModel = Model.getRandomModel();

            var InMessageJson = InMessage.GetAsJsonString();


            // create a socket client and connect

            ClientWebSocket clientWSocket = new ClientWebSocket();
            await clientWSocket.ConnectAsync(new Uri(OwinSocketRouterSrvAddressExternal), CancellationToken.None);

            // send in Message
            await clientWSocket.SendAsync(new ArraySegment <byte>(Encoding.UTF8.GetBytes(InMessageJson)),
                                          WebSocketMessageType.Text,
                                          true,
                                          CancellationToken.None);



            var socketrcv = await ReceiveFromSocket(clientWSocket);

            var outMessage = JsonConvert.DeserializeObject <MessageOut>(socketrcv);

            // based on routing the following should be true
            Assert.AreEqual(outMessage.Method, "POST");
            Assert.IsTrue(outMessage.Models.Count() == 1);
            Assert.IsTrue(outMessage.Models[0].ModelId == InMessage.theModel.ModelId);


            // stop the server
            SocketWebServer.Stop();
        }
コード例 #4
0
        public async Task OwinToHttpRoutingPut()
        {
            // start a web server that holds our owin pipeline (which has the router in it)
            var OwinWebServer = new TestWebServer();

            OwinWebServer.Start <TestOwinRouterStartUp>(OwinRouterSrvAddress);


            var path      = "api/models/0";
            var sentModel = Model.getRandomModel();


            var hrm = new HttpRequestMessage();

            // call the router endpoint
            hrm.RequestUri = new System.Uri(string.Concat(OwinRouterSrvAddress, path));
            hrm.Method     = HttpMethod.Put;
            hrm.Content    = new StreamContent(sentModel.asJsonStream());
            hrm.Content.Headers.Add("Content-Type", "application/json");

            var httpClient   = new HttpClient();
            var httpResponse = await httpClient.SendAsync(hrm);



            httpResponse.EnsureSuccessStatusCode();

            // stop the server
            OwinWebServer.Stop();



            var responseString = await httpResponse.Content.ReadAsStringAsync();

            var modelReturn = JsonConvert.DeserializeObject <ModelControllerResponseContent>(responseString);


            Assert.AreEqual(sentModel.ModelId, modelReturn.Models[0].ModelId);
        }