public ServiceProviderPerContextFixtureBase()
        {
            TestStore = TestStoreFactory.GetOrCreate(StoreName);

            // Setup database.
            var serviceProvider = SetupServices();

            TestStore.Initialize(serviceProvider, () => CreateContextFromServiceProvider(serviceProvider), c => Seed((TContext)c), Clean);
        }
Beispiel #2
0
 public EmptyMigrationsContext CreateEmptyContext()
 => new EmptyMigrationsContext(
     TestStore.AddProviderOptions(
         new DbContextOptionsBuilder())
     .UseInternalServiceProvider(
         TestStoreFactory.AddProviderServices(
             new ServiceCollection())
         .BuildServiceProvider())
     .Options);
        protected TestStore CreateTestStore(Action <ModelBuilder> onModelCreating)
        {
            TestStore = TestStoreFactory.Create(DatabaseName);

            ServiceProvider = TestStoreFactory.AddProviderServices(new ServiceCollection())
                              .AddSingleton(TestModelSource.GetFactory(onModelCreating))
                              .BuildServiceProvider(validateScopes: true);

            TestStore.Initialize(ServiceProvider, CreateContext, c => ((TransportationContext)c).Seed());

            return(TestStore);
        }
Beispiel #4
0
        public PullTests()
        {
            timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();

            store = new FakeStore();
            storeFactory = new TestStoreFactory(store);

            Emit(NewId<LocalCalendar>(),
                 new RemoteCalendarAdded(
                     new FakeRemote
                     {
                         Id = NewId<RemoteCalendar>()
                     }));
        }
Beispiel #5
0
        public PullTests()
        {
            timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();

            store        = new FakeStore();
            storeFactory = new TestStoreFactory(store);

            Emit(NewId <LocalCalendar>(),
                 new RemoteCalendarAdded(
                     new FakeRemote
            {
                Id = NewId <RemoteCalendar>()
            }));
        }
Beispiel #6
0
        protected TestStore CreateTestStore(Action <ModelBuilder> onModelCreating = null, bool seed = true)
        {
            TestStore = TestStoreFactory.Create(DatabaseName);

            ServiceProvider = TestStoreFactory.AddProviderServices(new ServiceCollection())
                              .AddSingleton(TestModelSource.GetFactory(onModelCreating ?? (_ => { })))
                              .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory)
                              .BuildServiceProvider(validateScopes: true);

            TestStore.Initialize(ServiceProvider, CreateContext, c =>
            {
                if (seed)
                {
                    ((TransportationContext)c).Seed();
                }
            });

            TestSqlLoggerFactory.Clear();

            return(TestStore);
        }
        protected virtual IServiceProvider SetupServices(
            Func <IServiceCollection, IServiceCollection> addServices          = null,
            Func <DbContextOptionsBuilder, DbContextOptionsBuilder> addOptions = null,
            IServiceCollection serviceCollection = null)
        {
            serviceCollection = AddServices(TestStoreFactory.AddProviderServices(serviceCollection ?? new ServiceCollection()))
                                .AddDbContext(
                typeof(TContext),
                optionsAction: (s, b) =>
            {
                var optionsBuilder = ConfigureOptions(s, b);
                addOptions?.Invoke(optionsBuilder);
            },
                ServiceLifetime.Transient,
                ServiceLifetime.Transient);

            serviceCollection = addServices != null
                ? addServices.Invoke(serviceCollection)
                : serviceCollection;

            return(serviceCollection.BuildServiceProvider(validateScopes: true));
        }
        protected SharedStoreFixtureBase()
        {
            TestStore = TestStoreFactory.GetOrCreate(StoreName);

            var services = AddServices(TestStoreFactory.AddProviderServices(new ServiceCollection()));

            if (UsePooling)
            {
                services = services.AddDbContextPool(ContextType, (s, b) => ConfigureOptions(s, b));
            }
            else
            {
                services = services.AddDbContext(
                    ContextType,
                    (s, b) => ConfigureOptions(s, b),
                    ServiceLifetime.Transient,
                    ServiceLifetime.Singleton);
            }

            ServiceProvider = services.BuildServiceProvider(validateScopes: true);

            TestStore.Initialize(ServiceProvider, CreateContext, c => Seed((TContext)c), c => Clean(c));
        }
 protected override IServiceCollection AddServices(IServiceCollection serviceCollection)
 => base.AddServices(serviceCollection)
 .AddSingleton <ILoggerFactory>(TestStoreFactory.CreateListLoggerFactory(ShouldLogCategory));
 protected TableSplittingTestBase(ITestOutputHelper testOutputHelper)
 {
     TestSqlLoggerFactory = (TestSqlLoggerFactory)TestStoreFactory.CreateListLoggerFactory(_ => true);
     //TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
 }
 public NestedDocumentsTest(ITestOutputHelper testOutputHelper)
 {
     TestSqlLoggerFactory = (TestSqlLoggerFactory)TestStoreFactory.CreateListLoggerFactory(_ => true);
     //TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
 }