Ejemplo n.º 1
0
        public async Task CatchAny_catches_for_failed_consumer_only_and_does_not_notify_any_consumer_of_failure()
        {
            var behaving            = AsyncInterceptingConsumer.Behaving();
            var misbehaving         = AsyncInterceptingConsumer.Misbehaving();
            var behavingGotCatch    = false;
            var misbehavingGotCatch = false;
            var sut = NewSut();

            sut
            .CatchAny(_ => behavingGotCatch = true)
            .Subscribe(behaving);
            sut
            .CatchAny(_ => misbehavingGotCatch = true)
            .Subscribe(misbehaving);

            await sut.EmitAsync("v1");

            await sut.EmitAsync("v2");

            behavingGotCatch.Should().BeFalse();
            misbehavingGotCatch.Should().BeTrue();

            behaving.Interceptions.OnAnyFailed.Should().BeEmpty();
            misbehaving.Interceptions.OnAnyFailed.Should().BeEmpty();
            behaving.Interceptions.OnAllSucceeded.Should().HaveCount(2);
            misbehaving.Interceptions.OnAllSucceeded.Should().HaveCount(2);
        }
Ejemplo n.º 2
0
        public async Task Emits_events_to_all_active_consumers_even_failed_ones()
        {
            var behaving              = AsyncInterceptingConsumer.Behaving();
            var behavingDelegating    = new Interceptions();
            var misbehaving           = AsyncInterceptingConsumer.Misbehaving(ev => ev.Sequence > Sequence.First);
            var misbehavingDelegating = new Interceptions();
            var sut = NewSut();

            sut.Subscribe(behaving);
            sut.Subscribe(
                behavingDelegating.InOnNewAsync,
                behavingDelegating.InOnAllSucceededAsync,
                behavingDelegating.InOnAnyFailedAsync);
            sut.Subscribe(misbehaving);
            sut.Subscribe(
                ev =>
            {
                misbehavingDelegating.InOnNew(ev);
                if (ev.Sequence > Sequence.First)
                {
                    throw new Exception(ev.ToString());
                }

                return(ValueTask.CompletedTask);
            },
                misbehavingDelegating.InOnAllSucceededAsync,
                misbehavingDelegating.InOnAnyFailedAsync);

            var ev1 = await sut.EmitAsync(Fake.Strings.Random());

            var ev2 = await sut.EmitAsync(Fake.Strings.Random());

            behaving.Ensure().OnNewOnlyHas(ev1, ev2);
            behaving.Ensure().OnAllSucceededOnlyHasId(ev1.Id);
            behaving.Ensure().OnAnyFailedOnlyHasId(ev2.Id);

            behavingDelegating.Ensure().OnNewOnlyHas(ev1, ev2);
            behavingDelegating.Ensure().OnAllSucceededOnlyHasId(ev1.Id);
            behavingDelegating.Ensure().OnAnyFailedOnlyHasId(ev2.Id);

            misbehaving.Ensure().OnNewOnlyHas(ev1, ev2);
            misbehaving.Ensure().OnAllSucceededOnlyHasId(ev1.Id);
            misbehaving.Ensure().OnAnyFailedOnlyHasId(ev2.Id);

            misbehavingDelegating.Ensure().OnNewOnlyHas(ev1, ev2);
            misbehavingDelegating.Ensure().OnAllSucceededOnlyHasId(ev1.Id);
            misbehavingDelegating.Ensure().OnAnyFailedOnlyHasId(ev2.Id);
        }
Ejemplo n.º 3
0
        public async Task Supports_event_filtering()
        {
            var consumer = AsyncInterceptingConsumer <string> .Behaving();

            var sut = NewSut();

            sut
            .When <string>()
            .Subscribe(consumer);

            await sut.EmitAsync("1");

            await sut.EmitAsync(new Dummy("test"));

            consumer.Interceptions.Ensure().OnNewOnlyHasContents("1");
        }
Ejemplo n.º 4
0
        public async Task Supports_content_filtering()
        {
            var consumer = AsyncInterceptingConsumer <string> .Behaving();

            var sut = NewSut();

            sut
            .When <string>()
            .Where(ev => ev.Content == "1")
            .Subscribe(consumer);

            await sut.EmitAsync("1");

            await sut.EmitAsync("2");

            consumer.Interceptions.Ensure().OnNewOnlyHasContents("1");
        }
Ejemplo n.º 5
0
        public async Task Unsubscribed_consumer_is_not_invoked_at_all()
        {
            var unsubscribing           = AsyncInterceptingConsumer.Behaving();
            var unsubscribingDelegating = new Interceptions();
            var sut = NewSut();

            sut.Subscribe(_ => throw new Exception("FAIL"));
            var sub1 = sut.Subscribe(unsubscribing);
            var sub2 = sut.Subscribe(
                unsubscribingDelegating.InOnNewAsync,
                unsubscribingDelegating.InOnAllSucceededAsync,
                unsubscribingDelegating.InOnAnyFailedAsync);

            sub1.Dispose();
            sub2.Dispose();

            await sut.EmitAsync(Fake.Strings.Random());

            unsubscribing.Ensure().ToBeUnTouched();
            unsubscribingDelegating.Ensure().ToBeUnTouched();
        }