Exemple #1
0
        /// <summary>
        /// Instantiates aggregates from the events within the scenario, and optionally runs projection catchups through specified handlers.
        /// </summary>
        /// <returns>A Scenario based on the specifications built-up using a <see cref="ScenarioBuilder" />.</returns>
        /// <exception cref="System.InvalidOperationException">Already prepared</exception>
        public virtual Scenario Prepare()
        {
            EnsureScenarioHasNotBeenPrepared();

            beforePrepare.ForEach(@do => @do());

            prepared = true;

            scenario = new Scenario(this);

            var configurationContext = ConfigurationContext.Establish(configuration);

            configurationContext.AllowOverride = true;
            scenario.RegisterForDispose(configurationContext);
            scenario.RegisterForDispose(configuration);

            if (configuration.IsUsingSqlEventStore())
            {
                // capture the highest event id from the event store before the scenario adds new ones
                startCatchupAtEventId = CreateEventStoreDbContext().DisposeAfter(db => db.Events.Max <StorableEvent, long?>(e => e.Id) ?? 0) + 1;
            }

            SourceAggregatesFromInitialEvents();
            SubscribeProjectors();
            RunCatchup();
            SubscribeConsequenters();

            // command scheduling
            InitialEvents.ForEach(ScheduleIfNeeded);

            return(scenario);
        }
Exemple #2
0
        /// <summary>
        /// Instantiates aggregates from the events within the scenario, and optionally runs projection catchups through specified handlers.
        /// </summary>
        /// <returns>A Scenario based on the specifications built-up using a <see cref="ScenarioBuilder" />.</returns>
        /// <exception cref="System.InvalidOperationException">Already prepared</exception>
        public virtual Scenario Prepare()
        {
            EnsureScenarioHasNotBeenPrepared();

            beforePrepare.ForEach(@do => @do());

            prepared = true;

            // command scheduling
            if (!configuration.IsUsingInMemoryCommandScheduling())
            {
                var clockName = "TEST-" + Guid.NewGuid().ToString("N").ToETag();
                Configuration.Properties["CommandSchedulerClockName"] = clockName;
                Configuration.Container.Register <GetClockName>(c => e => clockName);
                var clockRepository = Configuration.SchedulerClockRepository();
                clockRepository.CreateClock(clockName, Clock.Now());
            }

            configuration.EnsureCommandSchedulerPipelineTrackerIsInitialized();

            scenario = new Scenario(this);

            var configurationContext = ConfigurationContext.Establish(configuration);

            configurationContext.AllowOverride = true;
            scenario.RegisterForDispose(configurationContext);
            scenario.RegisterForDispose(configuration);

            if (configuration.IsUsingSqlEventStore())
            {
                // capture the highest event id from the event store before the scenario adds new ones
                startCatchupAtEventId = configuration.EventStoreDbContext()
                                        .DisposeAfter(db => db.HighestEventId()) + 1;
            }

            SourceAggregatesFromInitialEvents();
            SubscribeProjectors();
            RunCatchup();
            SubscribeConsequenters();

            InitialEvents.ForEach(ScheduleIfNeeded);

            return(scenario);
        }