Exemple #1
0
        public void ShallReleaseParentIfNotUsed(string serverAddress, string clientAddress)
        {
            //Arrange
            var parentObjectId = "1";
            var childObjectId  = "2";

            var parent = new HostedObject();

            parent.Child = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
            {
                server.Add <IContract>(parentObjectId, parent);
                server.Add(childObjectId, parent.Child);

                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    var parentRemoteObject = client.Connect <IContract>(parentObjectId);

                    var childRemoteObject = parentRemoteObject.Child;
                    childRemoteObject.Value = 5;
                    Assert.AreEqual(5, childRemoteObject.Value);

                    var parentWeakRef = new WeakReference(parentRemoteObject);
                    var childWeakRef  = new WeakReference(childRemoteObject);

                    Assert.IsTrue(parentWeakRef.IsAlive);
                    Assert.IsTrue(childWeakRef.IsAlive);

                    //Act
                    parentRemoteObject = null;
                    GC.Collect();

                    //Assert
                    Assert.AreEqual(5, childRemoteObject.Value);
                    Assert.IsNull(parentRemoteObject);
                    Assert.IsFalse(parentWeakRef.IsAlive);
                    Assert.IsTrue(childWeakRef.IsAlive);

                    //Act
                    childRemoteObject = null;
                    GC.Collect();

                    //Assert
                    Assert.IsNull(childRemoteObject);
                    Assert.IsFalse(parentWeakRef.IsAlive);
                    Assert.IsFalse(childWeakRef.IsAlive);
                }
            }
        }
        public void ShallRethrowExceptionWhenCalledRemoteMethodsTwoWay(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.TwoWayWithExceptionCalled);

                    //Act
                    var e = Assert.Catch <FaultException>(() => { remoteObject.CallTwoWayWithException("qwerty"); });

                    //Assert
                    Assert.IsTrue(hostedObject.TwoWayWithExceptionCalled);
                    Assert.IsInstanceOf <FaultException>(e);
                    Assert.AreEqual("qwerty", e.Message);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, e.ExceptionType);
                }
        }
        public void ShallCallReturnValue(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.TwoWayCalled);

                    //Act
                    var result = remoteObject.CallTwoWayWithReturnValue(1, true, "qwerty", 123.123);

                    //Assert
                    Assert.IsTrue(hostedObject.TwoWayWithReturnValueCalled);
                    AssertComplexParameter(new ComplexParameter
                    {
                        A = 1,
                        B = true,
                        S = "qwerty",
                        D = 123.123
                    }, result);
                }
        }
        public void ShallUseDefaultParametersIfAny(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.TwoWayCalled);

                    //Act
                    remoteObject.CallTwoWayWithDefaultParameter();

                    //Assert
                    Assert.AreEqual(new[] { 5 }, hostedObject.Parameters);

                    //Act
                    remoteObject.CallTwoWayWithDefaultParameter(6);

                    //Assert
                    Assert.AreEqual(new[] { 6 }, hostedObject.Parameters);
                }
        }
        public MeasurementResult Measure()
        {
            using (var remoteObjectServer = new EloquentServer($"{_scheme}://127.0.0.1:50000"))
                using (var remoteObjectClient = new EloquentClient($"{_scheme}://127.0.0.1:50000", $"{_scheme}://127.0.0.1:50001"))
                {
                    remoteObjectServer.Add <IBenchmarkObject>("endpoint1", new BenchmarkObject());

                    var benchmarkObj = remoteObjectClient.Connect <IBenchmarkObject>("endpoint1");

                    var parameter = new Parameter
                    {
                        Parameter1 = new InnerParameter1
                        {
                            Parameter2 = new InnerParameter2
                            {
                                Parameter3 = new InnerParameter3
                                {
                                    IntValue    = 123,
                                    BoolValue   = false,
                                    DoubleValue = 123.123,
                                    StringValue = "123"
                                }
                            }
                        }
                    };

                    return(MeasurementResult.Measure($"EloquentObjects: One-way calls with parameter with {_scheme}", () =>
                    {
                        for (var i = 0; i < _iterations; i++)
                        {
                            benchmarkObj.OneWayCallWithParameter(parameter);
                        }
                    }));
                }
        }
        public void ShallHideExceptionForOneWaySetters(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);
                    hostedObject.Value  = 0;
                    hostedObject.Action = () => throw new InvalidOperationException("qwerty");

                    //Act
                    remoteObject.OneWaySet = 5;
                    //Assert
                    Assert.AreEqual(0, hostedObject.Value);

                    //Act
                    remoteObject.OneWayGetSet = 5;
                    //Assert
                    Assert.AreEqual(0, hostedObject.Value);
                }
        }
