Beispiel #1
0
        public static int Main(string[] args)
        {
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            _serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
            _serverAppDomain.Load("Zyan.Communication");

            CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
            {
                EventServer server = EventServer.Instance;
            });

            _serverAppDomain.DoCallBack(serverWork);

            //TcpCustomClientProtocolSetup protocol = new TcpCustomClientProtocolSetup(true);
            MsmqClientProtocolSetup protocol = new MsmqClientProtocolSetup();

            //_connection = new ZyanConnection("tcp://*****:*****@"msmq://private$/reqchannel/EventTest", 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("Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCall.DoSomething();
            if (_callbackCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("SingleCall Callback Test passed.");
            }

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

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

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

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

            RequestResponseResult requestResponseResult = new RequestResponseResult();

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

            Thread.Sleep(1000);

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

            _connection.Dispose();
            EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;

            locator.GetEventServer().Dispose();
            AppDomain.Unload(_serverAppDomain);

            if (successCount == 9)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            _serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
            _serverAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());

            CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
            {
                var server = EventServer.Instance;
                if (server != null)
                {
                    Console.WriteLine("Event server started.");
                }
            });

            _serverAppDomain.DoCallBack(serverWork);

            // Subscriptions are tested synchronously
            ZyanSettings.LegacyBlockingSubscriptions = true;

            // Test IPC Binary
            int ipcBinaryTestResult = IpcBinaryTest.RunTest();

            Console.WriteLine("Passed: {0}", ipcBinaryTestResult == 0);

            // Test TCP Binary
            int tcpBinaryTestResult = TcpBinaryTest.RunTest();

            Console.WriteLine("Passed: {0}", tcpBinaryTestResult == 0);

            // Test TCP Custom
            int tcpCustomTestResult = TcpCustomTest.RunTest();

            Console.WriteLine("Passed: {0}", tcpCustomTestResult == 0);

            // Test TCP Duplex
            int tcpDuplexTestResult = TcpDuplexTest.RunTest();

            Console.WriteLine("Passed: {0}", tcpDuplexTestResult == 0);

            // Test HTTP Custom
            int httpCustomTestResult = HttpCustomTest.RunTest();

            Console.WriteLine("Passed: {0}", httpCustomTestResult == 0);

            // Test NULL Channel
            const string nullChannelResultSlot = "NullChannelResult";

            _serverAppDomain.DoCallBack(new CrossAppDomainDelegate(() =>
            {
                int result = NullChannelTest.RunTest();
                AppDomain.CurrentDomain.SetData(nullChannelResultSlot, result);
            }));
            var nullChannelTestResult = Convert.ToInt32(_serverAppDomain.GetData(nullChannelResultSlot));

            Console.WriteLine("Passed: {0}", nullChannelTestResult == 0);

            // Stop the event server
            EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;

            locator.GetEventServer().Dispose();
            Console.WriteLine("Event server stopped.");

            if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS)
            {
                // Mono/Windows bug:
                // AppDomain.Unload freezes in Mono under Windows if tests for
                // System.Runtime.Remoting.Channels.Tcp.TcpChannel were executed.
                AppDomain.Unload(_serverAppDomain);
                Console.WriteLine("Server AppDomain unloaded.");
            }

            if (ipcBinaryTestResult + tcpBinaryTestResult + tcpCustomTestResult + tcpDuplexTestResult + httpCustomTestResult + nullChannelTestResult == 0)
            {
                Console.WriteLine("All tests passed.");
                return(0);
            }

            return(1);
        }