public void TestOnCompleted_CompletedSynchronouly_True_SetTrue() { object owner = new object(); var target = new RequestMessageAsyncResult( owner, 1, null, null ); target.OnCompleted( CreateContext(), null, true ); Assert.That( ( target as IAsyncResult ).CompletedSynchronously, Is.True ); }
public void TestOnCompleted_ErrorIsSet() { object owner = new object(); var target = new RequestMessageAsyncResult( owner, 1, null, null ); var error = new Exception(); target.OnCompleted( CreateContext(), error, false ); Assert.That( target.Error, Is.SameAs( error ) ); }
public void TestOnCompleted_CallbackCalled() { bool isCallbacked = false; object owner = new object(); var target = new RequestMessageAsyncResult( owner, 1, _ => isCallbacked = true, null ); target.OnCompleted( CreateContext(), null, false ); Assert.That( isCallbacked, Is.True ); }
public void TestOnCompleted_ContextIsSet() { object owner = new object(); var target = new RequestMessageAsyncResult( owner, 1, null, null ); var context = CreateContext(); target.OnCompleted( context, null, false ); Assert.That( target.Result, Is.Not.Null ); }
public void TestOnCompleted_CompletedSynchronouly_True_SetTrue() { object owner = new object(); var target = new RequestMessageAsyncResult(owner, 1, null, null); target.OnCompleted(CreateContext(), null, true); Assert.That((target as IAsyncResult).CompletedSynchronously, Is.True); }
public void TestOnCompleted_ErrorIsSet() { object owner = new object(); var target = new RequestMessageAsyncResult(owner, 1, null, null); var error = new Exception(); target.OnCompleted(CreateContext(), error, false); Assert.That(target.Error, Is.SameAs(error)); }
public void TestOnCompleted_ContextIsSet() { object owner = new object(); var target = new RequestMessageAsyncResult(owner, 1, null, null); var context = CreateContext(); target.OnCompleted(context, null, false); Assert.That(target.Result, Is.Not.Null); }
public void TestOnCompleted_CallbackCalled() { bool isCallbacked = false; object owner = new object(); var target = new RequestMessageAsyncResult(owner, 1, _ => isCallbacked = true, null); target.OnCompleted(CreateContext(), null, false); Assert.That(isCallbacked, Is.True); }
/// <summary> /// Calls specified remote method with specified argument asynchronously. /// </summary> /// <param name="methodName"> /// The name of target method. /// </param> /// <param name="arguments"> /// Argument to be passed to the server. /// All values must be able to be serialized with MessagePack serializer. /// </param> /// <param name="asyncCallback"> /// The callback method invoked when the notification is sent or the reponse is received. /// This value can be <c>null</c>. /// Usually this callback get the result of invocation via <see cref="EndCall"/>. /// </param> /// <param name="asyncState"> /// User supplied state object which can be gotten via <see cref="IAsyncResult.AsyncState"/> in the <paramref name="asyncCallback"/> callback. /// This value can be <c>null</c>. /// </param> /// <returns> /// An <see cref="IAsyncResult" /> which can be passed to <see cref="EndCall"/> method. /// Usually, this value will be ignored because same instance will be passed to the <paramref name="asyncCallback"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="methodName"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="methodName"/> is not valid. /// </exception> public IAsyncResult BeginCall(string methodName, object[] arguments, AsyncCallback asyncCallback, object asyncState) { this.VerifyIsNotDisposed(); this.EnsureConnected(); var messageId = NextId(); var asyncResult = new RequestMessageAsyncResult(this, messageId, asyncCallback, asyncState); bool isSucceeded = false; var context = this._transport.GetClientRequestContext(); try { context.SetRequest(messageId, methodName, asyncResult.OnCompleted); if (arguments == null) { context.ArgumentsPacker.Pack(new MessagePackObject[0]); } else { context.ArgumentsPacker.PackArrayHeader(arguments.Length); foreach (var arg in arguments) { if (arg == null) { context.ArgumentsPacker.PackNull(); } else { this._serializationContext.GetSerializer(arg.GetType()).PackTo(context.ArgumentsPacker, arg); } } } this._transport.Send(context); isSucceeded = true; } finally { if (!isSucceeded) { this._transport.ReturnContext(context); } } return(asyncResult); }
/// <summary> /// Calls specified remote method with specified argument asynchronously. /// </summary> /// <param name="methodName"> /// The name of target method. /// </param> /// <param name="arguments"> /// Argument to be passed to the server. /// All values must be able to be serialized with MessagePack serializer. /// </param> /// <param name="asyncCallback"> /// The callback method invoked when the notification is sent or the reponse is received. /// This value can be <c>null</c>. /// Usually this callback get the result of invocation via <see cref="EndCall"/>. /// </param> /// <param name="asyncState"> /// User supplied state object which can be gotten via <see cref="IAsyncResult.AsyncState"/> in the <paramref name="asyncCallback"/> callback. /// This value can be <c>null</c>. /// </param> /// <returns> /// An <see cref="IAsyncResult" /> which can be passed to <see cref="EndCall"/> method. /// Usually, this value will be ignored because same instance will be passed to the <paramref name="asyncCallback"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="methodName"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="methodName"/> is not valid. /// </exception> public IAsyncResult BeginCall( string methodName, object[] arguments, AsyncCallback asyncCallback, object asyncState ) { this.VerifyIsNotDisposed(); this.EnsureConnected(); var messageId = NextId(); var asyncResult = new RequestMessageAsyncResult( this, messageId, asyncCallback, asyncState ); bool isSucceeded = false; var context = this._transport.GetClientRequestContext(); try { context.SetRequest( messageId, methodName, asyncResult.OnCompleted ); if ( arguments == null ) { context.ArgumentsPacker.Pack( new MessagePackObject[ 0 ] ); } else { context.ArgumentsPacker.PackArrayHeader( arguments.Length ); foreach ( var arg in arguments ) { if ( arg == null ) { context.ArgumentsPacker.PackNull(); } else { this._serializationContext.GetSerializer( arg.GetType() ).PackTo( context.ArgumentsPacker, arg ); } } } this._transport.Send( context ); isSucceeded = true; } finally { if ( !isSucceeded ) { this._transport.ReturnContext( context ); } } return asyncResult; }