Ejemplo n.º 1
0
        public void Global_store_can_be_used_when_AddDbContext_force_different_internal_service_provider()
        {
            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .EnableServiceProviderCaching(false)
                       .UseInMemoryDatabase(nameof(BooFooContext), _databaseRoot)
                       .Options))
            {
                context.Add(new Boo());
                context.SaveChanges();
            }

            var serviceProvider = new ServiceCollection()
                                  .AddDbContext <BooFooContext>(
                b =>
                b.UseInMemoryDatabase(nameof(BooFooContext), _databaseRoot)
                .EnableServiceProviderCaching(false))
                                  .BuildServiceProvider();

            using var scope = serviceProvider.CreateScope();
            {
                var context = scope.ServiceProvider.GetService <BooFooContext>();
                Assert.Equal(1, context.Boos.Count());
            }
        }
Ejemplo n.º 2
0
        public void Owned_types_are_found_correctly_with_database_root()
        {
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase("20784", _databaseRoot)
                          .Options;

            using (var context = new BooFooContext(options))
            {
                context.Add(new Foo {
                    Goo1 = null, Goo2 = new Goo()
                });
                context.Add(new Boo {
                    Goo1 = new Goo(), Goo2 = new Goo()
                });
                context.SaveChanges();

                var foos = context.Foos.Single();
                Assert.Null(foos.Goo1);
                Assert.NotNull(foos.Goo2);

                var boos = context.Boos.Single();
                Assert.NotNull(boos.Goo1);
                Assert.NotNull(boos.Goo2);
                Assert.NotSame(boos.Goo1, boos.Goo2);
            }

            using (var context = new BooFooContext(options))
            {
                var foos = context.Foos.Single();
                Assert.Null(foos.Goo1);
                Assert.NotNull(foos.Goo2);

                var boos = context.Boos.Single();
                Assert.NotNull(boos.Goo1);
                Assert.NotNull(boos.Goo2);
                Assert.NotSame(boos.Goo1, boos.Goo2);
            }
        }
Ejemplo n.º 3
0
        public void Global_store_can_be_used_when_options_force_different_internal_service_provider()
        {
            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .UseInMemoryDatabase(nameof(BooFooContext), _databaseRoot)
                       .Options))
            {
                context.Add(new Foo());
                context.SaveChanges();
            }

            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .UseInMemoryDatabase(nameof(BooFooContext), _databaseRoot)
                       .EnableSensitiveDataLogging()
                       .Options))
            {
                Assert.Equal(1, context.Foos.Count());
            }
        }
Ejemplo n.º 4
0
        public void Different_stores_are_used_when_options_force_different_internal_service_provider()
        {
            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .UseInMemoryDatabase(nameof(BooFooContext))
                       .Options))
            {
                context.Add(new Foo());
                context.SaveChanges();
            }

            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .UseInMemoryDatabase(nameof(BooFooContext))
                       .EnableSensitiveDataLogging()
                       .Options))
            {
                Assert.Empty(context.Foos.ToList());
            }
        }
Ejemplo n.º 5
0
        public void Different_stores_are_used_when_AddDbContext_force_different_internal_service_provider()
        {
            using (var context = new BooFooContext(
                       new DbContextOptionsBuilder()
                       .UseInMemoryDatabase(nameof(BooFooContext))
                       .Options))
            {
                context.Add(new Foo());
                context.SaveChanges();
            }

            var serviceProvider = new ServiceCollection()
                                  .AddDbContext <BooFooContext>(
                b => b.UseInMemoryDatabase(nameof(BooFooContext)))
                                  .BuildServiceProvider();

            using (var scope = serviceProvider.CreateScope())
            {
                var context = scope.ServiceProvider.GetService <BooFooContext>();
                Assert.Empty(context.Foos.ToList());
            }
        }