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)));
        }
Beispiel #2
0
        void IEventMonitorSink.RemoveEvaluator(Type eventType, IEventOccurredConditionEvaluator evaluator)
        {
            var eventTypeEvaluators = _evaluators.GetOrAdd(eventType, x => new ConcurrentDictionary <Guid, IEventOccurredConditionEvaluator>());

            eventTypeEvaluators.TryRemove(evaluator.Id, out var _);
        }