예제 #1
0
        public void Send_And_Receive_Standard_Request()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                Assert.IsTrue(t1.TotalPendingOutgoingMessages == 1);
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                t2.SendResponse(new CalculateResponse()
                {
                    Sum = receivedRequest.A + receivedRequest.B
                }, e.Message.Token);
            };

            var request = new CalculateRequest()
            {
                A = 10, B = 15
            };
            var response = t1.SendRequest <CalculateRequest, CalculateResponse>(request, new ResonanceRequestConfig()
            {
                LoggingMode = ResonanceMessageLoggingMode.Content
            });

            t1.Dispose(true);
            t2.Dispose(true);

            Assert.AreEqual(response.Sum, request.A + request.B);
        }
예제 #2
0
        public void Send_Standard_Message()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            bool received = false;

            t2.MessageReceived += (s, e) =>
            {
                Assert.IsTrue(t1.TotalPendingOutgoingMessages == 0);
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                Assert.IsTrue(receivedRequest.A == 10 && receivedRequest.B == 15);
                received = true;
            };

            t1.Send(new CalculateRequest()
            {
                A = 10, B = 15
            });

            Thread.Sleep(500);

            Assert.IsTrue(received);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #3
0
        public void Send_Standard_Message_With_Error_ACK_And_No_Reporting_Does_Not_Throws_Exception()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            bool received = false;

            t2.MessageReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                Assert.IsTrue(receivedRequest.A == 10 && receivedRequest.B == 15);
                received = true;

                throw new Exception("Test Error");
            };

            t1.Send(new CalculateRequest()
            {
                A = 10, B = 15
            }, new ResonanceMessageConfig()
            {
                RequireACK = true
            });

            Thread.Sleep(200);

            Assert.IsTrue(received);
            Assert.IsTrue(t1.TotalPendingOutgoingMessages == 0);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #4
0
        public void Send_Object_Without_Expecting_Response()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                Assert.IsTrue(receivedRequest.A == 10);
            };

            var request = new CalculateRequest()
            {
                A = 10
            };

            for (int i = 0; i < 1000; i++)
            {
                t1.Send(new CalculateRequest()
                {
                    A = 10
                });
            }

            Assert.IsTrue(t1.TotalPendingOutgoingMessages == 0);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #5
0
        public void Send_And_Receive_Standard_Request_With_Compression()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Encoder.CompressionConfiguration.Enabled = true;
            t2.Encoder.CompressionConfiguration.Enabled = true;

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                t2.SendResponse(new CalculateResponse()
                {
                    Sum = receivedRequest.A + receivedRequest.B
                }, e.Message.Token);
            };

            var request = new CalculateRequest()
            {
                A = 10, B = 15
            };
            var response = t1.SendRequest <CalculateRequest, CalculateResponse>(request);

            t1.Dispose(true);
            t2.Dispose(true);

            Assert.AreEqual(response.Sum, request.A + request.B);
        }
예제 #6
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_DateTime_Property_Get_Set()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            DateTime date = DateTime.Now;

            proxy.DateProperty = date;

            var value = proxy.DateProperty;

            Assert.AreEqual(value.ToString(), date.ToString());

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #7
0
        public void NamedPipes_Adapter_Writing_Reading()
        {
            if (IsRunningOnAzurePipelines)
            {
                return;
            }

            ResonanceTransporter t1 = new ResonanceTransporter(new NamedPipesAdapter("Resonance"));
            ResonanceTransporter t2 = new ResonanceTransporter();

            ResonanceNamedPipesServer server = new ResonanceNamedPipesServer("Resonance");

            server.Start();
            server.ConnectionRequest += (x, e) =>
            {
                t2.Adapter = e.Accept();
                t2.Connect();
            };

            t1.Connect();

            while (t2.State != ResonanceComponentState.Connected)
            {
                Thread.Sleep(10);
            }

            TestUtils.Read_Write_Test(this, t1, t2, false, 1000, 5);

            server.Dispose();
        }