Exemple #7
0
        public void ShallReleaseIfNotUsed(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
            {
                server.Add <IContract>(objectId, hostedObject);

                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    var remoteObject = client.Connect <IContract>(objectId);
                    remoteObject.Value = 5;
                    Assert.AreEqual(5, remoteObject.Value);

                    var weakRef = new WeakReference(remoteObject);

                    Assert.IsTrue(weakRef.IsAlive);

                    //Act
                    remoteObject = null;
                    GC.Collect();

                    //Assert
                    Assert.IsNull(remoteObject);
                    Assert.IsFalse(weakRef.IsAlive);
                }
            }
        }
Exemple #8
0
        public void ShallKeepReferenceIfSubscribed(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
            {
                server.Add <IContract>(objectId, hostedObject);

                WeakReference weakRef;

                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    var remoteObject = client.Connect <IContract>(objectId);
                    remoteObject.ValueChanged += RemoteObjectOnValueChanged;

                    weakRef = new WeakReference(remoteObject);

                    Assert.IsTrue(weakRef.IsAlive);

                    //Act
                    remoteObject = null;
                    GC.Collect();

                    Assert.IsNull(remoteObject);
                    Assert.IsTrue(weakRef.IsAlive);
                }

                GC.Collect();

                Assert.IsFalse(weakRef.IsAlive);
            }
        }
        public void ShallGetValuesForProperties(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    //Act
                    hostedObject.Value        = 5;
                    hostedObject.ComplexValue = new ComplexParameter
                    {
                        A = 1,
                        B = true,
                        D = 123.123,
                        S = "qwerty"
                    };

                    //Assert
                    Assert.AreEqual(5, remoteObject.Get);
                    Assert.AreEqual(5, remoteObject.GetSet);
                    Assert.AreEqual(5, remoteObject.OneWayGetSet);
                    AssertComplexParameter(new ComplexParameter
                    {
                        A = 1,
                        B = true,
                        D = 123.123,
                        S = "qwerty"
                    }, remoteObject.ComplexGetSet);

                    //Act
                    hostedObject.Value        = 7;
                    hostedObject.ComplexValue = new ComplexParameter
                    {
                        A = 2,
                        B = false,
                        D = 234.234,
                        S = "asd"
                    };

                    //Assert
                    Assert.AreEqual(7, remoteObject.Get);
                    Assert.AreEqual(7, remoteObject.GetSet);
                    Assert.AreEqual(7, remoteObject.OneWayGetSet);
                    AssertComplexParameter(new ComplexParameter
                    {
                        A = 2,
                        B = false,
                        D = 234.234,
                        S = "asd"
                    }, remoteObject.ComplexGetSet);
                }
        }
