Inheritance: AbstractHandlingSettings
コード例 #1
0
        public void AllBasicParametersShouldBeSet()
        {
            var settigs = new BatchedHandlingSettings(typeof(ModuleChecked), DelayUntil.Finished, 1000);

            settigs.Type.Should().Be(typeof(ModuleChecked));
            settigs.Priority.Should().Be(1000);
        }
コード例 #2
0
        public void ActionShouldBeFilteredByType()
        {
            var called = 0;
            IEventBatch<SystemChecked> batch = null;
            using (Events.Subscribe<IEventBatch<SystemChecked>>(
                ev =>
                {
                    // ReSharper disable once AccessToModifiedClosure
                    called++;
                    batch = ev;
                }))
            {
                var settigs = new BatchedHandlingSettings(typeof(SystemChecked), DelayUntil.Finished, 1000);

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

                called.Should().Be(0);
                batch.Should().Be.Null();

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

                called.Should().Be(1);
                batch.Should().Not.Be.Null();
                batch.Events.Should().Have.Count.EqualTo(2);

                called = 0;
                batch = null;

                using (var uow = new UnitOfWork())
                {
                    settigs.Action(new ModuleChecked());
                    settigs.Action(new ModuleChecked());
                    called.Should().Be(0);
                    batch.Should().Be.Null();
                    uow.Complete();
                    called.Should().Be(0);
                    batch.Should().Be.Null();
                }

                called.Should().Be(1);
                batch.Should().Not.Be.Null();
            }
        }
コード例 #3
0
        public void EventBatchShouldBePublishedWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified()
        {
            var called = 0;
            IEventBatch<SystemChecked> batch = null;
            using (Events.Subscribe<IEventBatch<SystemChecked>>(
                ev =>
                {
                    // ReSharper disable once AccessToModifiedClosure
                    called++;
                    batch = ev;
                }))
            {
                var settigs = new BatchedHandlingSettings(typeof(SystemChecked), DelayUntil.Finished, 1000);

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

                called.Should().Be(1);
                batch.Should().Not.Be.Null();
                batch.Events.Should().Have.Count.EqualTo(2);

                called = 0;
                batch = null;

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

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

                called.Should().Be(0);
                batch.Should().Be.Null();
            }
        }
コード例 #4
0
        public void EventBatchShouldBePublishedBeforeUnitOfWorkCompletionIfAppropriateStageIsSpecified()
        {
            var called = 0;
            IEventBatch<SystemChecked> batch = null;
            using (Events.Subscribe<IEventBatch<SystemChecked>>(
                ev =>
                {
                    // ReSharper disable once AccessToModifiedClosure
                    called++;
                    batch = ev;
                }))
            {
                var settigs = new BatchedHandlingSettings(typeof(SystemChecked), DelayUntil.PreCompleted, 1000);

                using (var uow = new UnitOfWork())
                {
                    settigs.Action(new SystemChecked());
                    settigs.Action(new SystemChecked());
                    called.Should().Be(0);
                    batch.Should().Be.Null();
                    uow.Complete();
                    called.Should().Be(1);
                    batch.Should().Not.Be.Null();
                    batch.Events.Should().Have.Count.EqualTo(2);
                }

                called.Should().Be(1);
                batch.Should().Not.Be.Null();
                batch.Events.Should().Have.Count.EqualTo(2);
            }
        }
コード例 #5
0
        public void EventPublishingShouldBeIgnoredIfIsUsedOutsideOfUnitOfWork()
        {
            var called = 0;

            using (Events.Subscribe<IEventBatch<ModuleChecked>>(ev => { called++; }))
            {
                var settigs = new BatchedHandlingSettings(typeof(ModuleChecked), DelayUntil.Finished, 100);
                settigs.Action(new ModuleChecked());
            }

            called.Should().Be(0);
        }
コード例 #6
0
 private bool Equals(BatchedHandlingSettings other)
 {
     return Type == other.Type && delayUntil == other.delayUntil && Priority == other.Priority && Unique == other.Unique;
 }