public void ConnectivityBaseTest(int listeningPort) { ICommunicationChannel clientHandler = Substitute.For <ICommunicationChannel>(); ServiceLocator.Current.GetInstance <IUnityContainer>().RegisterInstance(clientHandler); ApplicationContext applicationContext = new ApplicationContext() { Container = (UnityContainer)ServiceLocator.Current.GetInstance <IUnityContainer>() }; ILoggerService loggerService = Substitute.For <ILoggerService>(); IBufferManagerFactory bufferManagerFactory = Substitute.For <IBufferManagerFactory>(); ServerCommunicationServiceBase communicationHub = new TcpCommunicationService(applicationContext, loggerService, bufferManagerFactory, null, null); IPEndPoint communicationEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), listeningPort); SocketListenerSettings settings = new SocketListenerSettings(1, 100, communicationEndPoint); communicationHub.Init(settings); communicationHub.Start(); TcpClient tcpClient = new TcpClient(); tcpClient.Connect(communicationEndPoint.Address, communicationEndPoint.Port); Assert.True(tcpClient.Connected); }
public void TestMethod1() { var data = new byte[] { 1, 2, }; var a = new TcpCommunicationService(); var b = new TcpCommunicationService(); a.StartListener("127.0.0.1", 1988); b.StartClient("127.0.0.1", 1988); while (a.GetConnectCount() != 1 || b.GetConnectCount() != 1) { } var recvA = false; var recvB = false; var recvedA = false; var recvedB = false; a.Receive += (s, e) => { if (e.Buffer.SequenceEqual(data)) { recvA = true; } recvedA = true; }; b.Receive += (s, e) => { if (e.Buffer.SequenceEqual(data)) { recvB = true; } recvedB = true; }; a.Send(data); b.Send(data); while (recvedA == false || recvedB == false) { } Assert.IsTrue(recvA); Assert.IsTrue(recvB); }