Example #1
0
        private void InitializeWebServer()
        {
            _webserver = new RestWebServer();
            _webserver.RegisterController<ParametersController>();

            _webserver.StartServerAsync();
        }
        public async Task InitializeWebServer()
        {
            var webserver = new RestWebServer(8181);
            webserver.RegisterController<MirrorWebServer>();

            await webserver.StartServerAsync();
        }
Example #3
0
        public async Task HandleRequest_BasicGETUriPrefix_Status200()
        {
            var m = new RestWebServer(8800, "api");
            m.RegisterController<HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETUriPrefix);

            StringAssert.Contains(response.Response, "200 OK");
        }
        public async Task HandleRequest_BasicGETAbsoluteUri_Status200()
        {
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETAbsoluteUri);

            StringAssert.Contains(response.ToString(), "200 OK");
        }
Example #5
0
        public async Task HandleRequest_WrongParameterTypePUT_BadRequest()
        {
            var m = new RestWebServer();
            m.RegisterController<RaiyDayTestController>();
            var response = await m.HandleRequest(_parameterParseExceptionPUT);

            StringAssert.Contains(response.Response, "400 Bad Request");
        }
Example #6
0
        public async Task InitializeWebServer()
        {
            var webserver = new RestWebServer(8181);

            webserver.RegisterController <MirrorWebServer>();

            await webserver.StartServerAsync();
        }
Example #7
0
        public async Task HandleRequest_BasicPUT_MethodNotAllowed()
        {
            var m = new RestWebServer();
            m.RegisterController<RaiyDayTestController>();
            var response = await m.HandleRequest(_methodNotAllowedPUT);

            StringAssert.Contains(response.Response, "405 Method Not Allowed");
            StringAssert.Contains(response.Response, "Allow: POST");
        }
Example #8
0
        public async Task HandleRequest_CreateWithExistingId_Conflicted()
        {
            var m = new RestWebServer();
            m.RegisterController<RaiyDayTestController>();
            var response = await m.HandleRequest(_conflictingPOST);

            StringAssert.Contains(response.Response, "409 Conflict");
            StringAssert.DoesNotMatch(response.Response, new Regex("Location:"));
        }
Example #9
0
        public async Task HandleRequest_InvalidJsonBodyParameter_BadRequest()
        {
            var m = new RestWebServer();

            m.RegisterController <RaiyDayTestController>();
            var response = await m.HandleRequest(_invalidXmlFormatExPOST);

            StringAssert.Contains(response.Response, "400 Bad Request");
        }
Example #10
0
        public async Task HandleRequest_BasicGETUriPrefix_Status200()
        {
            var m = new RestWebServer(8800, "api");

            m.RegisterController <HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETUriPrefix);

            StringAssert.Contains(response.Response, "200 OK");
        }
Example #11
0
        public async Task HandleRequest_WrongParameterTypePUT_BadRequest()
        {
            var m = new RestWebServer();

            m.RegisterController <RaiyDayTestController>();
            var response = await m.HandleRequest(_parameterParseExceptionPUT);

            StringAssert.Contains(response.Response, "400 Bad Request");
        }
Example #12
0
        public async Task HandleRequest_BasicPUT_MethodNotAllowed()
        {
            var m = new RestWebServer();

            m.RegisterController <RaiyDayTestController>();
            var response = await m.HandleRequest(_methodNotAllowedPUT);

            StringAssert.Contains(response.Response, "405 Method Not Allowed");
            StringAssert.Contains(response.Response, "Allow: POST");
        }
Example #13
0
        public async Task HandleRequest_CreateWithExistingId_Conflicted()
        {
            var m = new RestWebServer();

            m.RegisterController <RaiyDayTestController>();
            var response = await m.HandleRequest(_conflictingPOST);

            StringAssert.Contains(response.Response, "409 Conflict");
            StringAssert.DoesNotMatch(response.Response, new Regex("Location:"));
        }
Example #14
0
        public async Task HandleRequest_BasicPOST_LocationHeaderStatus201()
        {
            var m = new RestWebServer();

            m.RegisterController <HappyPathTestController>();
            var response = await m.HandleRequest(_basicPOST);

            StringAssert.Contains(response.Response, "201 Created");
            StringAssert.Contains(response.Response, "Location: /users/2");
        }
