public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
                using (var socket = new TestStreamSocket(mem))
                {
                    var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                    var message = new NodeGreetingMessage(NodeType.Responder);
                    mem.Write(message.Serialize(), 0, message.Serialize().Length);
                    mem.Position = 0;

                    try
                    {
                        await negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                            NodeType.Requester
                        }, CancellationToken.None);

                        Assert.Fail();
                    }
                    catch (RedFoxProtocolException)
                    {
                        Assert.Pass();
                    }
                }
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
            using (var socket = new TestStreamSocket(mem))
            {
                var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                var message = new NodeGreetingMessage(NodeType.Responder);
                mem.Write(message.Serialize(), 0, message.Serialize().Length);
                mem.Position = 0;

                Assert.Throws<RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet<NodeType> { NodeType.Requester }));
            }
        }
        public void VerifyRemoteGreeting_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
            using (var socket = new TestStreamSocket(mem))
            {
                var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                var message = new NodeGreetingMessage(NodeType.Responder);
                mem.Write(message.Serialize(), 0, message.Serialize().Length);
                mem.Position = 0;

                negotiator.VerifyRemoteGreeting(new HashSet<NodeType> { NodeType.Responder });
            }
        }
        public void Serialize_ProtocolVersion()
        {
            var greetingMessage   = new NodeGreetingMessage(NodeType.Publisher);
            var serializedMessage = greetingMessage.Serialize();

            Assert.AreEqual(1, serializedMessage[1]);
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
                using (var socket = new TestStreamSocket(mem))
                {
                    var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                    var message = new NodeGreetingMessage(NodeType.Responder);
                    mem.Write(message.Serialize(), 0, message.Serialize().Length);
                    mem.Position = 0;

                    Assert.Throws <RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet <NodeType> {
                        NodeType.Requester
                    }));
                }
        }
        public void VerifyRemoteGreetingAsync_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
                using (var socket = new TestStreamSocket(mem))
                {
                    var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                    var message = new NodeGreetingMessage(NodeType.Responder);
                    mem.Write(message.Serialize(), 0, message.Serialize().Length);
                    mem.Position = 0;

                    negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                        NodeType.Responder
                    }, CancellationToken.None).Wait();
                }
        }
        public void Serialize_ProtocolVersion()
        {
            var greetingMessage = new NodeGreetingMessage(NodeType.Publisher);
            var serializedMessage = greetingMessage.Serialize();

            Assert.AreEqual(1, serializedMessage[1]);
        }
        public void Serialize_NodeType()
        {
            var greetingMessage = new NodeGreetingMessage(NodeType.Subscriber);
            var serializedMessage = greetingMessage.Serialize();

            Assert.AreEqual((byte)NodeType.Subscriber, serializedMessage[2]);
        }
        public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            try
            {
                await negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                    NodeType.Requester
                }, CancellationToken.None);

                Assert.Fail();
            }
            catch (RedFoxProtocolException)
            {
                Assert.Pass();
            }
        }
        public void Serialize_NodeType()
        {
            var greetingMessage   = new NodeGreetingMessage(NodeType.Subscriber);
            var serializedMessage = greetingMessage.Serialize();

            Assert.AreEqual((byte)NodeType.Subscriber, serializedMessage[2]);
        }
        public void Deserialize_NoteType_Success()
        {
            var originalMessage     = new NodeGreetingMessage(NodeType.Subscriber);
            var serialized          = originalMessage.Serialize();
            var deserializedMessage = NodeGreetingMessage.DeserializeWithoutLength(serialized, 1);

            Assert.AreEqual(originalMessage.NodeType, deserializedMessage.NodeType);
        }
Ejemplo n.º 12
0
        public void Deserialize_NoteType_Success()
        {
            var originalMessage = new NodeGreetingMessage(NodeType.Subscriber);
            var serialized = originalMessage.Serialize();
            var deserializedMessage = NodeGreetingMessage.DeserializeWithoutLength(serialized, 1);

            Assert.AreEqual(originalMessage.NodeType, deserializedMessage.NodeType);
        }
