public void CatchAny_catches_for_failed_consumer_only_and_does_not_notify_any_consumer_of_failure() { var behaving = InterceptingConsumer.Behaving(); var misbehaving = InterceptingConsumer.Misbehaving(); var behavingGotCatch = false; var misbehavingGotCatch = false; var sut = NewSut(); sut .CatchAny(_ => behavingGotCatch = true) .Subscribe(behaving); sut .CatchAny(_ => misbehavingGotCatch = true) .Subscribe(misbehaving); sut.Emit("v1"); sut.Emit("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); }
public void Supports_event_filtering() { var consumer = InterceptingConsumer <string> .Behaving(); var sut = NewSut(); sut .When <string>() .Subscribe(consumer); sut.Emit("1"); sut.Emit(new Dummy("test")); consumer.Interceptions.Ensure().OnNewOnlyHasContents("1"); }
public void Supports_content_filtering() { var consumer = InterceptingConsumer <string> .Behaving(); var sut = NewSut(); sut .When <string>() .Where(ev => ev.Content == "1") .Subscribe(consumer); sut.Emit("1"); sut.Emit("2"); consumer.Interceptions.Ensure().OnNewOnlyHasContents("1"); }
public void Emits_events_to_all_active_consumers_even_failed_ones() { var behaving = InterceptingConsumer.Behaving(); var behavingDelegating = new Interceptions(); var misbehaving = InterceptingConsumer.Misbehaving(ev => ev.Sequence > Sequence.First); var misbehavingDelegating = new Interceptions(); var sut = NewSut(); sut.Subscribe(behaving); sut.Subscribe( behavingDelegating.InOnNew, behavingDelegating.InOnAllSucceeded, behavingDelegating.InOnAnyFailed); sut.Subscribe(misbehaving); sut.Subscribe( ev => { misbehavingDelegating.InOnNew(ev); if (ev.Sequence > Sequence.First) { throw new Exception(ev.ToString()); } }, misbehavingDelegating.InOnAllSucceeded, misbehavingDelegating.InOnAnyFailed); var ev1 = sut.Emit(Fake.Strings.Random()); var ev2 = sut.Emit(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); }
public void Unsubscribed_consumer_is_not_invoked_at_all() { var unsubscribing = InterceptingConsumer.Behaving(); var unsubscribingDelegating = new Interceptions(); var sut = NewSut(); sut.Subscribe(_ => throw new Exception("FAIL")); var sub1 = sut.Subscribe(unsubscribing); var sub2 = sut.Subscribe( unsubscribingDelegating.InOnNew, unsubscribingDelegating.InOnAllSucceeded, unsubscribingDelegating.InOnAnyFailed); sub1.Dispose(); sub2.Dispose(); sut.Emit(Fake.Strings.Random()); unsubscribing.Ensure().ToBeUnTouched(); unsubscribingDelegating.Ensure().ToBeUnTouched(); }
internal static InterceptionsHas Ensure <T>(this InterceptingConsumer <T> consumer) where T : class => new(consumer.Interceptions);