Example #1
0
        public void Can_save_and_query_with_explicit_services_and_explicit_config()
        {
            var services = new ServiceCollection();

            services.AddEntityFramework().AddInMemoryDatabase();
            var serviceProvider = services.BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseInMemoryDatabase();

            using (var context = new ExplicitServicesAndConfigBlogContext(serviceProvider, optionsBuilder.Options))
            {
                context.Blogs.Add(new Blog {
                    Name = "The Waffle Cart"
                });
                context.SaveChanges();
            }

            using (var context = new ExplicitServicesAndConfigBlogContext(serviceProvider, optionsBuilder.Options))
            {
                var blog = context.Blogs.SingleOrDefault();

                Assert.NotEqual(0, blog.Id);
                Assert.Equal("The Waffle Cart", blog.Name);

                context.Blogs.RemoveRange(context.Blogs);
                context.SaveChanges();

                Assert.Empty(context.Blogs);
            }
        }
        public void Can_save_and_query_with_explicit_services_and_explicit_config()
        {
            var services = new ServiceCollection();
            services.AddEntityFramework().AddInMemoryDatabase();
            var serviceProvider = services.BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            using (var context = new ExplicitServicesAndConfigBlogContext(serviceProvider, optionsBuilder.Options))
            {
                context.Blogs.Add(new Blog { Name = "The Waffle Cart" });
                context.SaveChanges();
            }

            using (var context = new ExplicitServicesAndConfigBlogContext(serviceProvider, optionsBuilder.Options))
            {
                var blog = context.Blogs.SingleOrDefault();

                Assert.NotEqual(0, blog.Id);
                Assert.Equal("The Waffle Cart", blog.Name);

                context.Blogs.RemoveRange(context.Blogs);
                context.SaveChanges();

                Assert.Empty(context.Blogs);
            }
        }