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
        /// <summary>
        /// Initializes a new instance of the <see cref="TestDatabase" /> class with a database in a specified folder.
        /// </summary>
        /// <param name="testDatabaseOptions">The test database options.</param>
        /// <exception cref="System.ArgumentNullException">databaseName</exception>
        public TestDatabase(TestDatabaseOptions testDatabaseOptions)
        {
            if (testDatabaseOptions == null)
            {
                throw new ArgumentNullException("testDatabaseOptions");
            }

            _testDatabaseOptions = testDatabaseOptions;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestDatabase" /> class with a database in a specified folder.
        /// </summary>
        /// <param name="testDatabaseOptions">The test database options.</param>
        /// <exception cref="System.ArgumentNullException">databaseName</exception>
        public TestDatabase(TestDatabaseOptions testDatabaseOptions)
        {
            if (testDatabaseOptions == null) throw new ArgumentNullException("testDatabaseOptions");

            _testDatabaseOptions = testDatabaseOptions;
        }