public void ShouldBeAbleToReceiveResponseFromANodeWhenOtherNodesAreDown()
        {
            var sampleClusterConfiguration = BuildSampleClusterConfiguration();

            var testServer1 = SetupTestServerForNode(sampleClusterConfiguration.Nodes[0]);
            testServer1.Start();

            var sut = new NetMqRpcChannel(sampleClusterConfiguration, TimeSpan.FromMilliseconds(200));

            var sampleRequest = new SampleRequest("test");

            var autoResetEvent = new AutoResetEvent(false);

            int expectedNumberOfResponses = sampleClusterConfiguration.Nodes.Length;
            var responses = new List<SampleResponse>();

            sut.Broadcast<SampleRequest, SampleResponse>(sampleRequest, response =>
            {
                responses.Add(response);

                if (responses.Count >= expectedNumberOfResponses)
                {
                    autoResetEvent.Set();
                }
            });

            autoResetEvent.WaitOne(TimeSpan.FromSeconds(1));

            Assert.AreEqual(1, responses.Count);
            Assert.IsNotNull(responses.SingleOrDefault(x => x.ResponseString == sampleClusterConfiguration.Nodes[0].Id.ToString()));
        }
        public void ShouldBeAbleToUnicastAMessageAndReceiveAResponse()
        {
            var sampleClusterConfiguration = BuildSampleClusterConfiguration();

            // Start a test server to listen for requests
            SampleResponse serverResponse = new SampleResponse("test response");
            var testServer = new TestServer(sampleClusterConfiguration.Nodes[0], serverResponse);
            testServer.Start();

            var sut = new NetMqRpcChannel(sampleClusterConfiguration, TimeSpan.FromMilliseconds(200));

            var sampleRequest = new SampleRequest("test");

            var responseReturned = sut.Unicast<SampleRequest, SampleResponse>(sampleClusterConfiguration.Nodes[0].Id, sampleRequest);

            Assert.IsNotNull(responseReturned);
            Assert.AreEqual(serverResponse, responseReturned);
            Assert.AreEqual(sampleRequest, testServer.GetLastReceivedMessageObject<SampleRequest>());
        }
        public void UnicastShouldReturnNullIfServerDoesNotRespond()
        {
            var sampleClusterConfiguration = BuildSampleClusterConfiguration();

            var sut = new NetMqRpcChannel(sampleClusterConfiguration, TimeSpan.FromMilliseconds(200));

            var sampleRequest = new SampleRequest("test");

            var responseReturned = sut.Unicast<SampleRequest, SampleResponse>(sampleClusterConfiguration.Nodes[0].Id, sampleRequest);

            Assert.IsNull(responseReturned);
        }