예제 #8
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_No_Input_Method_Async()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            String s = proxy.GetStringNoInputAsync().GetAwaiter().GetResult();

            Assert.AreEqual(s, "Test");

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #9
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Transient_Service_3()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            bool funcExecuted = false;

            t2.RegisterService <ITestService, TestService>(RpcServiceCreationType.Transient, () =>
            {
                funcExecuted = true;
                return(new TestService());
            });

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            var response = proxy.Calculate(request);

            response = proxy.Calculate(request);

            Assert.IsTrue(funcExecuted);
            Assert.IsTrue(TestService.InstanceCount == 2);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #10
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Request_Async_Method()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            var response = proxy.CalculateAsync(request).GetAwaiter().GetResult();

            Assert.AreEqual(response.Sum, request.A + request.B);

            t2.UnregisterService <ITestService>();

            Assert.ThrowsException <ResonanceResponseException>(() =>
            {
                proxy.CalculateAsync(request).GetAwaiter().GetResult();
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #11
0
        public void Request_Timeout_Throws_Exception()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                Thread.Sleep(1000);
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                t2.SendResponse(new CalculateResponse()
                {
                    Sum = receivedRequest.A + receivedRequest.B
                }, e.Message.Token);
            };

            var request = new CalculateRequest()
            {
                A = 10, B = 15
            };

            Assert.ThrowsException <TimeoutException>(() =>
            {
                var response = t1.SendRequest <CalculateRequest, CalculateResponse>(request, new ResonanceRequestConfig()
                {
                    Timeout = TimeSpan.FromSeconds(0.5)
                });
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #12
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Singleton_Service_2()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RegisterService <ITestService, TestService>(RpcServiceCreationType.Singleton);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            var response = proxy.Calculate(request);

            response = proxy.Calculate(request);

            Assert.IsTrue(TestService.InstanceCount == 1);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #13
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Request_Method_With_Rpc_Attribute_Timeout_Throws_Exception()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            Assert.ThrowsException <TimeoutException>(() =>
            {
                var response = proxy.CalculateWithAttributeShortTimeout(request);
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #14
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Message_Method_Primitive_Int32()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            int s = proxy.GetInt32Value(10);

            Assert.AreEqual(s, 10);

            t2.UnregisterService <ITestService>();

            Assert.ThrowsException <ResonanceResponseException>(() =>
            {
                proxy.GetStringValue("Test");
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #15
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Int32_Property_Get_Set()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            proxy.Int32Property = 100;

            int value = proxy.Int32Property;

            Assert.AreEqual(value, 100);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #16
0
        public void Tcp_Adapter_Writing_Reading()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new TcpAdapter(TcpAdapter.GetLocalIPAddress(), 9999));
            ResonanceTransporter t2 = new ResonanceTransporter();

            ResonanceTcpServer server = new ResonanceTcpServer(9999);

            server.Start();
            server.ConnectionRequest += (x, e) =>
            {
                t2.Adapter = e.Accept();
                t2.Connect();
            };

            t1.Connect();

            while (t2.State != ResonanceComponentState.Connected)
            {
                Thread.Sleep(10);
            }

            TestUtils.Read_Write_Test(this, t1, t2, false, 1000, 5);

            server.Dispose();
        }
예제 #17
0
        public void Disconnection_Request()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (x, e) =>
            {
                t2.SendResponseAsync(new CalculateResponse(), e.Message.Token);
            };

            t1.SendRequest <CalculateRequest, CalculateResponse>(new CalculateRequest());

            t2.Disconnect();

            Thread.Sleep(1000);

            Assert.IsTrue(t1.State == ResonanceComponentState.Failed);
            Assert.IsTrue(t1.FailedStateException is ResonanceConnectionClosedException);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #18
0
        public void Message_Handler_ACK()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            bool received = false;

            t2.RegisterMessageHandler <CalculateRequest>((t, message) =>
            {
                received = true;
            });

            t1.Send(new CalculateRequest()
            {
                A = 10, B = 15
            }, new ResonanceMessageConfig()
            {
                RequireACK = true
            });

            Thread.Sleep(500);

            Assert.IsTrue(received);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #19
0
        public void KeepAlive_Auto_Response()
        {
            if (IsRunningOnAzurePipelines)
            {
                return;
            }

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.DefaultRequestTimeout = TimeSpan.FromSeconds(0.5);

            t1.KeepAliveConfiguration.Enabled = true;
            t1.KeepAliveConfiguration.Retries = 1;
            t1.KeepAliveConfiguration.Delay   = TimeSpan.Zero;
            t1.KeepAliveConfiguration.FailTransporterOnTimeout = true;
            t1.KeepAliveConfiguration.Interval = TimeSpan.FromSeconds(0.5);

            t2.KeepAliveConfiguration.Enabled            = false;
            t2.KeepAliveConfiguration.EnableAutoResponse = true;

            t1.Connect();
            t2.Connect();

            Thread.Sleep((int)(t1.DefaultRequestTimeout.Add(t1.KeepAliveConfiguration.Interval).TotalMilliseconds * 2));
            Assert.IsTrue(t1.State == ResonanceComponentState.Connected);

            t1.Dispose(true);
            t2.Dispose(true);

            Thread.Sleep(1000);
        }
예제 #20
0
        public void Decoder_Exception_Throws_Exception()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Decoder = new CorruptedDecoder();

            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest; //Should be calculate response...
                t2.SendResponse(new CalculateResponse(), e.Message.Token);
            };

            var request = new CalculateRequest();

            Assert.ThrowsException <CorruptedDecoderException>(() =>
            {
                var response = t1.SendRequest <CalculateRequest, CalculateResponse>(request);
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #21
0
        public void Transporter_Failes_With_Adapter()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.FailsWithAdapter = true;
            t1.Connect();

            var request = new CalculateRequest()
            {
                A = 10, B = 15
            };


            try
            {
                var response = t1.SendRequest(request);
                Assert.Fail("Expected an exception.");
            }
            catch { }

            Assert.IsTrue(t1.State == ResonanceComponentState.Failed);
            Assert.IsTrue(t1.FailedStateException.InnerException is KeyNotFoundException);
            Assert.IsTrue(t1.FailedStateException.InnerException == t1.Adapter.FailedStateException);

            t1.Dispose(true);
        }
예제 #22
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Multi_Parameter_Void_Method()
        {
            Reset();
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            proxy.CalculateMultiParameterVoid(10, 5);

            Assert.AreEqual(receivedRequest.A, 10);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #23
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Object_Property_Get_Set()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            CalculateRequest request = new CalculateRequest()
            {
                A = 1, B = 2
            };

            Assert.IsTrue(proxy.CalculateRequestProperty == null);

            proxy.CalculateRequestProperty = request;

            var value = proxy.CalculateRequestProperty;

            Assert.AreEqual(value.A + value.B, request.A + request.B);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #24
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Request_Method_With_Rpc_Attribute_Timeout()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            var response = proxy.CalculateWithAttributeTimeout(request); //The timeout is 10 seconds while the service method delay is 6 and default timeout is 5 or 2.

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #25
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_String_Property_Get_Set()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            proxy.StringProperty = "Test";

            String value = proxy.StringProperty;

            Assert.AreEqual(value, "Test");

            t2.UnregisterService <ITestService>();

            Assert.ThrowsException <ResonanceResponseException>(() =>
            {
                proxy.StringProperty = "Test";
            });

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #26
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Request_Method_Throws_Exception()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            Assert.ThrowsException <ResonanceResponseException>(() =>
            {
                proxy.CalculateThrows(request);
            }, "Test Error");

            t2.UnregisterService <ITestService>();

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #27
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Singleton_Service_1()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.Connect();
            t2.Connect();

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            var request = new CalculateRequest()
            {
                A = 10, B = 5
            };

            var response = proxy.Calculate(request);

            Assert.AreEqual(response.Sum, request.A + request.B);

            t1.Dispose(true);
            t2.Dispose(true);
        }
예제 #28
0
        public void Send_And_Receive_Standard_Request_With_Encryption()
        {
            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.CryptographyConfiguration.Enabled = true;
            t2.CryptographyConfiguration.Enabled = true;

            t1.Connect();
            t2.Connect();

            t2.RequestReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                t2.SendResponse(new CalculateResponse()
                {
                    Sum = receivedRequest.A + receivedRequest.B
                }, e.Message.Token);
            };

            t1.RequestReceived += (s, e) =>
            {
                CalculateRequest receivedRequest = e.Message.Object as CalculateRequest;
                t1.SendResponse(new CalculateResponse()
                {
                    Sum = receivedRequest.A + receivedRequest.B
                }, e.Message.Token);
            };

            var request = new CalculateRequest()
            {
                A = 10, B = 15
            };

            CalculateResponse response1 = null;
            CalculateResponse response2 = null;

            Task.Factory.StartNew(() =>
            {
                response1 = t2.SendRequest <CalculateRequest, CalculateResponse>(request);
                response1 = t2.SendRequest <CalculateRequest, CalculateResponse>(request);
            }).GetAwaiter().GetResult();

            Task.Factory.StartNew(() =>
            {
                response2 = t1.SendRequest <CalculateRequest, CalculateResponse>(request);
                response2 = t1.SendRequest <CalculateRequest, CalculateResponse>(request);
            }).GetAwaiter().GetResult();


            Thread.Sleep(4000);


            t1.Dispose(true);
            t2.Dispose(true);

            Assert.AreEqual(response1.Sum, request.A + request.B);
            Assert.AreEqual(response2.Sum, request.A + request.B);
        }
예제 #29
0
        public void Transporter_Builder_With_WebRTC_Adapter()
        {
            IResonanceTransporter signaling = new ResonanceTransporter();

            IResonanceTransporter webRtcAdapter = ResonanceTransporter.Builder
                                                  .Create()
                                                  .WithWebRTCAdapter()
                                                  .WithSignalingTransporter(signaling)
                                                  .WithRole(WebRTCAdapterRole.Connect)
                                                  .WithIceServer("some ice server")
                                                  .WithTranscoding <JsonEncoder, JsonDecoder>()
                                                  .NoKeepAlive()
                                                  .WithEncryption()
                                                  .WithCompression()
                                                  .Build();

            Assert.IsNotNull(webRtcAdapter);
            Assert.IsInstanceOfType(webRtcAdapter.Adapter, typeof(WebRTCAdapter));
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).IceServers[0].Url == "some ice server");
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).Role == WebRTCAdapterRole.Connect);
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).SignalingTransporter == signaling);
            Assert.IsInstanceOfType(webRtcAdapter.Encoder, typeof(JsonEncoder));
            Assert.IsInstanceOfType(webRtcAdapter.Decoder, typeof(JsonDecoder));
            Assert.IsFalse(webRtcAdapter.KeepAliveConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.CryptographyConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.Encoder.CompressionConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.Decoder.CompressionConfiguration.Enabled);

            webRtcAdapter = ResonanceTransporter.Builder
                            .Create()
                            .WithWebRTCAdapter()
                            .WithSignalingTransporter(signaling)
                            .WithOfferRequest(new WebRTCOfferRequest(), "token")
                            .WithIceServer("some ice server")
                            .WithTranscoding <JsonEncoder, JsonDecoder>()
                            .NoKeepAlive()
                            .WithEncryption()
                            .WithCompression()
                            .Build();

            Assert.IsNotNull(webRtcAdapter);
            Assert.IsInstanceOfType(webRtcAdapter.Adapter, typeof(WebRTCAdapter));
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).IceServers[0].Url == "some ice server");
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).Role == WebRTCAdapterRole.Accept);
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).InitializedByOffer);
            Assert.IsTrue((webRtcAdapter.Adapter as WebRTCAdapter).SignalingTransporter == signaling);
            Assert.IsInstanceOfType(webRtcAdapter.Encoder, typeof(JsonEncoder));
            Assert.IsInstanceOfType(webRtcAdapter.Decoder, typeof(JsonDecoder));
            Assert.IsFalse(webRtcAdapter.KeepAliveConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.CryptographyConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.Encoder.CompressionConfiguration.Enabled);
            Assert.IsTrue(webRtcAdapter.Decoder.CompressionConfiguration.Enabled);
        }
