コード例 #1
0
        public void TestBeginNotifyEndNotify_Normal_ReachToServer()
        {
            var clientArgs = new object[] { 1, "3" };
            int result     = 0;

            using (var waitHandle = new ManualResetEventSlim())
                using (var environment = new InProcTestEnvironment(
                           (id, args) =>
                {
                    if (args[0] != 1 || args[1] != "3")
                    {
                        Interlocked.Exchange(ref result, _notificationInvalidArguments);
                    }
                    else
                    {
                        Interlocked.Exchange(ref result, _notificationIsOk);
                    }

                    waitHandle.Set();
                    return(MessagePackObject.Nil);
                }
                           ))
                    using (var target = environment.CreateClient())
                    {
                        var ar = target.BeginNotify("Test", clientArgs, null, null);
                        Assert.That(ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)));
                        target.EndNotify(ar);
                        Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));
                        Assert.That(Interlocked.CompareExchange(ref result, 0, 0), Is.EqualTo(_notificationIsOk));
                    }
        }
コード例 #2
0
 public void TestDispose_Twise_Harmless()
 {
     using (var environment = new InProcTestEnvironment())
     {
         var target = new RpcClient(_loopbackEndPoint, environment.Configuration, null);
         target.Dispose();
         target.Dispose();
     }
 }
コード例 #3
0
 public void TestConstructorRpcClient_ConfigurationAndSerializationContextIsNull_DefaultsAreUsed()
 {
     using (var environment = new InProcTestEnvironment())
     {
         using (RpcClient target = new RpcClient(environment.EndPoint, null, null))
         {
             Assert.That(target.SerializationContext, Is.Not.Null);
         }
     }
 }
コード例 #4
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestConstructorRpcClient_ConfigurationAndSerializationContextIsNull_DefaultsAreUsed()
		{
			using ( var environment = new InProcTestEnvironment() )
			{
				using ( RpcClient target = new RpcClient( environment.EndPoint, null, null ) )
				{
					Assert.That( target.SerializationContext, Is.Not.Null );
				}
			}
		}
コード例 #5
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestDispose_TransportDisposed()
		{
			using ( var environment = new InProcTestEnvironment() )
			{
				var target = new RpcClient( _loopbackEndPoint, environment.Configuration, null );
				target.EnsureConnected();
				target.Dispose();
				Assert.That( target.Transport.IsDisposed );
				Assert.That( target.TransportManager.IsDisposed );
			}
		}
コード例 #6
0
 public void TestBeginNotifyEndNotify_NetworkError_ExceptionOnBeginCall()
 {
     using (var environment = new InProcTestEnvironment())
         using (var target = environment.CreateClient())
         {
             target.EnsureConnected();
             (target.Transport as InProcClientTransport).DataSending += EmulateSocketError;
             var args = new object[] { 1, "3" };
             Assert.Catch <SocketException>(() => target.BeginNotify("Test", args, null, null));
         }
 }
コード例 #7
0
 public void TestDispose_TransportDisposed()
 {
     using (var environment = new InProcTestEnvironment())
     {
         var target = new RpcClient(_loopbackEndPoint, environment.Configuration, null);
         target.EnsureConnected();
         target.Dispose();
         Assert.That(target.Transport.IsDisposed);
         Assert.That(target.TransportManager.IsDisposed);
     }
 }
コード例 #8
0
ファイル: DynamicRpcProxyTest.cs プロジェクト: Indifer/Test
		public void TestDynamicInvocation_Success()
		{
			string arg = Guid.NewGuid().ToString();
			int messageId = Environment.TickCount % 1000;
			string methodName = "SomeMethod";
			using ( var environment = new InProcTestEnvironment( ( method, id, args ) => method == methodName && args[ 0 ].AsString() == arg ) )
			using ( dynamic target = new DynamicRpcProxy( environment.EndPoint, environment.Configuration ) )
			{
				MessagePackObject result = target.SomeMethod( arg );
				Assert.That( result == true );
			}
		}
コード例 #9
0
 public void TestCall_Normal_Returned()
 {
     using (var environment = new InProcTestEnvironment())
         using (var target = environment.CreateClient())
         {
             var args   = new object[] { 1, "3" };
             var result = target.Call("Test", args);
             // CallbackServer just returns args.
             Assert.That(result.AsList()[0] == 1, result.AsList()[0].ToString());
             Assert.That(result.AsList()[1] == "3", result.AsList()[1].ToString());
         }
 }
