Beispiel #1
0
        public void SetUp()
        {
            Clock.Reset();

            Command <Order> .AuthorizeDefault = (order, command) => true;

            disposables = new CompositeDisposable
            {
                Disposable.Create(Clock.Reset)
            };

            schedule = GetScheduleDelegate();

            commandsScheduled = new ConcurrentBag <IScheduledCommand>();
            commandsDelivered = new ConcurrentBag <IScheduledCommand>();

            var configuration = new Configuration()
                                .TraceScheduledCommands() // trace to console
                                .TraceScheduledCommands(
                onScheduling: _ => { },
                onScheduled: c => commandsScheduled.Add(c),
                onDelivering: _ => { },
                onDelivered: c => commandsDelivered.Add(c));

            Configure(configuration);

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
        public void SetUp()
        {
            aggregateId    = Any.Guid();
            sequenceNumber = Any.PositiveInt();

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(new Configuration()
                                               .UseSqlStorageForScheduledCommands(c => c.UseConnectionString(TestDatabases.CommandScheduler.ConnectionString)))
            };

            if (clockName == null)
            {
                clockName = Any.CamelCaseName();

                using (var db = Configuration.Current.CommandSchedulerDbContext())
                {
                    db.Clocks.Add(new CommandScheduler.Clock
                    {
                        Name      = clockName,
                        StartTime = Clock.Now(),
                        UtcNow    = Clock.Now()
                    });

                    db.SaveChanges();
                }
            }


            using (var db = Configuration.Current.CommandSchedulerDbContext())
            {
                db.Database.ExecuteSqlCommand("delete from PocketMigrator.AppliedMigrations where MigrationScope = 'CommandSchedulerCleanup'");
            }
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable();
            // disable authorization
            Command <Order> .AuthorizeDefault           = (o, c) => true;
            Command <CustomerAccount> .AuthorizeDefault = (o, c) => true;

            disposables.Add(VirtualClock.Start());

            customerAccountId = Any.Guid();

            configuration = new Configuration()
                            .UseInMemoryCommandScheduling()
                            .UseInMemoryEventStore()
                            .TraceScheduledCommands();

            customerRepository = configuration.Repository <CustomerAccount>();
            orderRepository    = configuration.Repository <Order>();

            customerRepository.Save(new CustomerAccount(customerAccountId)
                                    .Apply(new ChangeEmailAddress(Any.Email())));

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Beispiel #4
0
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId  = Any.Word();
            target    = new CommandTarget(targetId);
            store     = new InMemoryStore <CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            configuration = new Configuration()
                            .UseInMemoryCommandScheduling()
                            .UseDependency <IStore <CommandTarget> >(_ => store)
                            .UseDependency <GetClockName>(c => _ => clockName)
                            .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler <CommandTarget>();

            Command <CommandTarget> .AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Beispiel #5
0
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId  = Any.Word();
            target    = new CommandTarget(targetId);
            store     = new InMemoryStore <CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            CommandSchedulerDbContext.NameOrConnectionString =
                @"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True; MultipleActiveResultSets=False; Initial Catalog=ItsCqrsTestsCommandScheduler";

            configuration = new Configuration()
                            .UseInMemoryCommandScheduling()
                            .UseDependency <IStore <CommandTarget> >(_ => store)
                            .UseDependency <GetClockName>(c => _ => clockName)
                            .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler <CommandTarget>();

            Command <CommandTarget> .AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Beispiel #6
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);
        }
        public void SetUp()
        {
            Command <CustomerAccount> .AuthorizeDefault = (order, command) => true;
            Command <Order> .AuthorizeDefault           = (order, command) => true;
            var configuration = new Configuration()
                                .UseInMemoryEventStore();

            disposables = new CompositeDisposable(ConfigurationContext.Establish(configuration));
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable();

            Command <Order> .AuthorizeDefault = (order, command) => true;
            EventStoreDbTest.SetConnectionStrings();
            configuration = GetConfiguration();
            disposables.Add(ConfigurationContext.Establish(configuration));
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable();

            Command <Order> .AuthorizeDefault = (order, command) => true;
            configuration = GetConfiguration();
            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Beispiel #10
0
        public void Configuration_Contexts_cannot_be_nested()
        {
            using (ConfigurationContext.Establish(new Configuration()))
            {
                Action establishAnother = () => ConfigurationContext.Establish(new Configuration());

                establishAnother.ShouldThrow <InvalidOperationException>();
            }
        }
        public void Setup()
        {
            Command <Target> .AuthorizeDefault = (account, command) => true;

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(new Configuration()
                                               .UseInMemoryEventStore(traceEvents: true))
            };
        }
