public void AllBasicParametersShouldBeSet()
 {
     var filters = new List<Func<ModuleChecked, bool>> { ev => true, ev => false };
     var settigs = new TypedHandlingSettings<ModuleChecked>(() => new SpecEventHandler<ModuleChecked>(ev => { }), filters, 100);
     settigs.Type.Should().Be(typeof(ModuleChecked));
     settigs.Priority.Should().Be(100);
     settigs.Filters.Should().Have.SameSequenceAs(filters);
 }
        public void AllBasicParametersShouldBeSet()
        {
            var originalSettigs = new TypedHandlingSettings<SystemChecked>(() => new SpecEventHandler<SystemChecked>(ev => { }), priority: 99);

            var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.Finished);

            settigs.Type.Should().Be(typeof(SystemChecked));
            settigs.Priority.Should().Be(99);
        }
        public void ActionShouldBeFilteredByType()
        {
            var resolved = false;

            var settigs = new TypedHandlingSettings<ModuleChecked>(
                () =>
                {
                    resolved = true;
                    return new SpecEventHandler<ModuleChecked>(ev => { });
                });

            settigs.Action(new object());
            resolved.Should().Be.False();
        }
        public void ActionShouldBeFilteredByType()
        {
            var resolved = 0;
            var called = 0;

            var originalSettigs = new TypedHandlingSettings<SystemChecked>(
                () =>
                {
                    resolved++;
                    return new SpecEventHandler<SystemChecked>(ev => { called++; });
                }, 
                priority: 99);

            var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.PreCompleted);

            using (var uow = new UnitOfWork())
            {
                settigs.Action(new object());
                settigs.Action(new object());
                resolved.Should().Be(0);
                called.Should().Be(0);
                uow.Complete();
                resolved.Should().Be(0);
                called.Should().Be(0);
            }

            resolved.Should().Be(0);
            called.Should().Be(0);

            using (var uow = new UnitOfWork())
            {
                settigs.Action(new SystemChecked());
                settigs.Action(new SystemChecked());
                resolved.Should().Be(0);
                called.Should().Be(0);
                uow.Complete();
                resolved.Should().Be(2);
                called.Should().Be(2);
            }

            resolved.Should().Be(2);
            called.Should().Be(2);
        }
        public void ActionShouldBeFilteredByFilters()
        {
            var resolved = false;
            var called = false;
            var filters = new List<Func<ModuleChecked, bool>> { ev => ev.HealthLevel > 98, ev => ev.HealthLevel < 100 };

            var settigs = new TypedHandlingSettings<ModuleChecked>(
                () =>
                {
                    resolved = true;
                    return new SpecEventHandler<ModuleChecked>(ev => { called = true; });
                }, 
                filters);

            settigs.Action(new ModuleChecked(98));
            resolved.Should().Be.False();
            settigs.Action(new ModuleChecked(100));
            resolved.Should().Be.False();
            settigs.Action(new ModuleChecked(99));
            resolved.Should().Be.True();
            called.Should().Be.True();
        }
        public void OriginalActionShouldBeCalledWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified()
        {
            var resolved = 0;
            var called = 0;

            var originalSettigs = new TypedHandlingSettings<SystemChecked>(
                () =>
                {
                    // ReSharper disable once AccessToModifiedClosure
                    resolved++;

                    // ReSharper disable once AccessToModifiedClosure
                    return new SpecEventHandler<SystemChecked>(ev => { called++; });
                }, 
                priority: 99);

            var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.Finished);

            using (var uow = new UnitOfWork())
            {
                settigs.Action(new SystemChecked());
                settigs.Action(new SystemChecked());
                resolved.Should().Be(0);
                called.Should().Be(0);
                uow.Complete();
                resolved.Should().Be(0);
                called.Should().Be(0);
            }

            resolved.Should().Be(2);
            called.Should().Be(2);

            resolved = 0;
            called = 0;

            try
            {
                using (var uow = new UnitOfWork("test"))
                {
                    // ReSharper disable once UnusedVariable
                    var session = ((IWrapper)uow).WrappedObject;

                    settigs.Action(new SystemChecked());
                    settigs.Action(new SystemChecked());
                    resolved.Should().Be(0);
                    called.Should().Be(0);
                    uow.Complete();
                }
            }
            catch (NotSupportedException)
            {
            }

            resolved.Should().Be(0);
            called.Should().Be(0);
        }
        public void SubscriberShouldBeIgnoredIfIsUsedOutsideOfUnitOfWork()
        {
            var resolved = false;
            var called = false;

            var originalSettigs = new TypedHandlingSettings<SystemChecked>(
                () =>
                {
                    resolved = true;
                    return new SpecEventHandler<SystemChecked>(ev => { called = true; });
                }, 
                priority: 99);

            var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.Finished);

            settigs.Action(new SystemChecked());
            resolved.Should().Be.False();
            called.Should().Be.False();
        }
        public void ActionShouldBeSafeToNull()
        {
            var resolved = false;

            var settigs = new TypedHandlingSettings<ModuleChecked>(
                () =>
                {
                    resolved = true;
                    return null;
                });

            settigs.Action(new ModuleChecked(98));
            resolved.Should().Be.True();
        }