本文整理汇总了C#中System.Threading.ManualResetEventSlim.AssertWaitFor方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEventSlim.AssertWaitFor方法的具体用法?C# ManualResetEventSlim.AssertWaitFor怎么用?C# ManualResetEventSlim.AssertWaitFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEventSlim
的用法示例。
在下文中一共展示了ManualResetEventSlim.AssertWaitFor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Client_should_connect_to_server_and_signal_appropriate_callbacks
public void Client_should_connect_to_server_and_signal_appropriate_callbacks()
{
var connected1 = new ManualResetEventSlim(false);
var connected2 = new ManualResetEventSlim(false);
var ex = ServerHelpers.CreateExecutor();
var server = ServerHelpers.CreateServer();
server.Connected.Subscribe(client =>
{
connected1.Set();
});
server.Started.Subscribe(u =>
{
var client = new SocketClient(ex);
client.Connected.Subscribe( _ =>
{
connected2.Set();
});
client.Disconnected.Subscribe(exn =>
{
throw exn;
});
client.Connect(new IPEndPoint(IPAddress.Loopback, server.BindEndPoint.Port));
});
server.Start();
connected1.AssertWaitFor(5000);
connected2.AssertWaitFor(5000);
server.StopAndAssertStopped();
}
示例2: Client_should_signal_disconnection_when_server_is_closed
public void Client_should_signal_disconnection_when_server_is_closed()
{
var disconnected = new ManualResetEventSlim();
Utils.CreateServerAndClientProxy<TestActor, ITestActor>(out server, out clientProxy);
clientProxy.Disconnected.Subscribe(exn => { disconnected.Set(); });
server.Stop();
disconnected.AssertWaitFor();
}
示例3: Starting_should_call_started_callback
public void Starting_should_call_started_callback()
{
var started = new ManualResetEventSlim();
var server = ServerHelpers.CreateServer();
server.Started += () => { started.Set(); };
server.Start();
started.AssertWaitFor(2000);
server.StopAndAssertStopped();
}
示例4: Starting_and_stopping_should_call_both_callbacks
public void Starting_and_stopping_should_call_both_callbacks()
{
var started = new ManualResetEventSlim();
var stopped = new ManualResetEventSlim();
var server = ServerHelpers.CreateServer();
server.Started.Subscribe(_ => { started.Set(); });
server.Stopped.Subscribe(_ => { stopped.Set(); });
server.Start();
server.Stop();
started.AssertWaitFor(2000);
stopped.AssertWaitFor(2000);
}
示例5: When_exception_is_thrown_inside_callback_executor_should_signal_error
public void When_exception_is_thrown_inside_callback_executor_should_signal_error()
{
var errOccured = new ManualResetEventSlim();
var exec = new ActionBlockExecutor(null, new ActionBlockExecutorSettings());
var server = ServerHelpers.CreateServer(exec);
exec.Error += exc => { Assert.Equal("abcdef", exc.Message); errOccured.Set(); };
server.Started += () => { throw new Exception("abcdef"); };
server.Start();
errOccured.AssertWaitFor(2000);
server.Stop();
}
示例6: Calling_connect_twice_should_throw_an_exception
public void Calling_connect_twice_should_throw_an_exception()
{
var hasConnected = new ManualResetEventSlim();
var executor = ServerHelpers.CreateExecutor();
var server = ServerHelpers.CreateServer(executor);
server.Started.Subscribe(_ =>
{
Assert.Throws(typeof(InvalidOperationException),
() =>
{
var client = new SocketClient(executor);
client.Connect(server.BindEndPoint);
hasConnected.Set();
client.Connect(server.BindEndPoint);
});
});
server.Start();
hasConnected.AssertWaitFor();
}
示例7: If_server_closes_then_client_should_raise_disconnect_event
public void If_server_closes_then_client_should_raise_disconnect_event()
{
var disconnectedCalled = new ManualResetEventSlim();
SocketServer server;
SocketClient serverClient, remoteClient;
ServerHelpers.CreateServerAndConnectedClient(out server, out serverClient, out remoteClient);
remoteClient.Disconnected.Subscribe(exn =>
{
Assert.IsType(typeof(SocketException), exn);
Assert.Equal((int)SocketError.Disconnecting, ((SocketException)exn).ErrorCode);
disconnectedCalled.Set();
});
serverClient.Disconnected.Subscribe(exn =>
{
});
server.Stop();
serverClient.Close();
disconnectedCalled.AssertWaitFor(5000);
}
示例8: If_client_cannot_connect_if_should_raise_disconnect_event_with_connection_refused_error
public void If_client_cannot_connect_if_should_raise_disconnect_event_with_connection_refused_error()
{
var disconnectedCalled = new ManualResetEventSlim();
var executor = ServerHelpers.CreateExecutor();
var client = new SocketClient(executor);
client.Disconnected.Subscribe(exn =>
{
Assert.IsType(typeof(SocketException), exn);
Assert.Equal((int)SocketError.ConnectionRefused, ((SocketException)exn).ErrorCode);
disconnectedCalled.Set();
});
client.Connect(new IPEndPoint(IPAddress.Loopback, 45232));
disconnectedCalled.AssertWaitFor();
}
示例9: CreateServerAndConnectedClient
public static void CreateServerAndConnectedClient(out SocketServer server,
out SocketClient client1, out SocketClient client2)
{
var connected1 = new ManualResetEventSlim(false);
var connected2 = new ManualResetEventSlim(false);
var ex = ServerHelpers.CreateExecutor();
var s = ServerHelpers.CreateServer();
SocketClient lClient = null;
SocketClient sClient = null;
s.Connected.Subscribe(c =>
{
sClient = c;
connected2.Set();
});
s.Started.Subscribe(_ =>
{
var c = new SocketClient(ex);
c.Connected.Subscribe(u =>
{
lClient = c;
connected1.Set();
});
c.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port));
});
s.Start();
connected1.AssertWaitFor(3000);
connected2.AssertWaitFor(3000);
server = s;
client1 = lClient;
client2 = sClient;
}
示例10: StopAndAssertStopped
public static void StopAndAssertStopped(this SocketServer server)
{
var stopped = new ManualResetEventSlim(false);
server.Stopped.Subscribe(_ =>
{
stopped.Set();
});
server.Stop();
stopped.AssertWaitFor(3000);
}