public void SydneyServiceConstructorCallsValidateOnConfig() { SydneyServiceConfig config = A.Fake <SydneyServiceConfig>(); config.Scheme = Uri.UriSchemeHttp; config.Host = "*"; config.Port = 80; SydneyService service = new SydneyService(config); A.CallTo(() => config.Validate()).MustHaveHappenedOnceExactly(); }
public void ValidateThrowsExceptionForInvalidScheme() { SydneyServiceConfig config = new SydneyServiceConfig { Scheme = "foo" }; Exception exception = Record.Exception(() => config.Validate()); Assert.IsType <ArgumentException>(exception); Assert.Equal( "SydneyServiceConfig.Scheme must be one of \"http\" or \"https\".", exception.Message); }
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(); } }
public void ValidateThrowsExceptionForInvalidHost() { SydneyServiceConfig config = new SydneyServiceConfig { Scheme = Uri.UriSchemeHttp, Host = null }; Exception exception = Record.Exception(() => config.Validate()); Assert.IsType <ArgumentException>(exception); Assert.Equal( "SydneyServiceConfig.Host must be a valid non-empty string. Use \"*\" or \"+\" to match all hosts.", exception.Message); }
public void ValidateThrowsExceptionForInvalidPort() { SydneyServiceConfig config = new SydneyServiceConfig { Scheme = Uri.UriSchemeHttp, Host = "*", Port = 0 }; Exception exception = Record.Exception(() => config.Validate()); Assert.IsType <ArgumentException>(exception); Assert.Equal( "SydneyServiceConfig.Port must be a valid port value between 1 and 65535.", exception.Message); }
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()); }
public void ValidateDoesNotThrowExceptionForValidConfig() { SydneyServiceConfig config = new SydneyServiceConfig( Uri.UriSchemeHttp, "*", 80, true); // Call should not throw exceptions. config.Validate(); Assert.Equal(Uri.UriSchemeHttp, config.Scheme); Assert.Equal("*", config.Host); Assert.Equal(80, config.Port); Assert.True(config.ReturnExceptionMessagesInResponse); }
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); }