public void Given_Evaluator_When_Description_Then_EventTypeName()
        {
            var eventMonitorSink = A.Dummy <IEventMonitorSink>();
            var condition        = A.Dummy <Func <Event, bool> >();

            var spec = new EventOccurredConditionSpecification <Event>(eventMonitorSink, condition);

            Assert.That(spec.Description, Is.EqualTo(typeof(Event).Name));
        }
        public async Task Given_SingleEvaluator_When_Build_Then_MonitorSingleEvaluator()
        {
            var eventMonitorSink = A.Fake <IEventMonitorSink>();
            var condition        = A.Dummy <Func <Event, bool> >();

            var spec = new EventOccurredConditionSpecification <Event>(eventMonitorSink, condition);

            // Act
            var evaluator = await spec.BuildAsync(_timeSpanFactory);

            // Assert
            Assert.That(evaluator, Is.Not.Null);

            A.CallTo(() => eventMonitorSink.AddEvaluator(typeof(Event), A <IEventOccurredConditionEvaluator> ._)).MustHaveHappenedOnceExactly();
        }
        public async Task Given_MultipleEvaluator_When_DisposeSingleEvaluator_Then_MonitorContinues()
        {
            var eventMonitorSink = A.Fake <IEventMonitorSink>();
            var condition        = A.Dummy <Func <Event, bool> >();

            var spec = new EventOccurredConditionSpecification <Event>(eventMonitorSink, condition);

            // Act
            var evaluator = await spec.BuildAsync(_timeSpanFactory);

            await spec.BuildAsync(_timeSpanFactory);

            await evaluator.DisposeAsync();

            // Assert
            A.CallTo(() => eventMonitorSink.AddEvaluator(typeof(Event), A <IEventOccurredConditionEvaluator> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => eventMonitorSink.RemoveEvaluator(typeof(Event), A <IEventOccurredConditionEvaluator> ._)).MustNotHaveHappened();
        }
        public async Task Given_MultpleEvaluators_When_GetInstances_Then_GetsSameConditionInstances()
        {
            var condition = A.Dummy <Func <Event, bool> >();

            A.CallTo(() => condition.Invoke(A <Event> ._)).Returns(true);

            IEventOccurredConditionEvaluator eventOccurredEvaluator = null;
            var eventMonitorSink = A.Fake <IEventMonitorSink>();

            A.CallTo(() => eventMonitorSink.AddEvaluator(typeof(Event), A <IEventOccurredConditionEvaluator> ._))
            .Invokes((Type t, IEventOccurredConditionEvaluator e) => eventOccurredEvaluator = e);

            var spec = new EventOccurredConditionSpecification <Event>(eventMonitorSink, condition);

            var evt1 = A.Dummy <Event>();
            var evt2 = A.Dummy <Event>();

            // Act
            var evaluator = await spec.BuildAsync(_timeSpanFactory);

            var evaluator2 = await spec.BuildAsync(_timeSpanFactory);

            await eventOccurredEvaluator.CheckEventAsync(evt1);

            await eventOccurredEvaluator.CheckEventAsync(evt2);

            var results = await evaluator.GetInstancesAsync().AsyncToListAsync(TimeSpan.FromMilliseconds(50));

            var results2 = await evaluator2.GetInstancesAsync().AsyncToListAsync(TimeSpan.FromMilliseconds(50));

            await evaluator.DisposeAsync();

            await evaluator2.DisposeAsync();

            Assert.That(results, Is.Not.Empty);
            Assert.That(results.Count, Is.EqualTo(2));

            Assert.That(results2, Is.Not.Empty);
            Assert.That(results2.Count, Is.EqualTo(2));

            Assert.That(results.All(x => results2.Contains(x)));
        }