本文整理汇总了C#中ConcurrentBag.Should方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.Should方法的具体用法?C# ConcurrentBag.Should怎么用?C# ConcurrentBag.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.Should方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: they_should_be_unique
public void they_should_be_unique()
{
var generatedSet = new ConcurrentBag<Guid>();
var tasks = Enumerable.Range(0, 1000)
.Select(_ => Task.Factory.StartNew(() => generatedSet.Add(SeqGuid.NewGuid())))
.ToArray();
Task.WaitAll(tasks);
generatedSet.Should().HaveCount(1000);
generatedSet.Should().OnlyHaveUniqueItems();
}
示例2: Multiple_scheduled_commands_having_the_some_causative_command_etag_have_repeatable_and_unique_etags
public async Task Multiple_scheduled_commands_having_the_some_causative_command_etag_have_repeatable_and_unique_etags()
{
var senderId = Any.Word();
await Save(new NonEventSourcedCommandTarget(senderId));
var targetIds = new[] { Any.Word(), Any.Word(), Any.Word() };
var results = new ConcurrentBag<RequestReply>();
Configuration.Current
.TraceScheduledCommands(
onScheduling: cmd =>
{
var requestReply = ((dynamic) cmd).Command as RequestReply;
if (requestReply != null)
{
results.Add(requestReply);
}
});
var initialEtag = "initial".ToETag();
var firstCommand = new SendRequests(targetIds)
{
ETag = initialEtag
};
var scheduledCommand = new ScheduledCommand<NonEventSourcedCommandTarget>(
firstCommand,
senderId);
await Deliver(scheduledCommand);
var secondCommand = new SendRequests(targetIds)
{
ETag = initialEtag
};
scheduledCommand = new ScheduledCommand<NonEventSourcedCommandTarget>(
secondCommand,
senderId);
// redeliver
await Deliver(scheduledCommand);
results.Should().HaveCount(6);
results.Select(r => r.ETag)
.Distinct()
.Should()
.HaveCount(3);
}
示例3: CopesWithHighConcurrencySending
public void CopesWithHighConcurrencySending()
{
// Arrange
var received = new ConcurrentBag<TestMessageTypeA>();
for (var i = 0; i < 1000; i++)
bus.SubscriberFor<TestMessageTypeA>(received.Add);
// Act
bus.SendMessage(new TestMessageTypeA());
// Assert
received.Should().HaveCount(1000);
}
示例4: When_multiple_projectors_are_subscribed_then_data_that_both_projections_have_seen_is_not_requeried
public async Task When_multiple_projectors_are_subscribed_then_data_that_both_projections_have_seen_is_not_requeried()
{
var queriedEvents = new ConcurrentBag<IDomainEvent>();
var balanceProjections = new InMemoryProjectionStore<BalanceProjection>();
await balanceProjections.Put(streamId, new BalanceProjection
{
CursorPosition = 2
});
var catchup = StreamCatchup.Create(stream.Trace(onResults: (q, b) =>
{
foreach (var e in b)
{
queriedEvents.Add(e);
}
}), batchCount: 10);
catchup.Subscribe(new BalanceProjector(), balanceProjections);
store.WriteEvents(streamId, howMany: 2);
await catchup.RunSingleBatch();
queriedEvents.Count
.Should()
.Be(1,
"the first two events should be skipped because of the starting cursor position");
queriedEvents.Should()
.ContainSingle(e => e.StreamRevision == 3,
"only the most recent event should be queried");
var accountHistoryProjections = new InMemoryProjectionStore<AccountHistoryProjection>();
await accountHistoryProjections.Put(streamId, new AccountHistoryProjection
{
CursorPosition = 2
});
catchup.Subscribe(new AccountHistoryProjector(), accountHistoryProjections);
store.WriteEvents(streamId);
await catchup.RunSingleBatch();
queriedEvents.Select(e => e.StreamRevision)
.ShouldBeEquivalentTo(new[] { 3, 3, 4 },
"event 3 needs to be repeated because the newly-subscribed aggregator hasn't seen it yet");
}
示例5: Unless_work_is_completed_then_lease_is_not_reissued_before_its_duration_has_passed
public async Task Unless_work_is_completed_then_lease_is_not_reissued_before_its_duration_has_passed()
{
var leasesGranted = new ConcurrentBag<string>();
var distributor = CreateDistributor(async l =>
{
Console.WriteLine("GRANTED: " + l);
leasesGranted.Add(l.LeasableResource.Name);
if (l.LeasableResource.Name == "2")
{
await Task.Delay(((int) DefaultLeaseDuration.TotalMilliseconds*6));
}
});
await distributor.Start();
await Task.Delay((int) (DefaultLeaseDuration.TotalMilliseconds*.5));
await distributor.Stop();
await Task.Delay(100);
leasesGranted.Should().ContainSingle(l => l == "2");
}
示例6: When_a_clock_is_advanced_then_unassociated_commands_are_not_triggered
public async Task When_a_clock_is_advanced_then_unassociated_commands_are_not_triggered()
{
// arrange
var clockOne = CreateClock(Any.CamelCaseName(), Clock.Now());
var clockTwo = CreateClock(Any.CamelCaseName(), Clock.Now());
var deliveryAttempts = new ConcurrentBag<IScheduledCommand>();
Configuration.Current.TraceScheduledCommands(onDelivering: command => { deliveryAttempts.Add(command); });
await Schedule(
new CreateCommandTarget(Any.CamelCaseName()),
Clock.Now().AddDays(1),
clock: clockOne);
await Schedule(
new CreateCommandTarget(Any.CamelCaseName()),
Clock.Now().AddDays(1),
clock: clockTwo);
// act
await AdvanceClock(TimeSpan.FromDays(2), clockOne.Name);
//assert
deliveryAttempts
.Should().HaveCount(1)
.And
.OnlyContain(c => ((CommandScheduler.Clock) c.Clock).Name == clockOne.Name);
}
示例7: PublisherPerformance
public void PublisherPerformance()
{
var exchange = new Exchange("eventflow");
var routingKey = new RoutingKey("performance");
var exceptions = new ConcurrentBag<Exception>();
const int threadCount = 100;
const int messagesPrThread = 200;
using (var consumer = new RabbitMqConsumer(_uri, "eventflow", new[] {"#"}))
using (var resolver = BuildResolver(o => o.RegisterServices(sr => sr.Register<ILog, NullLog>())))
{
var rabbitMqPublisher = resolver.Resolve<IRabbitMqPublisher>();
var threads = Enumerable.Range(0, threadCount)
.Select(_ =>
{
var thread = new Thread(o => SendMessages(rabbitMqPublisher, messagesPrThread, exchange, routingKey, exceptions));
thread.Start();
return thread;
})
.ToList();
foreach (var thread in threads)
{
thread.Join();
}
var rabbitMqMessages = consumer.GetMessages(threadCount * messagesPrThread);
rabbitMqMessages.Should().HaveCount(threadCount*messagesPrThread);
exceptions.Should().BeEmpty();
}
}
示例8: PageSmallerThanOnePage_NormalProcessing
public async void PageSmallerThanOnePage_NormalProcessing()
{
//------------ Arrange
var items = this.f.CreateMany< int >( 8 );
var result = new ConcurrentBag< string >();
//------------ Act
await items.DoWithPagesAsync( 10, async l => result.Add( "test" ) );
//------------ Assert
var expected = Enumerable.Repeat( "test", 1 );
result.Should().Equal( expected );
}
示例9: SeveralPagesWithConstantValueProcessor_ResultsUnioned
public async void SeveralPagesWithConstantValueProcessor_ResultsUnioned()
{
//------------ Arrange
var items = this.f.CreateMany< int >( 8 );
var result = new ConcurrentBag< string >();
//------------ Act
await items.DoWithPagesAsync( 3, async l => result.Add( "test" ) );
//------------ Assert
var expected = Enumerable.Repeat( "test", 3 );
result.Should().Equal( expected );
}
示例10: SeveralPagesWithSameValueProcessor_ResultsUnioned
public async void SeveralPagesWithSameValueProcessor_ResultsUnioned()
{
//------------ Arrange
var items = this.f.CreateMany< int >();
var result = new ConcurrentBag< int >();
//------------ Act
await items.DoWithPagesAsync( 3, async l => l.ForEach( result.Add ) );
//------------ Assert
result.Should().Contain( items );
}
示例11: CanSyncSendReceive
public void CanSyncSendReceive()
{
var buff = 0;
const int N = 20;
const int SecondsTimeout = 60;
var helper = new SendReceiveLockHelper(FullName, EmptyName);
for (var i = 0; i < N; i++)
{
var value = i;
helper.AddSendAction(
() =>
{
using (new SingleThreadAccessController())
{
buff = value;
}
});
helper.AddReceiveFunction(() =>
{
using (new SingleThreadAccessController())
{
return buff;
}
});
}
var list = new ConcurrentBag<int>();
var sendTask = Task.Factory.StartNew(() => helper.Send(TimeSpan.FromSeconds(SecondsTimeout)));
var receiveTask = Task.Factory.StartNew(() => helper.Receive(list, TimeSpan.FromSeconds(SecondsTimeout)));
Task.WaitAll(sendTask, receiveTask);
sendTask.Result.Should().BeTrue("sendTask.Result should be true");
receiveTask.Result.Should().BeTrue("receiveTask.Result should be true");
list.Count.Should().Be(N, string.Format("list.Count should be equals {0}", N));
for (var i = 0; i < N; i++)
{
list.Should().Contain(i, string.Format("list should contains {0}", i));
}
}