public void Respond <TRequest, TResult>(Func <TRequest, TResult> callback, CancellationToken cancellationToken = default) where TRequest : class, new() where TResult : class, new() { var xtResult = _rqRep.Respond <TRequest, TResult>(callback, cancellationToken); ThrowOnNonSuccess(xtResult); }
public async Task Multiple_Threads_Send_To_One_Responder_Works(object configuration) { // Arrange var sut = new RqRep((SocketConfiguration)configuration); sut.Respond <Request, Response>(rq => new Response { ResponseNumber = rq.RequestNumber }); var input_output_Tuples = new List <(int, int)>(); var taskList = new List <Task>() { DoMultipleRequestAsync(sut, 1, input_output_Tuples), DoMultipleRequestAsync(sut, 2, input_output_Tuples), DoMultipleRequestAsync(sut, 3, input_output_Tuples), }; // Act await Task.WhenAll(taskList); // Assert foreach (var(_in, _out) in input_output_Tuples) { Assert.Equal(_in, _out); } sut.Dispose(); }
internal static void SetupResponder(RqRep rqRep, CancellationToken token = default) { rqRep.Respond <Request, Response>((rq) => { System.Console.WriteLine(); System.Console.WriteLine("now calling the factory"); System.Console.WriteLine(); var rsp = new Response(); rsp.InsideResponse += " " + rq.FromRequest; return(rsp); }, cancellationToken: token); }
public async Task SimpleRequestAndReply_InProc() { // Arrange var sut = new RqRep(new ConfigurationTestData().GetSocketConfigInProc); sut.Respond <Request, Response>(rq => new Response { ResponseNumber = rq.RequestNumber }); // Act var xtResult = await sut.RequestAsync <Request, Response>(new Request { RequestNumber = 42 }); // Assert Assert.True(xtResult.IsSuccess); Assert.Equal(42, xtResult.GetResult().ResponseNumber); sut.Dispose(); }