Exemplo n.º 1
0
        public void LocalDbForSingleTest()
        {
            // The database will be recreated here if it already exists
            using (TempLocalDb db = new TempLocalDb("Test"))
            {
                // Create the schema in the database (This tool will work best if you are using some kind of database migration tool like FluentMigrator or DbUp)
                SchemaHelper.MigrateToCurrentSchema(db);

                // Call some code that interacts with the database
                DatabaseService dbService = new DatabaseService(db.ConnectionString);
                dbService.Insert("First", "Last");

                // Verify that the code worked correctly
                using (var conn = db.Open())
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM [Person] WHERE [FirstName] = @FirstName AND [LastName] = @LastName";
                        cmd.Parameters.AddWithValue("@FirstName", "First");
                        cmd.Parameters.AddWithValue("@LastName", "Last");

                        using (var reader = cmd.ExecuteReader())
                        {
                            // Just verify that the record exists in the table
                            Assert.IsTrue(reader.Read());
                        }
                    }

                // OR Call some other methods to verify the operation worked
                Assert.IsNotNull(dbService.FirstOrDefault("First", "Last"));
            }
        }
Exemplo n.º 2
0
        public static void Initialize(TestContext context)
        {
            database = new TempLocalDb("Test");

            // Create schema for tests
            // If you want to run tests against your database, you should execute your migrations or creation script here
            SchemaHelper.MigrateToCurrentSchema(database);
        }
Exemplo n.º 3
0
 public string Start(string databaseName)
 {
     _database = new TempLocalDb(databaseName);
     return(_database.ConnectionString);
 }