示例#1
0
        public void ShouldReceiveOnNetworkWhenSent()
        {
            var network = InProcessNetwork.Create();
            var parent  = network.Local;
            var channel = network.GetChannel <string>();

            string received = string.Empty;

            channel.Received += (sender, s) => received = s;
            parent.Send(typeof(string).AssemblyQualifiedName, NetworkChannel <string> .Serialize("Hello world"), null);
            received.ShouldEqual("Hello world");
        }
示例#2
0
        public void ShouldNotReceiveOnNetworkWhenSentIfISentIt()
        {
            var network = InProcessNetwork.Create();
            var channel = network.GetChannel <string>();
            var parent  = network.Local;

            string received = string.Empty;

            channel.Received += (sender, s) => received = s;
            parent.SendToNetwork(network, typeof(string).ToString(), NetworkChannel <string> .Serialize("Hello world"), parent.Address);
            received.ShouldBeEmpty();
        }
示例#3
0
        public void ShouldSendComplexType()
        {
            var data = new ComplexTypeForTest {
                IntProperty = 5, StringField = "Hello World"
            };
            var network = InProcessNetwork.Create();
            var channel = network.GetChannel <ComplexTypeForTest>();
            var parent  = network.Local;

            ComplexTypeForTest received = null;

            channel.Received += (sender, s) => received = s;
            parent.Send(typeof(ComplexTypeForTest).AssemblyQualifiedName, NetworkChannel <ComplexTypeForTest> .Serialize(data), null);
            received.IntProperty.ShouldEqual(data.IntProperty);
            received.StringField.ShouldEqual(data.StringField);
        }
示例#4
0
        public void ShouldReceiveOnChildWhenSent()
        {
            var childAddress = new NodeAddress("child");
            var localAddress = new NodeAddress("local");
            var data         = NetworkChannel <string> .Serialize("Hello world");

            var child = new Mock <INode>();

            child.Setup(x => x.Address).Returns(childAddress);
            var network = new Mock <INetwork>();

            network.Setup(x => x.FindOrDefault(null)).Returns((INode)null);
            network.Setup(x => x.FindOrCreate(childAddress)).Returns(child.Object);
            network.Setup(x => x.FindOrDefault(childAddress)).Returns(child.Object);

            var local = new Node(localAddress, network.Object);

            local.Connect(childAddress);
            local.Send(typeof(string).ToString(), data, null);

            child.Verify(x => x.Send(typeof(string).ToString(), data, It.IsAny <NodeAddress>()));
        }
示例#5
0
        public void ShouldNotReceiveOnChildWhenSentToNetworkFromChild()
        {
            var childAddress = new NodeAddress("child");
            var localAddress = new NodeAddress("local");
            var data         = "Hello world";

            var child = new Mock <INode>();

            child.Setup(x => x.Address).Returns(childAddress);
            var network = new Mock <INetwork>();

            network.Setup(x => x.FindOrDefault(null)).Returns((INode)null);
            network.Setup(x => x.FindOrCreate(childAddress)).Returns(child.Object);
            network.Setup(x => x.FindOrDefault(childAddress)).Returns(child.Object);

            var local = new Node(localAddress, network.Object);

            local.Connect(childAddress);
            local.SendToNetwork(network.Object, typeof(string).ToString(), NetworkChannel <string> .Serialize(data), childAddress);

            child.Verify(x => x.Send(typeof(string).ToString(), It.IsAny <byte[]>(), It.IsAny <NodeAddress>()), Times.Never());
        }
示例#6
0
        public void ShouldReceiveOnParentWhenSent()
        {
            var parentAddress = new NodeAddress("parent");
            var localAddress  = new NodeAddress("local")
            {
                Parent = parentAddress
            };
            var data = NetworkChannel <string> .Serialize("Hello world");

            var parent = new Mock <INode>();

            parent.Setup(x => x.Address).Returns(parentAddress);
            var network = new Mock <INetwork>();

            network.Setup(x => x.FindOrDefault(null)).Returns((INode)null);
            network.Setup(x => x.FindOrCreate(parentAddress)).Returns(parent.Object);
            network.Setup(x => x.FindOrDefault(parentAddress)).Returns(parent.Object);

            var local = new Node(localAddress, network.Object);

            local.Send(typeof(string).ToString(), data, null);

            parent.Verify(x => x.Send(typeof(string).ToString(), data, It.IsAny <NodeAddress>()), Times.Once());
        }