Example #15
0
        public async Task HandleRequest_ControllerWithArgs_MatchConstructor()
        {
            var m = new RestWebServer();

            m.RegisterController <HappyPathTestSingletonControllerWithArgs>("Johathan", 15);
            var response = await m.HandleRequest(_basicControllerWithArgs);

            StringAssert.Contains(response.Response, "\"Name\":\"Johathan\"");
            StringAssert.Contains(response.Response, "\"Age\":15");
        }
Example #16
0
        public async Task HandleRequest_BasicGETAcceptXML_Status200WithXml()
        {
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETAcceptXML);

            StringAssert.Contains(response.Response, "200 OK");
            StringAssert.Contains(response.Response, "Content-Type: application/xml");
            StringAssert.Contains(response.Response, "<Name>Tom</Name>");
            StringAssert.Contains(response.Response, "<Age>30</Age>");
        }
Example #17
0
        public async Task HandleRequest_BasicGETAcceptJSON_Status200WithJSON()
        {
            var m = new RestWebServer();

            m.RegisterController <HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETAcceptJSON);

            StringAssert.Contains(response.Response, "200 OK");
            StringAssert.Contains(response.Response, "Content-Type: application/json");
            StringAssert.Contains(response.Response, "\"Name\":\"Tom\"");
            StringAssert.Contains(response.Response, "\"Age\":30");
        }
Example #18
0
        public async Task HandleRequest_BasicGETAcceptXML_Status200WithXml()
        {
            var m = new RestWebServer();

            m.RegisterController <HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETAcceptXML);

            StringAssert.Contains(response.Response, "200 OK");
            StringAssert.Contains(response.Response, "Content-Type: application/xml");
            StringAssert.Contains(response.Response, "<Name>Tom</Name>");
            StringAssert.Contains(response.Response, "<Age>30</Age>");
        }
Example #19
0
        private async Task InitializeWebServer()
        {
            _webserver = new RestWebServer(8800, "api");

            _webserver.RegisterController <AsyncControllerSample>();
            _webserver.RegisterController <FromBodyControllerSample>();
            _webserver.RegisterController <PerCallControllerSample>();
            _webserver.RegisterController <SimpleParameterControllerSample>();
            _webserver.RegisterController <SingletonControllerSample>();
            _webserver.RegisterController <ThrowExceptionControllerSample>();
            _webserver.RegisterController <WithResponseBodyControllerSample>();

            await _webserver.StartServerAsync();
        }
Example #20
0
        private async Task InitializeWebServer()
        {
            _webserver = new RestWebServer(8800, "api");

            _webserver.RegisterController<AsyncControllerSample>();
            _webserver.RegisterController<FromBodyControllerSample>();
            _webserver.RegisterController<PerCallControllerSample>();
            _webserver.RegisterController<SimpleParameterControllerSample>();
            _webserver.RegisterController<SingletonControllerSample>();
            _webserver.RegisterController<ThrowExceptionControllerSample>();
            _webserver.RegisterController<WithResponseBodyControllerSample>();

            await _webserver.StartServerAsync();
        }
Example #21
0
        public async Task HandleRequest_PerCallControllerWithArgs_MatchConstructor()
        {
            int age = 15;
            var m   = new RestWebServer();

            m.RegisterController <HappyPathTestPerCallControllerWithArgs>(() => new object[] { "Johathan", age++ });
            var response = await m.HandleRequest(_basicControllerWithArgs);

            StringAssert.Contains(response.Response, "\"Name\":\"Johathan\"");
            StringAssert.Contains(response.Response, "\"Age\":15");

            response = await m.HandleRequest(_basicControllerWithArgs);

            StringAssert.Contains(response.Response, "\"Name\":\"Johathan\"");
            StringAssert.Contains(response.Response, "\"Age\":16");
        }
Example #22
0
        public void HandleRequest_WrongParameterTypeInController_InvalidOperationException()
        {
            var m = new RestWebServer();

            bool invOpThrown = false;

            try
            {
                m.RegisterController <ParameterTypeErrorTestController>();
            }
            catch (InvalidOperationException)
            {
                invOpThrown = true;
            }

            Assert.IsTrue(invOpThrown, "InvalidOperationException was not thrown");
        }
