public void RegisterHandlerOverloadsShouldRegisterWithRouteRegister() { var logger = MockRepository.GenerateMock<ILogger>(); var engine = MockRepository.GenerateMock<IStyxEngine>(); var socketListener = MockRepository.GenerateMock<ISocketListener>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); var routeRegister = MockRepository.GenerateStrictMock<IRouteRegister>(); routeRegister.Expect(r => r.Register(Arg<string>.Is.Equal("onOpen"), Arg<Func<IWebSocketHandler>>.Is.NotNull)); routeRegister.Expect(r => r.Register(Arg<string>.Is.Equal("onError"), Arg<Func<IWebSocketHandler>>.Is.NotNull)); routeRegister.Expect(r => r.Register(Arg<string>.Is.Equal("onClose"), Arg<Func<IWebSocketHandler>>.Is.NotNull)); routeRegister.Expect(r => r.Register(Arg<string>.Is.Equal("all"), Arg<Func<IWebSocketHandler>>.Is.NotNull)); var bootstrapper = MockRepository.GenerateStrictMock<IBootstrapper>(); bootstrapper.Expect(b => b.Logger).Return(logger); bootstrapper.Expect(b => b.Engine).Return(engine); bootstrapper.Expect(b => b.RouteRegister).Return(routeRegister); bootstrapper.Expect(b => b.SocketListener).Return(socketListener); bootstrapper.Expect(b => b.HostConfiguration).Return(hostConfiguration); var uri = new Uri("ws://localhost"); var host = new StyxHost(uri, bootstrapper: bootstrapper); host.RegisterRoute("onOpen", ws => {}); host.RegisterRoute("onError", ws => {}, ex => {}); host.RegisterRoute("onClose", ws => {}, () => {}); host.RegisterRoute("all", ws => {}, () => {}, ex => {}); }
public void UsageTest() { var resetEvent = new ManualResetEvent(false); var location = new Uri("ws://localhost"); var host = new StyxHost(location); host.RegisterRoute("/test", () => new TestRoute()); host.RegisterRoute("/test/{message}", h => { h.Send(h.Route.Message as string); h.OnMessage = h.Send; }); host.RegisterRoute("/test/ahoy", c => c.Send("ahoy"), () => Console.WriteLine("Closed")); host.RegisterRoute("/test/query", h => { foreach (string key in h.Query.Keys) h.Send(key); }); host.Start(); resetEvent.WaitOne(TimeSpan.FromMinutes(15)); host.Dispose(); }
public void RegisterHandlerOverloadsShouldThrowAnArgumentNullExceptionOnNullArguments() { var bootstrapper = MockRepository.GenerateMock<IBootstrapper>(); var uri = new Uri("ws://localhost"); var host = new StyxHost(uri, bootstrapper:bootstrapper); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute(null, ws => { })); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", ((Action<IWebSocketHandler>)null))); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", ws => { }, ((Action)null))); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", ws => { }, ((Action<Exception>)null))); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", null, () => { }, ex => { })); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", ws => { }, null, ex => { })); Assert.Throws<ArgumentNullException>(() => host.RegisterRoute("route", ws => { }, () => { }, null)); }
public void RegisteringARouteShouldDelegateToTheRouteRegister() { var logger = MockRepository.GenerateMock<ILogger>(); var engine = MockRepository.GenerateMock<IStyxEngine>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); var socketListener = MockRepository.GenerateMock<ISocketListener>(); var routeRegister = MockRepository.GenerateMock<IRouteRegister>(); routeRegister.Expect(r => r.Register(Arg<string>.Is.Equal("test"), Arg<Func<IWebSocketHandler>>.Is.NotNull)); var bootstrapper = MockRepository.GenerateStrictMock<IBootstrapper>(); bootstrapper.Expect(b => b.Logger).Return(logger); bootstrapper.Expect(b => b.Engine).Return(engine); bootstrapper.Expect(b => b.RouteRegister).Return(routeRegister); bootstrapper.Expect(b => b.SocketListener).Return(socketListener); bootstrapper.Expect(b => b.HostConfiguration).Return(hostConfiguration); var uri = new Uri("ws://localhost"); var host = new StyxHost(uri, bootstrapper: bootstrapper); host.RegisterRoute("test", h => {}); }
public void ShouldThrowAnArgumentNullExceptionWhenRegisteringANullRouteHandler() { var logger = MockRepository.GenerateMock<ILogger>(); var engine = MockRepository.GenerateMock<IStyxEngine>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); var socketListener = MockRepository.GenerateMock<ISocketListener>(); var routeRegister = MockRepository.GenerateMock<IRouteRegister>(); var bootstrapper = MockRepository.GenerateStrictMock<IBootstrapper>(); bootstrapper.Expect(b => b.Logger).Return(logger); bootstrapper.Expect(b => b.Engine).Return(engine); bootstrapper.Expect(b => b.RouteRegister).Return(routeRegister); bootstrapper.Expect(b => b.SocketListener).Return(socketListener); bootstrapper.Expect(b => b.HostConfiguration).Return(hostConfiguration); var uri = new Uri("ws://localhost"); var host = new StyxHost(uri, bootstrapper: bootstrapper); host.RegisterRoute("route", null); }