Exemplo n.º 1
0
        public void TestCustomDatabaseName()
        {
            //you can also create a new database per test (it's not very fast)
            //here we customise the database name and put the file in %TEMP%
            var options = new TestDatabaseOptions("ProductContext")
            {
                DatabaseName     = "Test",
                DatabaseFilePath = Path.Combine(Path.GetTempPath(), "Test"),
                //DataSource = @".\SqlExpress", //if this is installed
            };

            var td = new CreateTestDatabase.TestDatabase(options);

            td.CreateDatabase();
            td.InitConnectionString();
            //if you've already done this with AssemblyInitialize, EF has been initialized and the connection string is different

            //NB: this isn't the connection string in app.config
            var connectionString = ConfigurationManager.ConnectionStrings["ProductContext"].ConnectionString;

            using (var con = new SqlConnection(connectionString))
            {
                Assert.AreEqual("(LocalDB)\\MSSQLLocalDB", con.DataSource);
                Assert.AreEqual("Test", con.Database);
            }
        }
Exemplo n.º 2
0
        public void TestCustomDatabaseName()
        {
            //you can also create a new database per test (it's not very fast)
            //here we customise the database name and put the file in %TEMP%
            var options = new TestDatabaseOptions("ProductContext")
                          {
                              DatabaseName = "Test",
                              DatabaseFilePath = Path.Combine(Path.GetTempPath(), "Test"),
                              //DataSource = @".\SqlExpress", //if this is installed
                          };

            var td = new CreateTestDatabase.TestDatabase(options);
            td.CreateDatabase();
            td.InitConnectionString();
            //if you've already done this with AssemblyInitialize, EF has been initialized and the connection string is different

            //NB: this isn't the connection string in app.config
            var connectionString = ConfigurationManager.ConnectionStrings["ProductContext"].ConnectionString;

            using (var con = new SqlConnection(connectionString))
            {
                Assert.AreEqual("(LocalDB)\\MSSQLLocalDB", con.DataSource);
                Assert.AreEqual("Test", con.Database);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a temporary database overriding the app.Config connectionString to create a SqlServer 14 localDb.
        /// </summary>
        /// <param name="connectionStringName">Name of the connection string.</param>
        /// <exception cref="System.ArgumentNullException">connectionStringName</exception>
        public static void Create(string connectionStringName)
        {
            if (connectionStringName == null) throw new ArgumentNullException("connectionStringName");

            var td = new TestDatabase(new TestDatabaseOptions(connectionStringName));
            td.CreateDatabase();
            td.InitConnectionString();
        }