Example #23
0
        /// <remarks>
        /// If you start any asynchronous methods here, prevent the task
        /// from closing prematurely by using BackgroundTaskDeferral as
        /// described in http://aka.ms/backgroundtaskdeferral
        /// </remarks>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // This deferral should have an instance reference, if it doesn't... the GC will
            // come some day, see that this method is not active anymore and the local variable
            // should be removed. Which results in the application being closed.
            _deferral = taskInstance.GetDeferral();

            _webserver = new RestWebServer(8800, "api");

            _webserver.RegisterController<AsyncControllerSample>();
            _webserver.RegisterController<FromContentControllerSample>();
            _webserver.RegisterController<PerCallControllerSample>();
            _webserver.RegisterController<SimpleParameterControllerSample>();
            _webserver.RegisterController<SingletonControllerSample>();
            _webserver.RegisterController<ThrowExceptionControllerSample>();
            _webserver.RegisterController<WithResponseContentControllerSample>();

            await _webserver.StartServerAsync();

            // Dont release deferral, otherwise app will stop
        }
        public async Task HandleRequest_InvalidXMLContentParameter_BadRequest()
        {
            var m = new RestWebServer();
            m.RegisterController<RaiyDayTestController>();
            var response = await m.HandleRequest(_xmlContentParameterParseExPOST);

            StringAssert.Contains(response.ToString(), "400 Bad Request");
        }
        public async Task HandleRequest_PerCallControllerWithArgs_MatchConstructor()
        {
            int age = 15;
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestPerCallControllerWithArgs>(() => new object[] { "Johathan", age++ });
            var response = await m.HandleRequest(_basicControllerWithArgs);

            string content = response.ToString();

            StringAssert.Contains(content, "\"Name\":\"Johathan\"");
            StringAssert.Contains(content, "\"Age\":15");

            response = await m.HandleRequest(_basicControllerWithArgs);

            content = response.ToString();

            StringAssert.Contains(content, "\"Name\":\"Johathan\"");
            StringAssert.Contains(content, "\"Age\":16");
        }
        public async Task HandleRequest_ControllerWithArgs_MatchConstructor()
        {
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestSingletonControllerWithArgs>("Johathan", 15);
            var response = await m.HandleRequest(_basicControllerWithArgs);

            string content = response.ToString();

            StringAssert.Contains(content, "\"Name\":\"Johathan\"");
            StringAssert.Contains(content, "\"Age\":15");
        }
        public async Task HandleRequest_BasicPOST_LocationHeaderStatus201()
        {
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestController>();
            var response = await m.HandleRequest(_basicPOST);

            string content = response.ToString();

            StringAssert.Contains(content, "201 Created");
            StringAssert.Contains(content, "Location: /users/2");
        }
        public async Task HandleRequest_BasicGETAcceptJSON_Status200WithJSON()
        {
            var m = new RestWebServer();
            m.RegisterController<HappyPathTestController>();
            var response = await m.HandleRequest(_basicGETAcceptJSON);

            string content = response.ToString();

            StringAssert.Contains(content, "200 OK");
            StringAssert.Contains(content, "Content-Type: application/json");
            StringAssert.Contains(content, "\"Name\":\"Tom\"");
            StringAssert.Contains(content, "\"Age\":30");
        }
Example #29
0
        public async Task HandleRequest_InvalidJsonBodyParameter_BadRequest()
        {
            var m = new RestWebServer();
            m.RegisterController<RaiyDayTestController>();
            var response = await m.HandleRequest(_invalidXmlFormatExPOST);

            StringAssert.Contains(response.Response, "400 Bad Request");
        }
Example #30
0
        public void HandleRequest_WrongParameterTypeInController_InvalidOperationException()
        {
            var m = new RestWebServer();

            bool invOpThrown = false;
            try
            {
                m.RegisterController<ParameterTypeErrorTestController>();
            }
            catch (InvalidOperationException)
            {
                invOpThrown = true;
            }

            Assert.IsTrue(invOpThrown, "InvalidOperationException was not thrown");
        }