public static IJsonRpcServiceHost CreateJsonRpcServiceHost(UnitTestBase owner) { var builder = new JsonRpcServiceHostBuilder(); builder.Register(typeof(Utility).GetTypeInfo().Assembly); builder.ContractResolver = DefaultContractResolver; var globalSw = Stopwatch.StartNew(); var session = new SessionFeature(); if (owner.Output != null) { builder.Intercept(async(context, next) => { var sw = Stopwatch.StartNew(); owner.Output.WriteLine("{0}> {1}", globalSw.Elapsed, context.Request); try { context.Features.Set(session); await next(); owner.Output.WriteLine("{0}< {1}", globalSw.Elapsed, context.Response); } finally { owner.Output.WriteLine("Server: Ellapsed time: {0}", sw.Elapsed); } }); } builder.LoggerFactory = owner.LoggerFactory; return(builder.Build()); }
public ServerTestHelper(UnitTestBase owner, MessageReader reader, MessageWriter writer, StreamRpcServerHandlerOptions options) { ServiceHost = Utility.CreateJsonRpcServiceHost(owner); ServerHandler = new StreamRpcServerHandler(ServiceHost, options); ServerMessageReader = reader; ServerMessageWriter = writer; disposables.Add(ServerHandler.Attach(ServerMessageReader, ServerMessageWriter)); }