示例#1
0
 public void HttpUrlValidation()
 {
     var protocol = new HttpCustomClientProtocolSetup();
     Assert.IsTrue(protocol.IsUrlValid("http://localhost:123/server"));
     Assert.IsTrue(protocol.IsUrlValid("http://www.example.com:8080/server"));
     Assert.IsTrue(protocol.IsUrlValid("http://127.0.0.1:8888/index"));
     Assert.IsTrue(protocol.IsUrlValid("http://[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("http://"));
     Assert.IsFalse(protocol.IsUrlValid("http://host/server"));
 }
示例#2
0
文件: Program.cs 项目: yallie/zyan
        private static ZyanConnection LoginAndConnect()
        {
            HttpCustomClientProtocolSetup protocol = new HttpCustomClientProtocolSetup(true);

            ZyanConnection connection = null;
            bool success = false;
            string message = string.Empty;

            while (!success)
            {
                LoginForm loginForm = new LoginForm();

                if (!string.IsNullOrEmpty(message))
                    loginForm.Message = message;

                DialogResult result = loginForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    Hashtable credentials = new Hashtable();
                    credentials.Add(AuthRequestMessage.CREDENTIAL_USERNAME, loginForm.UserName);
                    credentials.Add(AuthRequestMessage.CREDENTIAL_PASSWORD, loginForm.Password);

                    try
                    {
                        connection = new ZyanConnection("http://localhost:8081/EbcCalc", protocol, credentials, false, true);
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                    }
                }
                else
                    return null;
            }
            return connection;
        }
示例#3
0
        public static int RunTest()
        {
            var protocol = new HttpCustomClientProtocolSetup(true)
            {
                CompressionThreshold = 1, // compress data packets of any size
                CompressionMethod = CompressionMethod.DeflateStream
            };

            _connection = new ZyanConnection("http://localhost:8085/HttpCustomEventTest", 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("[HTTP Custom] Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCall.DoSomething();
            if (_callbackCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("[HTTP Custom] SingleCall Callback Test passed.");
            }

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

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

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

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

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

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

            Thread.Sleep(1000);

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

            _connection.Dispose();

            if (successCount == 9)
                return 0;
            else
                return 1;
        }