Ejemplo n.º 13
0
        public void Serialize_message_size()
        {
            var greetingMessage = new NodeGreetingMessage(NodeType.Publisher);
            var serializedMessage = greetingMessage.Serialize();

            const int expectedSize = 3;
            Assert.AreEqual(expectedSize, serializedMessage.Length);
            Assert.AreEqual(expectedSize - 1, serializedMessage[0]);
        }
        public void Serialize_message_size()
        {
            var greetingMessage   = new NodeGreetingMessage(NodeType.Publisher);
            var serializedMessage = greetingMessage.Serialize();

            const int expectedSize = 3;

            Assert.AreEqual(expectedSize, serializedMessage.Length);
            Assert.AreEqual(expectedSize - 1, serializedMessage[0]);
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            Assert.Throws<RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet<NodeType> { NodeType.Requester }));
        }
        public void WriteGreetingAsync_writes_full_NodeGreetingMessage()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);

            var message = new NodeGreetingMessage(NodeType.Responder);
            negotiator.WriteGreetingAsync(message, CancellationToken.None).Wait();

            Assert.AreEqual(message.Serialize(), blockingQueue.Dequeue(CancellationToken.None).RawMessage);
        }
        public void WriteGreetingAsync_writes_full_NodeGreetingMessage()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);

            var message = new NodeGreetingMessage(NodeType.Responder);

            negotiator.WriteGreetingAsync(message, CancellationToken.None).Wait();

            Assert.AreEqual(message.Serialize(), blockingQueue.Dequeue(CancellationToken.None).RawMessage);
        }
        public void WriteGreetingAsync_writes_full_NodeGreetingMessage()
        {
            using (var mem = new MemoryStream())
            using (var socket = new TestStreamSocket(mem))
            {
                var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                var message = new NodeGreetingMessage(NodeType.Responder);
                negotiator.WriteGreetingAsync(message, CancellationToken.None).Wait();

                Assert.AreEqual(message.Serialize(), mem.ToArray());
            }
        }
        public void WriteGreetingAsync_writes_full_NodeGreetingMessage()
        {
            using (var mem = new MemoryStream())
                using (var socket = new TestStreamSocket(mem))
                {
                    var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                    var message = new NodeGreetingMessage(NodeType.Responder);
                    negotiator.WriteGreetingAsync(message, CancellationToken.None).Wait();

                    Assert.AreEqual(message.Serialize(), mem.ToArray());
                }
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            Assert.Throws <RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet <NodeType> {
                NodeType.Requester
            }));
        }
        public void VerifyRemoteGreetingAsync_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                NodeType.Responder
            }, CancellationToken.None).Wait();
        }
        public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            using (var mem = new MemoryStream())
            using (var socket = new TestStreamSocket(mem))
            {
                var negotiator = new NodeGreetingMessageStreamSocketNegotiator(socket);

                var message = new NodeGreetingMessage(NodeType.Responder);
                mem.Write(message.Serialize(), 0, message.Serialize().Length);
                mem.Position = 0;

                try
                {
                    await negotiator.VerifyRemoteGreetingAsync(new HashSet<NodeType> { NodeType.Requester }, CancellationToken.None);
                    Assert.Fail();
                }
                catch (RedFoxProtocolException)
                {
                    Assert.Pass();
                }
            }
        }
        public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            try
            {
                await negotiator.VerifyRemoteGreetingAsync(new HashSet<NodeType> { NodeType.Requester }, CancellationToken.None);
                Assert.Fail();
            }
            catch (RedFoxProtocolException)
            {
                Assert.Pass();
            }
        }
        public void VerifyRemoteGreetingAsync_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            negotiator.VerifyRemoteGreetingAsync(new HashSet<NodeType> { NodeType.Responder }, CancellationToken.None).Wait();
        }