Beispiel #12
0
        public void Configuration_Current_returns_the_Configuration_set_in_ConfigurationContext_Establish()
        {
            var configuration = new Configuration();

            using (var context = ConfigurationContext.Establish(configuration))
            {
                Configuration.Current.Should().BeSameAs(configuration);
                Configuration.Current.Should().BeSameAs(context.Configuration);
            }
        }
Beispiel #13
0
        public void SetUp()
        {
            Command <Order> .AuthorizeDefault = (order, command) => true;

            var configuration = new Configuration()
                                .UseSqlEventStore()
                                .UseSqlStorageForScheduledCommands();

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
Beispiel #14
0
        public void SetUp()
        {
            disposables = new CompositeDisposable();

            Command <Order> .AuthorizeDefault = (order, command) => true;
            CommandSchedulerDbContext.NameOrConnectionString =
                @"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True; MultipleActiveResultSets=False; Initial Catalog=ItsCqrsTestsCommandScheduler";
            configuration = GetConfiguration();
            disposables.Add(ConfigurationContext.Establish(configuration));
        }
        public void SetUp()
        {
            var configuration = new Configuration()
                                .UseInMemoryEventStore();

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(configuration),
                configuration
            };
        }
        public override void SetUp()
        {
            base.SetUp();

            var configuration = new Configuration()
                                .UseSqlEventStore(c =>
                                                  c.UseConnectionString(EventStore.ConnectionString));

            disposables.Add(
                ConfigurationContext.Establish(configuration));
        }
