Beispiel #1
0
        public void TestDatabase1SchemaChangeToDatabase2Ok()
        {
            //SETUP
            var connectionString = this.GetUniqueDatabaseConnectionString();
            var builder1         = new DbContextOptionsBuilder <DbContext1>();

            using (var context = new DbContext1(builder1.UseSqlServer(connectionString).Options))
                using (new TimeThings(_output, "EnsureDeleted/EnsureCreated"))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                }
            var builder2 = new DbContextOptionsBuilder <DbContext2>();

            using (var context = new DbContext2(builder2.UseSqlServer(connectionString).Options))
            {
                //ATTEMPT
                using (new TimeThings(_output, "EnsureClean"))
                {
                    context.Database.EnsureClean();
                }

                //VERIFY
                context.Add(new TopClass2());
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public void TestEnsureDeletedThenCreateDatabase2Ok()
        {
            //SETUP
            var showLog = false;

#pragma warning disable 618
            var options = this.CreateUniqueClassOptionsWithLogging <DbContext2>(log =>
#pragma warning restore 618
            {
                if (showLog)
                {
                    _output.WriteLine(log.Message);
                }
            });
            using (var context = new DbContext2(options))
            {
                context.Database.EnsureDeleted();

                //ATTEMPT
                showLog = true;
                context.Database.EnsureClean();
                showLog = false;

                //VERIFY
                context.Add(new TopClass2());
                context.SaveChanges();
            }
        }
Beispiel #3
0
        public void TestWipeDataDatabase2Ok()
        {
            //SETUP
            var options = this.CreateUniqueMethodOptions <DbContext2>();

            using (var context = new DbContext2(options))
            {
                context.Database.EnsureCreated();
                context.Add(new TopClass2 {
                    Dependents = new List <Dependent2> {
                        new Dependent2()
                    }
                });
                context.SaveChanges();
                context.TopClasses.Count().ShouldEqual(1);
                context.Dependents.Count().ShouldEqual(1);

                //ATTEMPT
                context.Database.EnsureClean();

                //VERIFY
                context.TopClasses.Count().ShouldEqual(0);
                context.Dependents.Count().ShouldEqual(0);
            }
        }