Exemplo n.º 1
0
        public static int RunTest()
        {
            var protocol = new TcpCustomClientProtocolSetup(true)
            {
                CompressionThreshold = 1, // compress data packets of any size
                CompressionMethod = CompressionMethod.LZF
            };

            _connection = new ZyanConnection("tcp://localhost:8083/TcpCustomEventTest", protocol);
            _proxySingleton = _connection.CreateProxy<IEventComponentSingleton>();
            _proxySingleCall = _connection.CreateProxy<IEventComponentSingleCall>();
            _proxyCallbackSingleton = _connection.CreateProxy<ICallbackComponentSingleton>();
            _proxyCallbackSingleCall = _connection.CreateProxy<ICallbackComponentSingleCall>();
            _proxyRequestResponseSingleCall = _connection.CreateProxy<IRequestResponseCallbackSingleCall>();

            int successCount = 0;

            _proxyCallbackSingleton.Out_Callback = CallBackSingleton;
            _proxyCallbackSingleCall.Out_Callback = CallBackSingleCall;

            _proxyCallbackSingleton.DoSomething();
            if (_callbackCountSingleton == 1)
            {
                successCount++;
                Console.WriteLine("[TCP Custom] Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCall.DoSomething();
            if (_callbackCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("[TCP Custom] SingleCall Callback Test passed.");
            }

            RegisterEvents();
            if (_registrationsSingleton == _proxySingleton.Registrations)
                successCount++;
            if (_registrationsSingleCall == _proxySingleCall.Registrations)
                successCount++;

            _proxySingleton.TriggerEvent();
            if (_firedCountSingleton == 1)
            {
                successCount++;
                Console.WriteLine("[TCP Custom] Singleton Event Test passed.");
            }

            _proxySingleCall.TriggerEvent();
            if (_firedCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("[TCP Custom] SingleCall Event Test passed.");
            }

            UnregisterEvents();
            if (_registrationsSingleton == _proxySingleton.Registrations)
                successCount++;
            if (_registrationsSingleCall == _proxySingleCall.Registrations)
                successCount++;

            RequestResponseResult requestResponseResult = new RequestResponseResult("TCP Custom");

            _proxyRequestResponseSingleCall.DoRequestResponse("Success", requestResponseResult.ReceiveResponseSingleCall);

            Thread.Sleep(1000);

            if (requestResponseResult.Count == 1)
                successCount++;

            _connection.Dispose();

            if (successCount == 9)
                return 0;
            else
                return 1;
        }
Exemplo n.º 2
0
        public void CreateDisposeAndRecreateConnectionUsingTcpSimplexChannel()
        {
            string url = "tcp://localhost:8085/RecreateClientConnectionTestHost_TcpSimplex";
            var protocol = new TcpCustomClientProtocolSetup(true);

            using (var connection = new ZyanConnection(url, protocol))
            {
                var proxy1 = connection.CreateProxy<ISampleServer>("SampleServer");
                Assert.AreEqual("Hallo", proxy1.Echo("Hallo"));
                proxy1 = null;
            }

            using (var connection = new ZyanConnection(url, protocol))
            {
                var proxy2 = connection.CreateProxy<ISampleServer>("SampleServer");
                Assert.AreEqual("Hallo", proxy2.Echo("Hallo"));
            }
        }
Exemplo n.º 3
0
 public void TcpCustomUrlValidation()
 {
     var protocol = new TcpCustomClientProtocolSetup();
     Assert.IsTrue(protocol.IsUrlValid("tcp://localhost:123/server"));
     Assert.IsTrue(protocol.IsUrlValid("tcp://www.example.com:8080/server"));
     Assert.IsTrue(protocol.IsUrlValid("tcp://127.0.0.1:8888/index"));
     Assert.IsTrue(protocol.IsUrlValid("tcp://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index"));
     Assert.IsFalse(protocol.IsUrlValid(null));
     Assert.IsFalse(protocol.IsUrlValid(string.Empty));
     Assert.IsFalse(protocol.IsUrlValid("tcp://"));
     Assert.IsFalse(protocol.IsUrlValid("tcp://host/server"));
 }