コード例 #10
0
        public void TestDynamicInvocation_Success()
        {
            string arg        = Guid.NewGuid().ToString();
            int    messageId  = Environment.TickCount % 1000;
            string methodName = "SomeMethod";

            using (var environment = new InProcTestEnvironment((method, id, args) => method == methodName && args[0].AsString() == arg))
                using (dynamic target = new DynamicRpcProxy(environment.EndPoint, environment.Configuration))
                {
                    MessagePackObject result = target.SomeMethod(arg);
                    Assert.That(result == true);
                }
        }
コード例 #11
0
 public void TestShutdown_TransportShutdownIsInitiated()
 {
     using (var environment = new InProcTestEnvironment())
         using (var target = new RpcClient(_loopbackEndPoint, environment.Configuration, null))
         {
             int isShutdownCompleted = 0;
             target.EnsureConnected();
             target.Transport.ShutdownCompleted += (sender, e) => Interlocked.Exchange(ref isShutdownCompleted, 1);
             target.Shutdown();
             Assert.That(target.Transport.IsClientShutdown);
             Assert.That(isShutdownCompleted, Is.EqualTo(1));
         }
 }
コード例 #12
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestConstructorRpcClient_Normal_SetPropertyAsIs()
		{
			using ( var environment = new InProcTestEnvironment() )
			{
				var configuration = RpcClientConfiguration.Default.Clone();
				configuration.TransportManagerProvider = conf => environment.ClientTransportManager;
				SerializationContext serializationContext = new SerializationContext();

				using ( RpcClient target = new RpcClient( environment.EndPoint, configuration, serializationContext ) )
				{
					Assert.That( target.SerializationContext, Is.SameAs( serializationContext ) );
				}
			}
		}
コード例 #13
0
        public void TestConstructorRpcClient_Normal_SetPropertyAsIs()
        {
            using (var environment = new InProcTestEnvironment())
            {
                var configuration = RpcClientConfiguration.Default.Clone();
                configuration.TransportManagerProvider = conf => environment.ClientTransportManager;
                SerializationContext serializationContext = new SerializationContext();

                using (RpcClient target = new RpcClient(environment.EndPoint, configuration, serializationContext))
                {
                    Assert.That(target.SerializationContext, Is.SameAs(serializationContext));
                }
            }
        }
コード例 #14
0
        public void TestNotify_RemoteError_NoEffect()
        {
            var clientArgs = new object[] { 1, "3" };

            using (var environment = new InProcTestEnvironment(
                       (id, args) =>
            {
                throw new RpcMethodInvocationException(RpcError.CallError, "Test");
            }
                       ))
                using (var target = environment.CreateClient())
                {
                    target.Notify("Test", clientArgs);
                }
        }
コード例 #15
0
 public void TestDynamicInvocation_ServerError()
 {
     using (var environment = new InProcTestEnvironment((method, id, args) => { throw new InvalidOperationException("DUMMY"); }))
         using (dynamic target = new DynamicRpcProxy(environment.EndPoint, environment.Configuration))
         {
             try
             {
                 target.SomeMethod();
                 Assert.Fail();
             }
             catch (RpcMethodInvocationException ex)
             {
                 Assert.That(ex.MethodName, Is.StringContaining("SomeMethod"));
                 Assert.That(ex.Message, Is.StringContaining("DUMMY"));
             }
         }
 }
コード例 #16
0
ファイル: DynamicRpcProxyTest.cs プロジェクト: Indifer/Test
		public void TestDynamicInvocation_ServerError()
		{
			using ( var environment = new InProcTestEnvironment( ( method, id, args ) => { throw new InvalidOperationException( "DUMMY" ); } ) )
			using ( dynamic target = new DynamicRpcProxy( environment.EndPoint, environment.Configuration ) )
			{
				try
				{
					target.SomeMethod();
					Assert.Fail();
				}
				catch ( RpcMethodInvocationException ex )
				{
					Assert.That( ex.MethodName, Is.StringContaining( "SomeMethod" ) );
					Assert.That( ex.Message, Is.StringContaining( "DUMMY" ) );
				}
			}
		}
コード例 #17
0
        public void TestBeginNotifyEndNotify_RemoteError_NoEffect()
        {
            var clientArgs = new object[] { 1, "3" };

            using (var environment = new InProcTestEnvironment(
                       (id, args) =>
            {
                throw new RpcMethodInvocationException(RpcError.CallError, "Test");
            }
                       ))
                using (var target = environment.CreateClient())
                {
                    var ar = target.BeginNotify("Test", clientArgs, null, null);
                    Assert.That(ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)));
                    target.EndNotify(ar);
                }
        }