Exemple #10
0
        public MeasurementResult Measure()
        {
            using (var remoteObjectServer = new EloquentServer($"{_scheme}://127.0.0.1:50000", new EloquentSettings
            {
                HeartBeatMs = 1000,
                MaxHeartBeatLost = 5,
                ReceiveTimeout = 1000,
                SendTimeout = 1000
            }))
            {
                var benchmarkObject = new BenchmarkObject();
                remoteObjectServer.Add <IBenchmarkObject>("endpoint1", benchmarkObject);

                //Create Clients
                var clients     = new EloquentClient[_numberOfEventClients];
                var connections = new IBenchmarkObject[_numberOfEventClients];

                var autoResetEvent = new AutoResetEvent(false);
                for (var i = 0; i < _numberOfEventClients; i++)
                {
                    clients[i] = new EloquentClient($"{_scheme}://127.0.0.1:50000", $"{_scheme}://127.0.0.1:6000{i}", new EloquentSettings
                    {
                        HeartBeatMs    = 1000,
                        SendTimeout    = 1000,
                        ReceiveTimeout = 10000
                    });
                    connections[i] = clients[i].Connect <IBenchmarkObject>("endpoint1");
                    connections[i].EventOccurred += last =>
                    {
                        if (last)
                        {
                            autoResetEvent.Set();
                        }
                    };
                }

                var result = MeasurementResult.Measure($"EloquentObjects: Events with {_scheme}", () =>
                {
                    benchmarkObject.StartEvents(_iterations / _numberOfEventClients);

                    autoResetEvent.WaitOne();
                });

                //Dispose clients
                for (var i = 0; i < _numberOfEventClients; i++)
                {
                    clients[i].Dispose();
                }

                return(result);
            }
        }
        public void ShallRaiseExceptionForTwoWaySetters(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);
                    hostedObject.Value  = 0;
                    hostedObject.Action = () => throw new InvalidOperationException("qwerty");

                    //Act
                    var exception = Assert.Catch <FaultException>(() => { remoteObject.Set = 5; });
                    //Assert
                    Assert.AreEqual(0, hostedObject.Value);
                    Assert.AreEqual("qwerty", exception.Message);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, exception.ExceptionType);

                    //Act
                    exception = Assert.Catch <FaultException>(() => { remoteObject.GetSet = 5; });
                    //Assert
                    Assert.AreEqual(0, hostedObject.Value);
                    Assert.AreEqual("qwerty", exception.Message);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, exception.ExceptionType);

                    //Act
                    exception = Assert.Catch <FaultException>(() =>
                    {
                        remoteObject.ComplexGetSet = new ComplexParameter {
                            A = 5
                        };
                    });
                    //Assert
                    Assert.AreEqual(0, hostedObject.Value);
                    Assert.AreEqual("qwerty", exception.Message);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, exception.ExceptionType);

                    //Act
                    ComplexParameter complex = null;
                    exception = Assert.Catch <FaultException>(() => { complex = remoteObject.ComplexGetSet; });
                    //Assert
                    Assert.AreEqual(null, complex);
                    Assert.AreEqual("qwerty", exception.Message);
                    Assert.AreEqual(typeof(InvalidOperationException).FullName, exception.ExceptionType);
                }
        }
Exemple #12
0
        public void ShallRaiseEventWithoutParameters(string serverAddress, string client1Address, string client2Address)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client1 = new EloquentClient(serverAddress, client1Address))
                    using (var client2 = new EloquentClient(serverAddress, client2Address))
                    {
                        server.Add <IContract>(objectId, hostedObject);

                        var remoteObject1 = client1.Connect <IContract>(objectId);
                        var remoteObject2 = client2.Connect <IContract>(objectId);

                        var noParameterEvent1Called = false;
                        var noParameterEvent2Called = false;

                        var autoResetEvent1 = new AutoResetEvent(false);
                        var autoResetEvent2 = new AutoResetEvent(false);

                        remoteObject1.NoParameterEvent += () =>
                        {
                            noParameterEvent1Called = true;
                            autoResetEvent1.Set();
                        };
                        remoteObject2.NoParameterEvent += () =>
                        {
                            noParameterEvent2Called = true;
                            autoResetEvent2.Set();
                        };

                        //Act
                        Assert.IsFalse(noParameterEvent1Called);
                        Assert.IsFalse(noParameterEvent2Called);
                        hostedObject.SendNoParametersEvent();

                        autoResetEvent1.WaitOne(2000);
                        autoResetEvent2.WaitOne(2000);

                        //Assert
                        Assert.IsTrue(noParameterEvent1Called);

                        //TODO: Failed during long run
                        Assert.IsTrue(noParameterEvent2Called);
                    }
        }
