コード例 #1
0
        public static void Main()
        {
            SydneyServiceConfig config = new SydneyServiceConfig("http", "*", 8080, returnExceptionMessagesInResponse: true);

            using (SydneyService service = new SydneyService(config, new ConsoleLogger()))
            {
                service.AddRoute("/books/", new BooksHandler());

                // Routes can have path parameters by enclosing a name in braces.
                service.AddRoute("/users/{id}", new UserHandler());

                // Blocks until Ctrl+C or SIGBREAK is received.
                service.Start();
            }
        }
コード例 #2
0
        public void AddRouteStoresPrefixWithFullPath()
        {
            SydneyServiceConfig config =
                new SydneyServiceConfig(
                    Uri.UriSchemeHttp,
                    "*",
                    80);
            RestHandlerBase handler = A.Fake <RestHandlerBase>();
            SydneyService   service = new SydneyService(config);

            service.AddRoute("/foo/bar", handler);

            Assert.Equal(
                "http://*:80/foo/bar",
                service.Prefixes.Single());
        }
コード例 #3
0
        public void AddRouteThrowsInvalidOperationExceptionWhenServiceIsRunning()
        {
            SydneyServiceConfig config =
                new SydneyServiceConfig(
                    Uri.UriSchemeHttp,
                    "*",
                    80);
            RestHandlerBase handler = A.Fake <RestHandlerBase>();
            SydneyService   service = new SydneyService(config);

            service.Running = true;

            Exception exception = Record.Exception(() => service.AddRoute("/foo/bar", handler));

            Assert.IsType <InvalidOperationException>(exception);
            Assert.Equal(
                "Cannot add a route after the service has been started.",
                exception.Message);
        }