Пример #1
0
            public async Task should_batch_multiple_subscription_requests()
            {
                AddInvoker <FakeRoutableCommand>(shouldBeSubscribedOnStartup: false);

                var subscriptions = new List <SubscriptionsForType>();

                _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptionsAsync(bus, items), subscriptions);

                _bus.Start();

                var batch = new SubscriptionRequestBatch();

                var requestA = new SubscriptionRequest(new[]
                {
                    Subscription.ByExample(x => new FakeRoutableCommand(1, "foo")),
                    Subscription.ByExample(x => new FakeRoutableCommand(1, "bar"))
                });

                var requestB = new SubscriptionRequest(new[]
                {
                    Subscription.ByExample(x => new FakeRoutableCommand(1, "bar")),
                    Subscription.ByExample(x => new FakeRoutableCommand(1, "baz"))
                });

                requestA.AddToBatch(batch);
                requestB.AddToBatch(batch);

                var taskA = _bus.SubscribeAsync(requestA);
                var taskB = _bus.SubscribeAsync(requestB);

                subscriptions.ShouldBeEmpty();

                await batch.SubmitAsync();

                await Task.WhenAll(taskA, taskB);

                subscriptions.ExpectedSingle()
                .ShouldEqual(new SubscriptionsForType(
                                 MessageUtil.TypeId <FakeRoutableCommand>(),
                                 new BindingKey("1", "foo", "*"),
                                 new BindingKey("1", "bar", "*"),
                                 new BindingKey("1", "baz", "*")
                                 )
                             );

                subscriptions.Clear();

                taskA.Result.Dispose();
                await _bus.WhenUnsubscribeCompletedAsync();

                subscriptions.ExpectedSingle()
                .ShouldEqual(new SubscriptionsForType(
                                 MessageUtil.TypeId <FakeRoutableCommand>(),
                                 new BindingKey("1", "bar", "*"),
                                 new BindingKey("1", "baz", "*")
                                 )
                             );
            }
Пример #2
0
            public void should_throw_when_batch_is_sent_after_bus_is_stopped()
            {
                AddInvoker <FakeCommand>(shouldBeSubscribedOnStartup: false);

                var batch   = new SubscriptionRequestBatch();
                var request = new SubscriptionRequest(Subscription.Any <FakeCommand>());

                request.AddToBatch(batch);

                _bus.Start();
                var _ = _bus.SubscribeAsync(request);

                _bus.Stop();

                var submitTask = batch.SubmitAsync();

                Assert.Throws <AggregateException>(() => submitTask.Wait()).InnerExceptions.ExpectedSingle().ShouldBe <InvalidOperationException>();
            }
Пример #3
0
            public void empty_batch_should_not_block()
            {
                var batch = new SubscriptionRequestBatch();

                batch.SubmitAsync().IsCompleted.ShouldBeTrue();
            }