Beispiel #1
0
        /// <summary>
        /// Helper method to ensure that the different ways of routing
        /// result in the same setup
        /// </summary>
        /// <param name="server">The server runner instance</param>
        private void CommonTesting(ServerRunner server)
        {
            Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/"));
            Assert.AreEqual(HttpStatusCode.OK, server.GetStatusCode("/home"));
            Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/xyz"));
            Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/home1"));

            Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "GET"));
            Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "XYZ"));

            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/home1", "XYZ"));
            Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "XYZ"));
            Assert.AreEqual(ControllerItems.ENTRY_DEFAULT_INDEX, server.GetStatusMessage("/api/v1/entry"));
            Assert.AreEqual(ControllerItems.ENTRY_INDEX_ID, server.GetStatusMessage("/api/v1/entry/4"));
            Assert.AreEqual(HttpStatusCode.BadRequest, server.GetStatusCode("/api/v1/entry/x"));
            Assert.AreEqual(ControllerItems.ENTRY_DETAIL_INDEX, server.GetStatusMessage("/api/v1/entry/detail"));
            Assert.AreEqual(ControllerItems.ENTRY_DETAIL_ID, server.GetStatusMessage("/api/v1/entry/detail/7"));
            Assert.AreEqual(HttpStatusCode.BadRequest, server.GetStatusCode("/api/v1/entry/detail/y"));

            Assert.AreEqual(ControllerItems.ENTRY_DETAIL_CROSS, server.GetStatusMessage("/api/v1/entry/7/detail"));

            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/"));
            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1"));
            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/home"));
            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/xyz"));

            Assert.AreEqual(ControllerItems.WAIT_INDEX, server.GetStatusMessage("/api/v1/wait", "GET"));
            Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.MethodNotAllowed), server.GetStatusMessage("/api/v1/wait", "POST"));

            Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/api/v1/4/detail"));
        }
Beispiel #2
0
 public void TestResetProcessingTimeout()
 {
     using (var server = new ServerRunner(
                new Ceen.Httpd.ServerConfig()
     {
         MaxProcessingTimeSeconds = 1
     }
                .AddLogger((context, exception, started, duration) => Task.Run(() => Console.WriteLine("Error: {0}", exception)))
                .AddRoute(
                    new[] { typeof(DelayExample) }
                    .ToRoute(
                        new ControllerRouterConfig()
     {
         Debug = true
     }
                        ))
                ))
     {
         Assert.AreEqual(HttpStatusCode.OK, server.GetStatusCode("/delaytarget?waitseconds=2&resettimer=true"));
         Assert.AreEqual(HttpStatusCode.RequestTimeout, server.GetStatusCode("/delaytarget?waitseconds=2&resettimer=false"));
     }
 }
Beispiel #3
0
        public void TestRoutingWithDefaultController()
        {
            using (var server = new ServerRunner(
                       new Ceen.Httpd.ServerConfig()
                       .AddLogger(new Ceen.Httpd.Logging.StdOutErrors())
                       .AddRoute(
                           typeof(ControllerItems)
                           .GetNestedTypes()
                           .ToRoute(
                               new ControllerRouterConfig(
                                   typeof(ControllerItems.HomeController))
            {
                HideDefaultController = false, Debug = true
            }
                               ))
                       ))
            {
                Assert.AreEqual(HttpStatusCode.OK, server.GetStatusCode("/"));
                Assert.AreEqual(HttpStatusCode.OK, server.GetStatusCode("/home"));
                Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/xyz"));
                Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/home1"));

                Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/", "GET"));
                Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/", "XYZ"));
                Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "GET"));
                Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "XYZ"));

                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/home1", "XYZ"));
                Assert.AreEqual(ControllerItems.XYZ_HOME_INDEX, server.GetStatusMessage("/home", "XYZ"));
                Assert.AreEqual(ControllerItems.ENTRY_DEFAULT_INDEX, server.GetStatusMessage("/api/v1/entry"));
                Assert.AreEqual(ControllerItems.ENTRY_INDEX_ID, server.GetStatusMessage("/api/v1/entry/4"));
                Assert.AreEqual(HttpStatusCode.BadRequest, server.GetStatusCode("/api/v1/entry/x"));
                Assert.AreEqual(ControllerItems.ENTRY_DETAIL_INDEX, server.GetStatusMessage("/api/v1/entry/detail"));
                Assert.AreEqual(ControllerItems.ENTRY_DETAIL_ID, server.GetStatusMessage("/api/v1/entry/detail/7"));
                Assert.AreEqual(HttpStatusCode.BadRequest, server.GetStatusCode("/api/v1/entry/detail/y"));

                Assert.AreEqual(ControllerItems.ENTRY_DETAIL_CROSS, server.GetStatusMessage("/api/v1/entry/7/detail"));

                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/"));
                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1"));
                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/home"));
                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.NotFound), server.GetStatusMessage("/api/v1/xyz"));

                Assert.AreEqual(ControllerItems.WAIT_INDEX, server.GetStatusMessage("/api/v1/wait", "GET"));
                Assert.AreEqual(HttpStatusMessages.DefaultMessage(HttpStatusCode.MethodNotAllowed), server.GetStatusMessage("/api/v1/wait", "POST"));

                Assert.AreEqual(HttpStatusCode.NotFound, server.GetStatusCode("/api/v1/4/detail"));
            }
        }
Beispiel #4
0
        public void TestRoutingWithRequirements()
        {
            using (var server = new ServerRunner(
                       new Ceen.Httpd.ServerConfig()
                       .AddLogger(new Ceen.Httpd.Logging.StdOutErrors())
                       .AddRoute("/api/v1/wait", new RequirementControllerItems.TestHandler())
                       .AddRoute(
                           new[] { typeof(RequirementControllerItems.WaitExample) }
                           .ToRoute(
                               new ControllerRouterConfig()
            {
                Debug = true
            }
                               ))
                       ))
            {
                Assert.AreEqual(RequirementControllerItems.WAIT_INDEX_GET, server.GetStatusMessage("/api/v1/wait", "GET"));
                Assert.AreEqual(RequirementControllerItems.WAIT_INDEX_DETAIL_GET, server.GetStatusMessage("/api/v1/wait/detail", "GET"));
                Assert.AreEqual(HttpStatusCode.InternalServerError, server.GetStatusCode("/api/v1/wait/detail", "HEAD"));
            }

            using (var server = new ServerRunner(
                       new Ceen.Httpd.ServerConfig()
                       .AddLogger(new Ceen.Httpd.Logging.StdOutErrors())
                       .AddRoute("/api/v1/wait/detail", new RequirementControllerItems.TestHandler())
                       .AddRoute(
                           new[] { typeof(RequirementControllerItems.WaitExample) }
                           .ToRoute(
                               new ControllerRouterConfig()
            {
                Debug = true
            }
                               ))
                       ))
            {
                Assert.AreEqual(HttpStatusCode.InternalServerError, server.GetStatusCode("/api/v1/wait", "GET"));
                Assert.AreEqual(RequirementControllerItems.WAIT_INDEX_DETAIL_GET, server.GetStatusMessage("/api/v1/wait/detail", "GET"));
                Assert.AreEqual(RequirementControllerItems.WAIT_INDEX_DETAIL_HEAD, server.GetStatusMessage("/api/v1/wait/detail", "HEAD"));
            }
        }