Ejemplo n.º 1
0
        public void Can_save_and_query_with_explicit_services_and_OnConfiguring()
        {
            var services = new ServiceCollection();

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

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

            using (var context = new ExplicitServicesImplicitConfigBlogContext(serviceProvider))
            {
                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_OnConfiguring()
        {
            var services = new ServiceCollection();
            services.AddEntityFramework().AddInMemoryDatabase();
            var serviceProvider = services.BuildServiceProvider();

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

            using (var context = new ExplicitServicesImplicitConfigBlogContext(serviceProvider))
            {
                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);
            }
        }