예제 #30
0
파일: RPC_TST.cs 프로젝트: royben/Resonance
        public void Service_Handles_Event_Late_Bound()
        {
            Reset();

            ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST"));
            ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST"));

            t1.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;
            t2.MessageAcknowledgmentBehavior = ResonanceMessageAckBehavior.ReportErrors;

            var testService = new TestService();

            t2.RegisterService <ITestService, TestService>(testService);

            var proxy = t1.CreateClientProxy <ITestService>();

            List <double> sums = new List <double>();

            proxy.CalculateResponseEvent += (x, response) =>
            {
                sums.Add(response.Sum);
            };

            //Connect after event registration...
            t2.Connect(); //Connect the event receiver first because event registration happens right after connection...
            t1.Connect();

            Thread.Sleep(1000);

            testService.RaiseCalculateResponseEvent(new CalculateResponse()
            {
                Sum = 1
            });
            testService.RaiseCalculateResponseEvent(new CalculateResponse()
            {
                Sum = 2
            });
            testService.RaiseCalculateResponseEvent(new CalculateResponse()
            {
                Sum = 3
            });

            TestHelper.WaitWhile(() => sums.Count < 3, TimeSpan.FromSeconds(5));

            Assert.AreEqual(sums[0], 1);
            Assert.AreEqual(sums[1], 2);
            Assert.AreEqual(sums[2], 3);

            t2.UnregisterService <ITestService>();

            t1.Dispose(true);
            t2.Dispose(true);
        }