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)); } }
public void TestDispose_Twise_Harmless() { using (var environment = new InProcTestEnvironment()) { var target = new RpcClient(_loopbackEndPoint, environment.Configuration, null); target.Dispose(); target.Dispose(); } }
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); } } }
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 ); } } }
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 ); } }
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)); } }
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); } }
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 ); } }
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()); } }
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); } }
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)); } }
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 ) ); } } }
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)); } } }
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); } }
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")); } } }
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" ) ); } } }
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); } }
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)); } } }
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))); } } }
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)); } } }
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)); } } }
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 ) ); } } }
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() ); } }
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 ); } }
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 ) ); } }
public void TestDispose_Twise_Harmless() { using ( var environment = new InProcTestEnvironment() ) { var target = new RpcClient( _loopbackEndPoint, environment.Configuration, null ); target.Dispose(); target.Dispose(); } }
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 ) ); } } }
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 ) ) ); } } }
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 ) ); } } }
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 ); } }
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 ) ); } } }
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 ) ); } }