コード例 #18
0
 public void TestCall_RemoteError_Thrown()
 {
     using (var environment = new InProcTestEnvironment(new RpcMethodInvocationException(RpcError.CallError, "Test")))
         using (var target = environment.CreateClient())
         {
             var args = new object[] { 1, "3" };
             try
             {
                 target.Call("Test", args);
                 Assert.Fail();
             }
             catch (RpcException ex)
             {
                 Assert.That(ex.RpcError.Identifier, Is.EqualTo(RpcError.CallError.Identifier));
             }
         }
 }
コード例 #19
0
        public void TestNotifyAsync_RemoteError_NoEffect()
        {
            var clientArgs = new object[] { 1, "3" };

            using (var environment = new InProcTestEnvironment(
                       (id, args) =>
            {
                throw new RpcMethodInvocationException(RpcError.CallError, "Test");
            }
                       ))
                using (var target = environment.CreateClient())
                {
                    using (var task = target.NotifyAsync("Test", clientArgs, null))
                    {
                        Assert.That(task.Wait(TimeSpan.FromSeconds(1)));
                    }
                }
        }
コード例 #20
0
 public void TestBeginCallEndCall_RemoteError_Thrown()
 {
     using (var environment = new InProcTestEnvironment(new RpcMethodInvocationException(RpcError.CallError, "Test")))
         using (var target = environment.CreateClient())
         {
             var args = new object[] { 1, "3" };
             try
             {
                 var ar = target.BeginCall("Test", args, null, null);
                 Assert.That(ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)));
                 target.EndCall(ar);
                 Assert.Fail();
             }
             catch (RpcException ex)
             {
                 Assert.That(ex.RpcError.Identifier, Is.EqualTo(RpcError.CallError.Identifier));
             }
         }
 }
コード例 #21
0
 public void TestCallAsync_RemoteError_Thrown()
 {
     using (var environment = new InProcTestEnvironment(new RpcMethodInvocationException(RpcError.CallError, "Test")))
         using (var target = environment.CreateClient())
         {
             var args = new object[] { 1, "3" };
             try
             {
                 var task = target.CallAsync("Test", args, null);
                 task.Wait();
                 Assert.Fail();
             }
             catch (AggregateException ex)
             {
                 var rpcException = ex.InnerException as RpcException;
                 Assert.That(rpcException, Is.Not.Null);
                 Assert.That(rpcException.RpcError.Identifier, Is.EqualTo(RpcError.CallError.Identifier));
             }
         }
 }
コード例 #22
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestBeginCallEndCall_RemoteError_Thrown()
		{
			using ( var environment = new InProcTestEnvironment( new RpcMethodInvocationException( RpcError.CallError, "Test" ) ) )
			using ( var target = environment.CreateClient() )
			{
				var args = new object[] { 1, "3" };
				try
				{
					var ar = target.BeginCall( "Test", args, null, null );
					Assert.That( ar.AsyncWaitHandle.WaitOne( TimeSpan.FromSeconds( 1 ) ) );
					target.EndCall( ar );
					Assert.Fail();
				}
				catch ( RpcException ex )
				{
					Assert.That( ex.RpcError.Identifier, Is.EqualTo( RpcError.CallError.Identifier ) );
				}
			}
		}
コード例 #23
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestBeginCallEndCall_Normal_Returned()
		{
			using ( var environment = new InProcTestEnvironment() )
			using ( var target = environment.CreateClient() )
			{
				var args = new object[] { 1, "3" };
				var ar = target.BeginCall( "Test", args, null, null );
				// CallbackServer just returns args.
				var result = target.EndCall( ar );
				Assert.That( result.AsList()[ 0 ] == 1, result.AsList()[ 0 ].ToString() );
				Assert.That( result.AsList()[ 1 ] == "3", result.AsList()[ 1 ].ToString() );
			}
		}
コード例 #24
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestNotify_RemoteError_NoEffect()
		{
			var clientArgs = new object[] { 1, "3" };
			using ( var environment = new InProcTestEnvironment(
				( id, args ) =>
				{
					throw new RpcMethodInvocationException( RpcError.CallError, "Test" );
				}
			) )
			using ( var target = environment.CreateClient() )
			{
				target.Notify( "Test", clientArgs );
			}
		}
コード例 #25
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestBeginNotifyEndNotify_Normal_ReachToServer()
		{
			var clientArgs = new object[] { 1, "3" };
			int result = 0;
			using ( var waitHandle = new ManualResetEventSlim() )
			using ( var environment = new InProcTestEnvironment(
				( id, args ) =>
				{
					if ( args[ 0 ] != 1 || args[ 1 ] != "3" )
					{
						Interlocked.Exchange( ref result, _notificationInvalidArguments );
					}
					else
					{
						Interlocked.Exchange( ref result, _notificationIsOk );
					}

					waitHandle.Set();
					return MessagePackObject.Nil;
				}
			) )
			using ( var target = environment.CreateClient() )
			{
				var ar = target.BeginNotify( "Test", clientArgs, null, null );
				Assert.That( ar.AsyncWaitHandle.WaitOne( TimeSpan.FromSeconds( 1 ) ) );
				target.EndNotify( ar );
				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );
				Assert.That( Interlocked.CompareExchange( ref result, 0, 0 ), Is.EqualTo( _notificationIsOk ) );
			}
		}
