public void EngineShouldHandleNewRequests() { var logger = MockRepository.GenerateMock<ILogger>(); var routeRegister = MockRepository.GenerateMock<IRouteRegister>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); var socketListener = MockRepository.GenerateStrictMock<ISocketListener>(); socketListener.Expect(s => s.RemoteIpAddress).Return("ip"); socketListener.Expect(s => s.RemotePort).Return(80); socketListener.Expect(s => s.Start()); socketListener.Expect(s => s.Accept()) .Return(new Task<ISocketListener>(() => socketListener)) .Repeat.Once(); socketListener.Expect(s => s.Accept()) .Return(new Task<ISocketListener>(() => socketListener)); var engine = MockRepository.GenerateStrictMock<IStyxEngine>(); engine.Expect(e => e.HandleRequest(Arg<ISocketListener>.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.Start(); }
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 HostTest() { var manualResetEvent = new ManualResetEventSlim(); var uri = new Uri("ws://localhost"); var logger = new NLogger(); var host = new StyxHost(uri, logger: logger); host.Start(); manualResetEvent.Wait(); }
public void PassingNullForTheLocationShouldThrowAnArgumentNullException() { var host = new StyxHost(null); host.Start(); }
public void StartingTheHostShouldStartTheSocketListener() { var logger = MockRepository.GenerateMock<ILogger>(); var engine = MockRepository.GenerateMock<IStyxEngine>(); var routeRegister = MockRepository.GenerateMock<IRouteRegister>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); var socketListener = MockRepository.GenerateStrictMock<ISocketListener>(); socketListener.Expect(s => s.Start()).Repeat.Once(); socketListener.Expect(s => s.Accept()).Return(new Task<ISocketListener>(() => socketListener)); 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.Start(); }
public void ShouldThrowAnApplicationExceptionIfSecureButMissingCertificate() { var logger = MockRepository.GenerateMock<ILogger>(); var engine = MockRepository.GenerateMock<IStyxEngine>(); var routeRegister = MockRepository.GenerateMock<IRouteRegister>(); var socketListener = MockRepository.GenerateMock<ISocketListener>(); var hostConfiguration = MockRepository.GenerateMock<IHostConfiguration>(); hostConfiguration.Expect(h => h.Certificate).Return(null); hostConfiguration.Expect(h => h.Scheme).Return("wss"); 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("wss://localhost"); var host = new StyxHost(uri, bootstrapper: bootstrapper); host.Start(); }