Exemple #13
0
        public void ShallThrowWhenCalledRemovedObject(string serverAddress, string client1Address)
        {
            //Arrange
            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, client1Address))
                {
                    var objectHost = server.Add <IContract>("objectId", new HostedObject());

                    var remoteObject = client.Connect <IContract>("objectId");
                    objectHost.Dispose();

                    //Act
                    var exception = Assert.Catch <Exception>(() => { remoteObject.Value = 5; });

                    //Assert
                    Assert.AreEqual("Object with id 'objectId' is not hosted on server.", exception.Message);
                }
        }
Exemple #14
0
        public MeasurementResult Measure()
        {
            using (var remoteObjectServer = new EloquentServer($"{_scheme}://127.0.0.1:50000"))
                using (var remoteObjectClient = new EloquentClient($"{_scheme}://127.0.0.1:50000", $"{_scheme}://127.0.0.1:50001"))
                {
                    remoteObjectServer.Add <IBenchmarkObject>("endpoint1", new BenchmarkObject());

                    var benchmarkObj = remoteObjectClient.Connect <IBenchmarkObject>("endpoint1");

                    return(MeasurementResult.Measure($"EloquentObjects: One-way calls with {_scheme}", () =>
                    {
                        for (var i = 0; i < _iterations; i++)
                        {
                            benchmarkObj.OneWayCall();
                        }
                    }));
                }
        }
