internal static TraceableRemoteApiMapWrapperRealSockets ArrangeRemoteApiMapTestWrapperWithRealSockets( string address) { var recorder = new ApplicationCacheRecorder(); var sockets = new List <SocketTesterWrapper>(); var socketFactoryCounter = 0; var apiMapWrapper = default(TraceableRemoteApiMapWrapperRealSockets); void OnAccepted(SocketTesterWrapper wrapper) { sockets.Add(wrapper); apiMapWrapper.SocketAcceptedHandler?.Invoke(wrapper); } Func <AddressFamily, SocketType, ProtocolType, ISocket> socketFactory = (family, type, arg3) => { socketFactoryCounter++; var socket = new SocketTesterWrapper(family, type, arg3, $"{socketFactoryCounter}"); socket.Accepted += OnAccepted; sockets.Add(socket); return(socket); }; // RemoteApiMap var instructionReceiverFactory = new TestInstructionReceiverFactory(socketFactory, recorder); var traceableRemoteApiMapFactory = new BaseTraceableRemoteApiMapFactory( instructionReceiverFactory, recorder); var apiMap = traceableRemoteApiMapFactory.Create(address); apiMapWrapper = new TraceableRemoteApiMapWrapperRealSockets(sockets, apiMap, recorder); return(apiMapWrapper); }
internal static RemoteOperatorTestWrapperRealSockets ArrangeLocalOperatorTestWrapperRealSockets( string address = "127.0.0.1:22222") { var recorder = new ApplicationCacheRecorder(); var sockets = new List <SocketTesterWrapper>(); var remoteTraceMonitorСonsistent = new RemoteTraceMonitorСonsistentTester(recorder); var socketFactoryCounter = 0; Func <AddressFamily, SocketType, ProtocolType, ISocket> socketFactory = (family, type, arg3) => { socketFactoryCounter++; var socket = new SocketTesterWrapper(family, type, arg3, $"{socketFactoryCounter}"); socket.Accepted += OnAccepted; sockets.Add(socket); return(socket); }; void OnAccepted(SocketTesterWrapper wrapper) { sockets.Add(wrapper); } var apiOperator = CreateLocalOperator(socketFactory, recorder, remoteTraceMonitorСonsistent, address); return(new RemoteOperatorTestWrapperRealSockets(sockets, apiOperator, recorder, remoteTraceMonitorСonsistent)); }
private async void SocketAccepted(SocketTesterWrapper socket) { _connectedTask = new TaskCompletionSource <bool>(); await socket.ReceivedCalledSecondTime; _connectedTask.SetResult(true); }
public async Task <ISocket> AcceptAsync() { var socket = await _socket.AcceptAsync(); var wrapper = new SocketTesterWrapper(socket, "accepted"); Accepted?.Invoke(wrapper); return(wrapper); }