コード例 #1
0
        public void Client_should_connect_to_server_and_signal_appropriate_callbacks()
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex     = ServerHelpers.CreateExecutor();
            var server = ServerHelpers.CreateServer();

            server.Connected.Subscribe(client =>
            {
                connected1.Set();
            });

            server.Started.Subscribe(u =>
            {
                var client = new SocketClient(ex);
                client.Connected.Subscribe(_ =>
                {
                    connected2.Set();
                });
                client.Disconnected.Subscribe(exn =>
                {
                    throw exn;
                });
                client.Connect(new IPEndPoint(IPAddress.Loopback, server.BindEndPoint.Port));
            });

            server.Start();

            connected1.AssertWaitFor(5000);
            connected2.AssertWaitFor(5000);

            server.StopAndAssertStopped();
        }
コード例 #2
0
            public void Starting_two_times_should_throw()
            {
                var server = ServerHelpers.CreateServer();

                server.Start();

                Assert.Throws(typeof(InvalidOperationException), () =>
                {
                    server.Start();
                });
            }
コード例 #3
0
            public void Starting_should_call_started_callback()
            {
                var started = new ManualResetEventSlim();
                var server  = ServerHelpers.CreateServer();

                server.Started.Subscribe(u => { started.Set(); });
                server.Start();

                started.AssertWaitFor(2000);

                server.StopAndAssertStopped();
            }
コード例 #4
0
ファイル: Utils.cs プロジェクト: waqashaneef/Stacks
        public static void CreateServerAndConnectedClient(out SocketServer server,
                                                          out SslClient client1, out SslClient client2)
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex = ServerHelpers.CreateExecutor();
            var s  = ServerHelpers.CreateServer();

            SslClient lClient = null;
            SslClient sClient = null;

            var certBytesStream = Assembly.GetExecutingAssembly()
                                  .GetManifestResourceStream("Stacks.Tests.StacksTest.pfx");
            var certBytes = new BinaryReader(certBytesStream).ReadBytes((int)certBytesStream.Length);

            s.Connected.Subscribe(c =>
            {
                sClient = new SslClient(c, new X509Certificate2(certBytes));

                sClient.Connected.Subscribe(_ =>
                {
                    connected2.Set();
                });

                sClient.EstablishSsl();
            });

            s.Started.Subscribe(_ =>
            {
                lClient = new SslClient(new SocketClient(ex), "Stacks Test", true);

                lClient.Connected.Subscribe(__ =>
                {
                    connected1.Set();
                });

                lClient.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port));
            });

            s.Start();

            connected1.AssertWaitFor(300000);
            connected2.AssertWaitFor(300000);

            server  = s;
            client1 = lClient;
            client2 = sClient;
        }
コード例 #5
0
            public void Starting_and_stopping_should_call_both_callbacks()
            {
                var started = new ManualResetEventSlim();
                var stopped = new ManualResetEventSlim();
                var server  = ServerHelpers.CreateServer();

                server.Started.Subscribe(_ => { started.Set(); });
                server.Stopped.Subscribe(_ => { stopped.Set(); });

                server.Start();
                server.Stop();

                started.AssertWaitFor(2000);
                stopped.AssertWaitFor(2000);
            }
コード例 #6
0
            public void When_exception_is_thrown_inside_callback_executor_should_signal_error()
            {
                var errOccured = new ManualResetEventSlim();

                var exec   = new ActionBlockExecutor(null, new ActionBlockExecutorSettings());
                var server = ServerHelpers.CreateServer(exec);

                exec.Error += exc => { Assert.Equal("abcdef", exc.Message); errOccured.Set(); };
                server.Started.Subscribe(_ => { throw new Exception("abcdef"); });

                server.Start();

                errOccured.AssertWaitFor(2000);

                server.Stop();
            }
コード例 #7
0
        public void Calling_connect_twice_should_throw_an_exception()
        {
            var hasConnected = new ManualResetEventSlim();
            var executor     = ServerHelpers.CreateExecutor();
            var server       = ServerHelpers.CreateServer(executor);

            server.Started.Subscribe(_ =>
            {
                Assert.Throws(typeof(InvalidOperationException),
                              () =>
                {
                    var client = new SocketClient(executor);
                    client.Connect(server.BindEndPoint);
                    hasConnected.Set();
                    client.Connect(server.BindEndPoint);
                });
            });

            server.Start();

            hasConnected.AssertWaitFor();
        }
コード例 #8
0
ファイル: Utils.cs プロジェクト: waqashaneef/Stacks
        public static void CreateServerAndConnectedClient(out SocketServer server,
                                                          out SocketClient client1, out SocketClient client2)
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex = ServerHelpers.CreateExecutor();
            var s  = ServerHelpers.CreateServer();

            SocketClient lClient = null;
            SocketClient sClient = null;

            s.Connected.Subscribe(c =>
            {
                sClient = c;
                connected2.Set();
            });

            s.Started.Subscribe(_ =>
            {
                var c = new SocketClient(ex);
                c.Connected.Subscribe(u =>
                {
                    lClient = c;
                    connected1.Set();
                });
                c.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port));
            });

            s.Start();

            connected1.AssertWaitFor(3000);
            connected2.AssertWaitFor(3000);

            server  = s;
            client1 = lClient;
            client2 = sClient;
        }