Entry point of MessagePack-RPC client.
Inheritance: IDisposable
示例#1
0
		public void TestEcho()
		{
			string mesage = "Hello, MsgPack-RPC!!";
			long timeStamp = MessagePackConvert.FromDateTime( DateTime.Now );
			using ( var server =
				CallbackServer.Create(
					( messageId, args ) =>
					{
						Assert.That( args, Is.Not.Null.And.Length.EqualTo( 2 ) );
						Assert.That( args[ 0 ].Equals( timeStamp ) );
						Assert.That( args[ 1 ].Equals( mesage ) );
						return args;
					},
					isDebugMode: true
				) )
			{
				server.Error += ( sender, e ) => Console.Error.WriteLine( "{0} Error:{1}", e.IsClientError ? "Client" : "Server", e.Exception );

				using ( var client = new RpcClient( new IPEndPoint( IPAddress.Loopback, CallbackServer.PortNumber ) ) )
				{
					var result = client.Call( "Echo", timeStamp, mesage );
					var asArray = result.AsList();
					Assert.That( asArray[ 0 ].Equals( timeStamp ) );
					Assert.That( asArray[ 1 ].Equals( mesage ) );
				}
			}
		}
示例#2
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 );
				}
			}
		}
示例#3
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 );
			}
		}
示例#4
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 ) );
				}
			}
		}
示例#5
0
		/// <summary>
		///		Initializes a new instance of the <see cref="DynamicRpcProxy"/> class.
		/// </summary>
		/// <param name="client">An underlying <see cref="RpcClient"/>.</param>
		/// <exception cref="ArgumentNullException">
		///		<paramref name="client"/> is <c>null</c>.
		/// </exception>
		public DynamicRpcProxy( RpcClient client )
		{
			if ( client == null )
			{
				throw new ArgumentNullException( "client" );
			}

			Contract.EndContractBlock();

			this._client = client;
		}
示例#6
0
		public void TestDispose_Twise_Harmless()
		{
			using ( var environment = new InProcTestEnvironment() )
			{
				var target = new RpcClient( _loopbackEndPoint, environment.Configuration, null );
				target.Dispose();
				target.Dispose();
			}
		}
示例#7
0
		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 ) );
				}
			}
		}