public async Task InitializeAndWarmUp()
        {
            var eventStore = Wireup.Init()
                             .UsingSqlPersistence(null, "System.Data.SqlClient", ConnectionString)
                             .WithDialect(new MsSqlDialect())
                             .UsingJsonSerialization()
                             .Build();

            _outbox = new NEventStoreOutbox(eventStore, TimeSpan.Zero);
            var options = new DbContextOptionsBuilder().UseSqlServer(ConnectionString).Options;
            var db      = new TestDbContextWithOutbox(options, _outbox);

            try
            {
                _ = db.Users.FirstOrDefault();
            }
            catch (SqlException)
            {
                await db.Database.EnsureDeletedAsync();

                await db.Database.EnsureCreatedAsync();
            }

            eventStore.Advanced.Initialize();
            await WarmUp();
        }
示例#2
0
        public async Task EnsureSchemaInitialized()
        {
            // `receptionDelay` should include transaction timeout + clock drift. Otherwise, it may skip events during reception.
            var receptionDelay = TimeSpan.FromMilliseconds(3000);
            var eventStore     = Wireup.Init()
                                 .UsingSqlPersistence(null, "System.Data.SqlClient", ConnectionString)
                                 .WithDialect(new MsSqlDialect())
                                 .UsingJsonSerialization()
                                 .Build();

            _eventStore = eventStore;
            Outbox      = new NEventStoreOutbox(eventStore, receptionDelay);
            var options = new DbContextOptionsBuilder().UseSqlServer(ConnectionString).Options;
            var db      = new TestDbContextWithOutbox(options, Outbox);

            try
            {
                _ = db.Users.FirstOrDefault();
            }
            catch (SqlException)
            {
                await db.Database.EnsureDeletedAsync();

                await db.Database.EnsureCreatedAsync();
            }

            eventStore.Advanced.Initialize();
            eventStore.Advanced.Purge();
        }