Ejemplo n.º 1
0
        public void ShouldConnect()
        {
            var xxxx = InProcessNetwork.Create("xxxx");

            var manager = new NetworkManager();

            InProcessNetwork.Register(manager);
            var connection = manager.ConnectTo(xxxx.Local.Address);

            connection.ShouldNotBeNull();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        public void ShouldReceiveOnParentNetworkWhenSent()
        {
            var parentNetwork = InProcessNetwork.Create();
            var childNetwork  = InProcessNetwork.Create("Child");
            var parentChannel = parentNetwork.GetChannel <string>();

            parentNetwork.Connect(childNetwork.Local.Address);
            var childChannel = childNetwork.GetChannel <string>();

            string received = string.Empty;

            parentChannel.Received += (sender, s) => received = s;
            childChannel.Send("Hello world");
            received.ShouldEqual("Hello world");
        }
Ejemplo n.º 5
0
        public void ShouldBeAbleToHaveMultipleChildren()
        {
            var parentNetwork = InProcessNetwork.Create();
            var parentNode    = parentNetwork.Local;
            var child1Network = InProcessNetwork.Create("child1");
            var child1        = child1Network.Local.Address;
            var child2Network = InProcessNetwork.Create("child2");
            var child2        = child2Network.Local.Address;

            parentNode.Connect(child1);
            parentNode.Connect(child2);

            parentNode.HasChild(child1).ShouldBeTrue();
            parentNode.HasChild(child2).ShouldBeTrue();
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void ShouldBeAbleToDisconnect()
        {
            var parentNetwork = InProcessNetwork.Create();
            var parent        = parentNetwork.Local;
            var childNetwork  = InProcessNetwork.Create("child");
            var child         = childNetwork.Local.Address;

            parent.Connect(child);
            parent.HasChild(child).ShouldBeTrue();

            var child1Node = parentNetwork.FindOrDefault(child);

            child1Node.Disconnect();

            parent.HasChild(child).ShouldBeFalse();
        }
Ejemplo n.º 8
0
        public void ShouldUpdateSecondNetworkWithConnection()
        {
            var network1 = InProcessNetwork.Create();
            var node1    = network1.Local;

            var network2 = InProcessNetwork.Create("network2");
            var node2    = network2.Local;

            node2.AdviseConnect(node1.Address);

            node1.HasChild(node2.Address).ShouldBeTrue();
            node2.HasParent.ShouldBeTrue();
            node2.Address.Parent.Matches(node1.Address).ShouldBeTrue();

            network1.FindOrDefault(node2.Address).HasParent.ShouldBeTrue();
            network2.FindOrDefault(node1.Address).ShouldNotBeNull();
        }
Ejemplo n.º 9
0
        public void ShouldIncludeAConnectedNodeName()
        {
            var manager = new NetworkManager();

            InProcessNetwork.Register(manager);

            var network1 = InProcessNetwork.Create("1");
            var node1    = network1.Local;

            var network2 = InProcessNetwork.Create("2");

            network2.Connect(network1.Local.Address);

            network1.Connections.ShouldContain(network2.Local.Address.AsString);

            network2.Connections.ShouldContain(network1.Local.Address.AsString);
        }
Ejemplo n.º 10
0
        public void ShouldBecomeChildWhenAskingToJoin()
        {
            var parentNetwork = InProcessNetwork.Create();
            var parentNode    = parentNetwork.Local;
            var childNetwork  = InProcessNetwork.Create("child");
            var child         = childNetwork.Local.Address;

            parentNode.Connect(child);

            parentNode.HasChild(child).ShouldBeTrue();
            child.Parent.Matches(parentNode.Address).ShouldBeTrue();

            var childNode = parentNetwork.FindOrDefault(child);

            childNode.HasParent.ShouldBeTrue();
            parentNode.IsConnected.ShouldBeTrue();
            childNode.IsConnected.ShouldBeTrue();
        }
Ejemplo n.º 11
0
        public void ShouldNotHaveSameNodeAppearingTwice()
        {
            var grandparentNetwork = InProcessNetwork.Create();
            var grandparentNode    = grandparentNetwork.Local;

            var parentNetwork = InProcessNetwork.Create("parent");
            var parent        = parentNetwork.Local.Address;
            var childNetwork  = InProcessNetwork.Create("child");
            var child         = childNetwork.Local.Address;

            grandparentNode.Connect(parent);
            var parentNode = parentNetwork.Local;

            parentNode.Connect(child);

            grandparentNode.Connect(child);
            grandparentNode.HasChild(child).ShouldBeTrue();
            parentNode.HasChild(child).ShouldBeFalse();
        }
Ejemplo n.º 12
0
        public void ShouldReceiveWhenSent()
        {
            var network      = InProcessNetwork.Create();
            var parent       = network.Local;
            var childNetwork = InProcessNetwork.Create("child");
            var child        = childNetwork.Local.Address;

            network.Connect(child);
            var channel = network.GetChannel <string>();

            //Call this to prevent test failure with Can't find constructor on type string
            var childChannel = childNetwork.GetChannel <string>();
            var childNode    = network.FindOrDefault(child);

            string received = string.Empty;

            childChannel.Received += (sender, s) => received = s;
            channel.Send("Hello world");
            received.ShouldEqual("Hello world");
        }
Ejemplo n.º 13
0
        public void ShouldBeAbleToDropNodeFromChainWithoutLosingGrandChildren()
        {
            var grandParentNetwork = InProcessNetwork.Create();
            var grandparentNode    = grandParentNetwork.Local;

            var parentNetwork = InProcessNetwork.Create("parent");
            var parent        = parentNetwork.Local.Address;
            var childNetwork  = InProcessNetwork.Create("child");
            var child         = childNetwork.Local.Address;

            grandparentNode.Connect(parent);
            var parentNode = //grandParentNetwork.FindOrCreate(parent);
                             parentNetwork.Local;

            parentNode.Connect(child);

            parentNode.Disconnect();
            grandparentNode.HasChild(parent).ShouldBeFalse();
            grandparentNode.HasChild(child).ShouldBeTrue();
        }
Ejemplo n.º 14
0
        public void ShouldNotHaveDuplicateChildren()
        {
            var parentNetwork = InProcessNetwork.Create("parent");
            var parent        = parentNetwork.Local.Address;
            var childNetwork  = InProcessNetwork.Create("child");
            var child         = childNetwork.Local.Address;

            var parentNode = parentNetwork.Local;

            parentNode.Connect(child);

            parentNode.IsConnected.ShouldBeTrue();
            parentNode.HasChild(child).ShouldBeTrue();
            ((NodeWithoutContract)parentNode).Children.Count.ShouldEqual(1);

            var childNode = childNetwork.Local;

            childNode.IsConnected.ShouldBeTrue();
            ((NodeWithoutContract)childNode).Children.Count.ShouldEqual(0);
        }
Ejemplo n.º 15
0
        public void ShouldBeAbleToChain()
        {
            var grandParentNetwork = InProcessNetwork.Create();
            var grandParent        = grandParentNetwork.Local;
            var parentNetwork      = InProcessNetwork.Create("Parent");
            var parent             = parentNetwork.Local.Address;
            var childNetwork       = InProcessNetwork.Create("Child");
            var child = childNetwork.Local.Address;

            grandParent.Connect(parent);

            var parentNode = grandParentNetwork.FindOrDefault(parent);

            parentNode.Connect(child);

            grandParent.HasChild(parent).ShouldBeTrue();
            parentNetwork.Local.HasChild(child).ShouldBeTrue();

            // but local representation doesn't know about grandparent relationship
            parentNode.HasChild(child).ShouldBeFalse();
        }
Ejemplo n.º 16
0
        public void ShouldReceiveOnAllChildNetworksWhenSent()
        {
            var parentNetwork = InProcessNetwork.Create();
            var parentNode    = parentNetwork.Local;
            var parentChannel = parentNetwork.GetChannel <string>();
            var childANetwork = InProcessNetwork.Create("ChildANetwork");
            var childANode    = childANetwork.Local;
            var childAChannel = childANetwork.GetChannel <string>();
            var childBNetwork = InProcessNetwork.Create("ChildBNetwork");
            var childBNode    = childBNetwork.Local;
            var childBChannel = childBNetwork.GetChannel <string>();

            parentNetwork.Connect(childANode.Address);
            parentNetwork.Connect(childBNode.Address);

            string receivedA = string.Empty;
            string receivedB = string.Empty;

            childAChannel.Received += (sender, s) => receivedA = s;
            childBChannel.Received += (sender, s) => receivedB = s;
            parentChannel.Send("Hello world");
            receivedA.ShouldEqual("Hello world");
            receivedB.ShouldEqual("Hello world");
        }
Ejemplo n.º 17
0
        public void ShouldHaveNoParent()
        {
            var network = InProcessNetwork.Create();

            network.Local.HasParent.ShouldBeFalse();
        }