本文整理汇总了C#中ConcurrentBag.Single方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.Single方法的具体用法?C# ConcurrentBag.Single怎么用?C# ConcurrentBag.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.Single方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_not_filter_received_messages_when_environment_is_not_specified
public void should_not_filter_received_messages_when_environment_is_not_specified()
{
var transport1 = CreateAndStartZmqTransport(environment: null);
var transport2ReceivedMessages = new ConcurrentBag<TransportMessage>();
var transport2 = CreateAndStartZmqTransport(onMessageReceived: transport2ReceivedMessages.Add, environment: "NotTest");
var transport2Peer = new Peer(new PeerId("Abc.Testing.2"), transport2.InboundEndPoint);
var message = new FakeCommand(1).ToTransportMessage();
transport1.Send(message, new[] { transport2Peer });
Wait.Until(() => transport2ReceivedMessages.Count >= 1, 500.Milliseconds());
transport2ReceivedMessages.Single().Id.ShouldEqual(message.Id);
}
示例2: should_not_dispatch_messages_received_from_wrong_environment
public void should_not_dispatch_messages_received_from_wrong_environment()
{
var transport1ReceivedMessages = new ConcurrentBag<TransportMessage>();
var transport1 = CreateAndStartZmqTransport(onMessageReceived: transport1ReceivedMessages.Add);
var transport2ReceivedMessages = new ConcurrentBag<TransportMessage>();
var transport2 = CreateAndStartZmqTransport(onMessageReceived: transport2ReceivedMessages.Add, environment: "NotTest");
var transport2Peer = new Peer(new PeerId("Abc.Testing.2"), transport2.InboundEndPoint);
var message1 = new FakeCommand(1).ToTransportMessage();
var message2 = new FakeCommand(2).ToTransportMessage();
transport1.Send(message1, new[] { transport2Peer }); // should not arrive
Thread.Sleep(500); //:(
transport2.Configure(transport2Peer.Id, _environment);
transport1.Send(message2, new[] { transport2Peer }); //should arrive
Wait.Until(() => transport2ReceivedMessages.Count >= 1, 500.Milliseconds());
transport2ReceivedMessages.Single().Id.ShouldEqual(message2.Id);
}