public void client_receives_both_messages()
        {
            var pipe1 = Guid.NewGuid().ToString();
            var pipe2 = Guid.NewGuid().ToString();
            var pipe3 = Guid.NewGuid().ToString();

            using (var server1 = new PipeServer(pipe1))
            {
                using (var server2 = new PipeServer(pipe2))
                {
                    using (var junction = new PipeJunction(pipe3))
                    {
                        junction.Combine(pipe1);
                        junction.Combine(pipe2);
                        server1.Send("Message from server 1");
                        server2.Send("Message from server 2");

                        var messages = new List <string>();
                        var client   = new PipeClient();
                        new System.Threading.Thread(() => client.Listen(pipe3, (m) => messages.Add(m))).Start();
                        Timeout.AfterTwoSeconds().IfNot(() => messages.Count == 2);
                        Assert.That(messages.Count, Is.EqualTo(2));
                    }
                }
            }
        }
        public void the_client_receives_it()
        {
            var pipeName = Guid.NewGuid().ToString();
            var client   = new PipeClient();

            using (var server = new PipeServer(pipeName))
            {
                string receivedMessage = null;
                new System.Threading.Thread(() => client.Listen(pipeName, (m) => receivedMessage = m)).Start();
                server.Send("message sent by server");
                Timeout.AfterTwoSeconds().IfNot(() => receivedMessage != null);
                Assert.That(receivedMessage, Is.EqualTo("message sent by server"));
            }
        }
Пример #3
0
        private Thread startChannelListener(string channel)
        {
            if (OS.IsPosix)
            {
                return(null);
            }
            var thread = new Thread(
                (x) =>
            {
                _pipeClient = new PipeClient();
                _pipeClient.Listen(
                    x.ToString(),
                    (msg) =>
                {
                    if (msg == "")
                    {
                        return;
                    }
                    if (_feedback != null)
                    {
                        var testStarted = "Test started:";
                        if (msg.StartsWith(testStarted))
                        {
                            _feedback.TestStarted(msg.Substring(testStarted.Length, msg.Length - testStarted.Length));
                        }
                        else
                        {
                            _feedback.TestFinished(TestResult.FromXml(msg));
                        }
                    }
                });
            });

            thread.Start(channel);
            return(thread);
        }