コード例 #26
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestDispose_Twise_Harmless()
		{
			using ( var environment = new InProcTestEnvironment() )
			{
				var target = new RpcClient( _loopbackEndPoint, environment.Configuration, null );
				target.Dispose();
				target.Dispose();
			}
		}
コード例 #27
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestCall_RemoteError_Thrown()
		{
			using ( var environment = new InProcTestEnvironment( new RpcMethodInvocationException( RpcError.CallError, "Test" ) ) )
			using ( var target = environment.CreateClient() )
			{
				var args = new object[] { 1, "3" };
				try
				{
					target.Call( "Test", args );
					Assert.Fail();
				}
				catch ( RpcException ex )
				{
					Assert.That( ex.RpcError.Identifier, Is.EqualTo( RpcError.CallError.Identifier ) );
				}
			}
		}
コード例 #28
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestNotifyAsync_RemoteError_NoEffect()
		{
			var clientArgs = new object[] { 1, "3" };
			using ( var environment = new InProcTestEnvironment(
				( id, args ) =>
				{
					throw new RpcMethodInvocationException( RpcError.CallError, "Test" );
				}
			) )
			using ( var target = environment.CreateClient() )
			{
				using ( var task = target.NotifyAsync( "Test", clientArgs, null ) )
				{
					Assert.That( task.Wait( TimeSpan.FromSeconds( 1 ) ) );
				}
			}
		}
コード例 #29
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestCallAsync_RemoteError_Thrown()
		{
			using ( var environment = new InProcTestEnvironment( new RpcMethodInvocationException( RpcError.CallError, "Test" ) ) )
			using ( var target = environment.CreateClient() )
			{
				var args = new object[] { 1, "3" };
				try
				{
					var task = target.CallAsync( "Test", args, null );
					task.Wait();
					Assert.Fail();
				}
				catch ( AggregateException ex )
				{
					var rpcException = ex.InnerException as RpcException;
					Assert.That( rpcException, Is.Not.Null );
					Assert.That( rpcException.RpcError.Identifier, Is.EqualTo( RpcError.CallError.Identifier ) );
				}
			}
		}
コード例 #30
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestBeginNotifyEndNotify_RemoteError_NoEffect()
		{
			var clientArgs = new object[] { 1, "3" };
			using ( var environment = new InProcTestEnvironment(
				( id, args ) =>
				{
					throw new RpcMethodInvocationException( RpcError.CallError, "Test" );
				}
			) )
			using ( var target = environment.CreateClient() )
			{
				var ar = target.BeginNotify( "Test", clientArgs, null, null );
				Assert.That( ar.AsyncWaitHandle.WaitOne( TimeSpan.FromSeconds( 1 ) ) );
				target.EndNotify( ar );
			}
		}
コード例 #31
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestShutdownAsync_TransportShutdownIsInitiated()
		{
			using ( var environment = new InProcTestEnvironment() )
			using ( var target = new RpcClient( _loopbackEndPoint, environment.Configuration, null ) )
			{
				int isShutdownCompleted = 0;
				target.EnsureConnected();
				target.Transport.ShutdownCompleted += ( sender, e ) => Interlocked.Exchange( ref isShutdownCompleted, 1 );
				using ( var task = target.ShutdownAsync() )
				{
					Assert.That( target.Transport.IsClientShutdown );
					Assert.That( task.Wait( TimeSpan.FromSeconds( 1 ) ) );
					Assert.That( isShutdownCompleted, Is.EqualTo( 1 ) );
				}
			}
		}
コード例 #32
0
ファイル: RpcClientTest.cs プロジェクト: Indifer/Test
		public void TestBeginNotifyEndNotify_NetworkError_ExceptionOnBeginCall()
		{
			using ( var environment = new InProcTestEnvironment() )
			using ( var target = environment.CreateClient() )
			{
				target.EnsureConnected();
				( target.Transport as InProcClientTransport ).DataSending += EmulateSocketError;
				var args = new object[] { 1, "3" };
				Assert.Catch<SocketException>( () => target.BeginNotify( "Test", args, null, null ) );
			}
		}