private void PopulateData()
        {
            using (BodyShopContext context = new BodyShopContext())
            {
                // Clean databases
                context.Database.EnsureDeleted();
                MySQLTestStore.DeleteDatabase("01cars");
                MySQLTestStore.DeleteDatabase("02bodyshops");
                MySQLTestStore.DeleteDatabase("03employees");
                context.Database.EnsureCreated();

                context.BodyShop.AddRange(new BodyShop
                {
                    Name  = "Western Collision Works",
                    City  = "Hollywood",
                    State = "California",
                    Brand = "Chevrolet"
                },
                                          new BodyShop
                {
                    Name  = "Yosemite Auto Body Shop",
                    City  = "Pico-Union",
                    State = "California",
                    Brand = "Ford"
                });

                context.Car.AddRange(new Car
                {
                    LicensePlate = "ATD 427",
                    Make         = "Chevrolet",
                    Model        = "Cruze",
                    State        = "New"
                },
                                     new Car
                {
                    LicensePlate = "TJC 265",
                    Make         = "Fore",
                    Model        = "Escape",
                    State        = "Used"
                });

                context.Employee.AddRange(new Employee
                {
                    FirstName   = "Jonh",
                    LastName    = "Doe",
                    DisplayName = "Jonhy",
                    Timestamp   = DateTime.Now
                },
                                          new Employee
                {
                    FirstName   = "Maurice",
                    LastName    = "Kent",
                    DisplayName = "Mau",
                    Timestamp   = DateTime.Now
                });

                context.SaveChanges();
            }
        }
 public void LoadingData()
 {
     PopulateData();
     using (BodyShopContext context = new BodyShopContext())
     {
         Assert.Equal(2, context.Car.Count());
         Assert.Equal(2, context.BodyShop.Count());
         Assert.Equal(2, context.Employee.Count());
     }
 }
Ejemplo n.º 3
0
 private void PopulateData()
 {
     using (BodyShopContext context = new BodyShopContext())
     {
         // Clean databases
         context.Database.EnsureDeleted();
         MySQLTestStore.DeleteDatabase("01cars");
         MySQLTestStore.DeleteDatabase("02bodyshops");
         MySQLTestStore.DeleteDatabase("03employees");
         context.Database.EnsureCreated();
     }
 }
Ejemplo n.º 4
0
 public void OneTimeTearDown()
 {
     using (BodyShopContext context = new BodyShopContext())
     {
         using (MySqlConnection conn = (MySqlConnection)context.Database.GetDbConnection())
         {
             MySqlCommand cmd = conn.CreateCommand();
             cmd.CommandText = @"DROP DATABASE IF EXISTS `01cars`;
     DROP DATABASE IF EXISTS `02bodyshops`;
     DROP DATABASE IF EXISTS `03employees`;";
             conn.Open();
             context.Database.EnsureDeleted();
             cmd.Connection = conn;
             cmd.ExecuteNonQuery();
         }
     }
 }
 public void MultiSchemaTest()
 {
     PopulateData();
     using (BodyShopContext context = new BodyShopContext())
     {
         using (MySqlConnection conn = (MySqlConnection)context.Database.GetDbConnection())
         {
             MySqlCommand cmd = conn.CreateCommand();
             cmd.CommandText = "SHOW DATABASES WHERE `Database` IN('01cars', '02bodyshops', '03employees')";
             conn.Open();
             List <string> databases = new List <string>(new string[] { "01cars", "02bodyshops", "03employees" });
             int           count     = 0;
             using (MySqlDataReader reader = cmd.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     Assert.True(databases.Contains(reader.GetString(0)));
                     count++;
                 }
             }
             Assert.Equal(3, count);
         }
     }
 }