Beispiel #17
0
        public void SetUp()
        {
            Command <CustomerAccount> .AuthorizeDefault = (order, command) => true;
            Command <Order> .AuthorizeDefault           = (order, command) => true;

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(new Configuration()
                                               .UseInMemoryCommandScheduling()
                                               .UseInMemoryEventStore())
            };
        }
        public override void SetUp()
        {
            TestDbConfiguration.UseSqlAzureExecutionStrategy = false;

            base.SetUp();

            var configuration = new Configuration()
                                .UseSqlEventStore(c => c.UseConnectionString(TestDatabases.EventStore.ConnectionString));

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
        public void SetUp()
        {
            Command <Order> .AuthorizeDefault = (order, command) => true;

            disposables = new CompositeDisposable();

            var configuration = new Configuration()
                                .UseInMemoryEventStore()
                                .UseInMemoryCommandScheduling();

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
Beispiel #20
0
        public void SetUp()
        {
            // disable authorization
            Command <FakeAggregateWithEnactCommandConvention> .AuthorizeDefault  = (o, c) => true;
            Command <FakeAggregateWithNestedCommandConvention> .AuthorizeDefault = (o, c) => true;
            Command <Order> .AuthorizeDefault = (o, c) => true;

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(new Configuration()
                                               .IgnoreScheduledCommands())
            };
        }
        public override void SetUp()
        {
            base.SetUp();

            var configuration = new Configuration()
                                .UseSqlEventStore(c =>
                                                  c.UseConnectionString(TestDatabases.EventStore.ConnectionString));

            disposables.Add(
                ConfigurationContext.Establish(configuration));
            disposables.Add(
                VirtualClock.Start());
        }
Beispiel #22
0
        public void SetUp()
        {
            // disable authorization
            Command <Order> .AuthorizeDefault           = (o, c) => true;
            Command <CustomerAccount> .AuthorizeDefault = (o, c) => true;

            disposables = new CompositeDisposable();

            var configurationContext = ConfigurationContext
                                       .Establish(new Configuration()
                                                  .UseInMemoryEventStore()
                                                  .IgnoreScheduledCommands());

            disposables.Add(configurationContext);
        }
        public void SetUp()
        {
            // this is a shim to make sure that the Test.Domain.Ordering.Api assembly is loaded into the AppDomain, otherwise Web API won't discover the controller type
            var controller = new OrderApiController();

            disposables = new CompositeDisposable();

            Command <Order> .AuthorizeDefault = (order, command) => true;

            var configuration = new Configuration()
                                .UseInMemoryEventStore()
                                .UseInMemoryCommandScheduling();

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
        public virtual void SetUp()
        {
            // disable authorization checks
            Command <Order> .AuthorizeDefault           = (order, command) => true;
            Command <CustomerAccount> .AuthorizeDefault = (order, command) => true;

            var configuration = new Configuration();

            Configure(configuration);

            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(configuration),
                configuration
            };
        }
Beispiel #25
0
        public void SetUp()
        {
            // disable authorization checks
            Command <Order> .AuthorizeDefault           = (order, command) => true;
            Command <CustomerAccount> .AuthorizeDefault = (account, command) => true;

            var configuration = new Configuration();

            Configure(configuration);
            disposables = new CompositeDisposable
            {
                ConfigurationContext.Establish(configuration),
                configuration,
                VirtualClock.Start(),
                Disposable.Create(() => onSave = null)
            };
        }
Beispiel #26
0
        public void OneTimeSetUp()
        {
            disposables = new CompositeDisposable();

            var configuration = new Configuration()
                                .UseSqlStorageForScheduledCommands(
                c => c.UseConnectionString(CommandSchedulerConnectionString));

            disposables.Add(ConfigurationContext.Establish(configuration));

            Database.Delete(MigrationsTestEventStore.ConnectionString);
            Database.Delete(CommandSchedulerConnectionString);
            Database.Delete(MigrationsTestReadModels.ConnectionString);

            InitializeEventStore();
            InitializeCommandScheduler();
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            configuration = new Configuration()
                            .UseInMemoryCommandScheduling()
                            .UseInMemoryEventStore(traceEvents: true);

            playerRepo = configuration.Repository <MarcoPoloPlayerWhoIsNotIt>();
            itRepo     = configuration.Repository <MarcoPoloPlayerWhoIsIt>();

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
        public void SetUp()
        {
            eventStoreDbTest = new EventStoreDbTest();
            clockName        = Any.CamelCaseName();

            VirtualClock.Start();

            disposables = new CompositeDisposable
            {
                Disposable.Create(() => eventStoreDbTest.TearDown())
            };

            var configuration = new Configuration();

            Configure(configuration);

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
Beispiel #29
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);
        }
Beispiel #30
0
        public override void SetUp()
        {
            base.SetUp();

            using (VirtualClock.Start(DateTimeOffset.Now.AddMonths(1)))
            {
                disposables      = new CompositeDisposable();
                Settings.Sources = new ISettingsSource[] { new ConfigDirectorySettings(@"c:\dev\.config") }.Concat(Settings.Sources);

                serviceBusSettings                = Settings.Get <ServiceBusSettings>();
                serviceBusSettings.NamePrefix     = "itscqrstests";
                serviceBusSettings.ConfigureQueue = q =>
                {
                    q.AutoDeleteOnIdle = TimeSpan.FromMinutes(15);
                };

                bus             = new FakeEventBus();
                orderRepository = new SqlEventSourcedRepository <Order>(bus);

                var configuration = new Configuration()
                                    .UseSqlEventStore(() => new EventStoreDbContext())
                                    .UseEventBus(bus)
                                    .UseSqlCommandScheduling()
                                    .UseDependency <IEventSourcedRepository <Order> >(t => orderRepository);

                var clockName = Any.Paragraph(4);
                scheduler = new SqlCommandScheduler(configuration)
                {
                    GetClockName = @event => clockName
                };

                queueSender = new ServiceBusCommandQueueSender(serviceBusSettings)
                {
                    MessageDeliveryOffsetFromCommandDueTime = TimeSpan.FromSeconds(30)
                };

                disposables.Add(scheduler.Activity.Subscribe(s => Console.WriteLine("SqlCommandScheduler: " + s.ToJson())));
                disposables.Add(queueSender.Messages.Subscribe(s => Console.WriteLine("ServiceBusCommandQueueSender: " + s.ToJson())));
                disposables.Add(bus.Subscribe(scheduler));
                disposables.Add(configuration);
                disposables.Add(ConfigurationContext.Establish(configuration));
            }
        }