Exemple #15
0
        public void ShallHostAgain(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
            {
                server.Add <IContract>(objectId, hostedObject);

                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    var remoteObject = client.Connect <IContract>(objectId);

                    //Act
                    remoteObject.Value = 5;

                    //Assert
                    Assert.AreEqual(5, remoteObject.Value);
                }
            }

            using (var server = new EloquentServer(serverAddress))
            {
                server.Add <IContract>(objectId, hostedObject);

                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    var remoteObject = client.Connect <IContract>(objectId);

                    //Assert
                    Assert.AreEqual(5, remoteObject.Value);

                    //Act
                    remoteObject.Value = 6;

                    //Assert
                    Assert.AreEqual(6, remoteObject.Value);
                }
            }
        }
        public void ShallCallRemoteMethodsTwoWay(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.TwoWayCalled);

                    //Act
                    remoteObject.CallTwoWay();

                    //Assert
                    Assert.IsTrue(hostedObject.TwoWayCalled);
                }
        }
        public void ShallHideExceptionWhenCalledRemoteMethodsOneWay(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.OneWayWithExceptionCalled);

                    //Act
                    remoteObject.CallOneWayWithException();
                    hostedObject.WaitCallCompleted();

                    //Assert
                    Assert.IsTrue(hostedObject.OneWayWithExceptionCalled);
                }
        }
        public void ShallPassRemoteObjectAsParameter(string serverAddress, string clientAddress)
        {
            //Arrange
            var parent = new Parent();
            var child  = new Child();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IParent>("parent", parent);
                    server.Add <IChild>("child", child);

                    var remoteParent = client.Connect <IParent>("parent");
                    var remoteChild  = client.Connect <IChild>("child");

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild1(remoteChild);
                    //Assert
                    Assert.AreEqual(0, parent.A);
                    Assert.AreEqual(null, parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild2(5, remoteChild);
                    //Assert
                    Assert.AreEqual(5, parent.A);
                    Assert.AreEqual(null, parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild3(7, remoteChild, "qwerty");
                    //Assert
                    Assert.AreEqual(7, parent.A);
                    Assert.AreEqual("qwerty", parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild4(remoteChild);
                    parent.WaitNotificationReceived();
                    //Assert
                    Assert.AreEqual(7, parent.A);
                    Assert.AreEqual("qwerty", parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild5(5, remoteChild);
                    parent.WaitNotificationReceived();
                    //Assert
                    Assert.AreEqual(5, parent.A);
                    Assert.AreEqual("qwerty", parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;

                    //Act
                    remoteParent.SetChild6(0, remoteChild, null);
                    parent.WaitNotificationReceived();
                    //Assert
                    Assert.AreEqual(0, parent.A);
                    Assert.AreEqual(null, parent.B);
                    Assert.AreSame(child, parent.Value);

                    parent.Value = null;
                }
        }
 public IObjectHost <T> Add <T>(string objectId, T obj, SynchronizationContext synchronizationContext = null) where T : class
 {
     return(_eloquentServer.Add(objectId, obj, synchronizationContext));
 }
Exemple #20
0
        public void ShallRaiseEventWithParameters(string serverAddress, string client1Address, string client2Address)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client1 = new EloquentClient(serverAddress, client1Address))
                    using (var client2 = new EloquentClient(serverAddress, client2Address))
                    {
                        server.Add <IContract>(objectId, hostedObject);

                        var remoteObject1 = client1.Connect <IContract>(objectId);
                        var remoteObject2 = client2.Connect <IContract>(objectId);

                        object[] parameters1 = null;
                        object[] parameters2 = null;

                        var autoResetEvent1 = new AutoResetEvent(false);
                        var autoResetEvent2 = new AutoResetEvent(false);

                        remoteObject1.EventWithParameters += (i, b, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
                        {
                            parameters1 = new object[]
                            {
                                i, b, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
                            };

                            autoResetEvent1.Set();
                        };

                        remoteObject2.EventWithParameters += (i, b, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
                        {
                            parameters2 = new object[]
                            {
                                i, b, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
                            };

                            autoResetEvent2.Set();
                        };

                        //Act
                        Assert.IsNull(parameters1);
                        Assert.IsNull(parameters2);

                        //Act
                        var complexParameter1 = new ComplexParameter
                        {
                            A = 5,
                            B = true,
                            D = 543.543,
                            S = "asd"
                        };
                        var complexParameter2 = new ComplexParameter
                        {
                            A = 6,
                            B = false,
                            D = 345.345,
                            S = "zxc"
                        };
                        var complexParameter3 = new ComplexParameter
                        {
                            A = 5,
                            B = true,
                            D = 543.543,
                            S = "123"
                        };

                        hostedObject.SendEventWithParameters(
                            1,
                            false,
                            "qwerty",
                            123.123,
                            complexParameter1,
                            new[] { 1, 2, 3 },
                            new[] { false, true, false },
                            new[] { "123", "qwe", "zxc" },
                            new[] { 1.123, 2.234, 3.345 },
                            new[]
                        {
                            complexParameter2,
                            complexParameter3,
                        });

                        autoResetEvent1.WaitOne(2000);
                        autoResetEvent2.WaitOne(2000);

                        Assert.NotNull(parameters1);
                        Assert.NotNull(parameters2);

                        Assert.AreEqual(1, parameters1[0]);
                        Assert.AreEqual(false, parameters1[1]);
                        Assert.AreEqual("qwerty", parameters1[2]);
                        Assert.AreEqual(123.123, parameters1[3]);
                        AssertComplexParameter(complexParameter1, (ComplexParameter)parameters1[4]);
                        Assert.AreEqual(new[] { 1, 2, 3 }, parameters1[5]);
                        Assert.AreEqual(new[] { false, true, false }, parameters1[6]);
                        Assert.AreEqual(new[] { "123", "qwe", "zxc" }, parameters1[7]);
                        Assert.AreEqual(new[] { 1.123, 2.234, 3.345 }, parameters1[8]);
                        Assert.AreEqual(2, ((ComplexParameter[])parameters1[9]).Length);
                        AssertComplexParameter(complexParameter2, ((ComplexParameter[])parameters1[9])[0]);
                        AssertComplexParameter(complexParameter3, ((ComplexParameter[])parameters1[9])[1]);


                        Assert.AreEqual(1, parameters2[0]);
                        Assert.AreEqual(false, parameters2[1]);
                        Assert.AreEqual("qwerty", parameters2[2]);
                        Assert.AreEqual(123.123, parameters2[3]);
                        AssertComplexParameter(complexParameter1, (ComplexParameter)parameters2[4]);
                        Assert.AreEqual(new[] { 1, 2, 3 }, parameters2[5]);
                        Assert.AreEqual(new[] { false, true, false }, parameters2[6]);
                        Assert.AreEqual(new[] { "123", "qwe", "zxc" }, parameters2[7]);
                        Assert.AreEqual(new[] { 1.123, 2.234, 3.345 }, parameters2[8]);
                        Assert.AreEqual(2, ((ComplexParameter[])parameters2[9]).Length);
                        AssertComplexParameter(complexParameter2, ((ComplexParameter[])parameters2[9])[0]);
                        AssertComplexParameter(complexParameter3, ((ComplexParameter[])parameters2[9])[1]);
                    }
        }
        public void ShallCallRemoteMethodsOneWayWithParameters(string serverAddress, string clientAddress)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client = new EloquentClient(serverAddress, clientAddress))
                {
                    server.Add <IContract>(objectId, hostedObject);

                    var remoteObject = client.Connect <IContract>(objectId);

                    Assert.IsFalse(hostedObject.OneWayWithParameterCalled);

                    //Act
                    var complexParameter1 = new ComplexParameter
                    {
                        A = 5,
                        B = true,
                        D = 543.543,
                        S = "asd"
                    };
                    var complexParameter2 = new ComplexParameter
                    {
                        A = 6,
                        B = false,
                        D = 345.345,
                        S = "zxc"
                    };
                    var complexParameter3 = new ComplexParameter
                    {
                        A = 5,
                        B = true,
                        D = 543.543,
                        S = "123"
                    };

                    remoteObject.CallOneWayWithParameters(
                        1,
                        false,
                        "qwerty",
                        123.123,
                        complexParameter1,
                        new[] { 1, 2, 3 },
                        new[] { false, true, false },
                        new[] { "123", "qwe", "zxc" },
                        new[] { 1.123, 2.234, 3.345 },
                        new[]
                    {
                        complexParameter2,
                        complexParameter3,
                    });
                    hostedObject.WaitCallCompleted();

                    //Assert
                    Assert.IsTrue(hostedObject.OneWayWithParameterCalled);

                    Assert.AreEqual(1, hostedObject.Parameters[0]);
                    Assert.AreEqual(false, hostedObject.Parameters[1]);
                    Assert.AreEqual("qwerty", hostedObject.Parameters[2]);
                    Assert.AreEqual(123.123, hostedObject.Parameters[3]);
                    AssertComplexParameter(complexParameter1, (ComplexParameter)hostedObject.Parameters[4]);
                    Assert.AreEqual(new[] { 1, 2, 3 }, hostedObject.Parameters[5]);
                    Assert.AreEqual(new[] { false, true, false }, hostedObject.Parameters[6]);
                    Assert.AreEqual(new[] { "123", "qwe", "zxc" }, hostedObject.Parameters[7]);
                    Assert.AreEqual(new[] { 1.123, 2.234, 3.345 }, hostedObject.Parameters[8]);
                    Assert.AreEqual(2, ((ComplexParameter[])hostedObject.Parameters[9]).Length);
                    AssertComplexParameter(complexParameter2, ((ComplexParameter[])hostedObject.Parameters[9])[0]);
                    AssertComplexParameter(complexParameter3, ((ComplexParameter[])hostedObject.Parameters[9])[1]);

                    //Act
                    hostedObject.OneWayWithParameterCalled = false;
                    hostedObject.Parameters = null;

                    Assert.IsFalse(hostedObject.OneWayWithParameterCalled);

                    remoteObject.CallOneWayWithParameters(
                        2,
                        true,
                        null,
                        234.234,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null);
                    hostedObject.WaitCallCompleted();

                    //Assert
                    Assert.IsTrue(hostedObject.OneWayWithParameterCalled);

                    Assert.AreEqual(2, hostedObject.Parameters[0]);
                    Assert.AreEqual(true, hostedObject.Parameters[1]);
                    Assert.AreEqual(null, hostedObject.Parameters[2]);
                    Assert.AreEqual(234.234, hostedObject.Parameters[3]);
                    Assert.AreEqual(null, hostedObject.Parameters[4]);
                    Assert.AreEqual(null, hostedObject.Parameters[5]);
                    Assert.AreEqual(null, hostedObject.Parameters[6]);
                    Assert.AreEqual(null, hostedObject.Parameters[7]);
                }
        }
Exemple #22
0
        public void ShallRaiseRegularEventWithClientAsSender(string serverAddress, string client1Address,
                                                             string client2Address)
        {
            //Arrange
            var objectId = "obj";

            var hostedObject = new HostedObject();

            using (var server = new EloquentServer(serverAddress))
                using (var client1 = new EloquentClient(serverAddress, client1Address))
                    using (var client2 = new EloquentClient(serverAddress, client2Address))
                    {
                        server.Add <IContract>(objectId, hostedObject);

                        var remoteObject1 = client1.Connect <IContract>(objectId);
                        var remoteObject2 = client2.Connect <IContract>(objectId);
                        var remoteObject3 = client2.Connect <IContract>(objectId);
                        Assert.AreNotSame(remoteObject1, remoteObject2);
                        Assert.AreNotSame(remoteObject2, remoteObject3);

                        object           sender1 = null;
                        object           sender2 = null;
                        object           sender3 = null;
                        object           sender4 = null;
                        ComplexParameter args1   = null;
                        ComplexParameter args2   = null;
                        ComplexParameter args3   = null;
                        ComplexParameter args4   = null;

                        var autoResetEvent1 = new AutoResetEvent(false);
                        var autoResetEvent2 = new AutoResetEvent(false);
                        var autoResetEvent3 = new AutoResetEvent(false);
                        var autoResetEvent4 = new AutoResetEvent(false);

                        remoteObject1.RegularEvent += (s, args) =>
                        {
                            sender1 = s;
                            args1   = args;
                            autoResetEvent1.Set();
                        };
                        remoteObject2.RegularEvent += (s, args) =>
                        {
                            sender2 = s;
                            args2   = args;
                            autoResetEvent2.Set();
                        };
                        remoteObject3.RegularEvent += (s, args) =>
                        {
                            sender3 = s;
                            args3   = args;
                            autoResetEvent3.Set();
                        };
                        remoteObject3.RegularEvent += (s, args) =>
                        {
                            sender4 = s;
                            args4   = args;
                            autoResetEvent4.Set();
                        };

                        var complexParameter1 = new ComplexParameter
                        {
                            A = 5,
                            B = true,
                            D = 543.543,
                            S = "asd"
                        };

                        Assert.IsNull(sender1);
                        Assert.IsNull(sender2);
                        Assert.IsNull(sender3);
                        Assert.IsNull(sender4);
                        Assert.IsNull(args1);
                        Assert.IsNull(args2);
                        Assert.IsNull(args3);
                        Assert.IsNull(args4);

                        //Act
                        hostedObject.SendRegularEvent(complexParameter1);

                        autoResetEvent1.WaitOne(2000);
                        autoResetEvent2.WaitOne(2000);
                        autoResetEvent3.WaitOne(2000);
                        autoResetEvent4.WaitOne(2000);

                        //Assert
                        Assert.AreSame(remoteObject1, sender1);
                        Assert.AreSame(remoteObject2, sender2);
                        Assert.AreSame(remoteObject3, sender3);
                        Assert.AreSame(remoteObject3, sender4);
                        AssertComplexParameter(complexParameter1, args1);
                        AssertComplexParameter(complexParameter1, args2);
                        AssertComplexParameter(complexParameter1, args3);
                        AssertComplexParameter(complexParameter1, args4);
                    }
        }