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"); }
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(); }
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); }
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>())); }
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()); }
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()); }