Geeks With Blogs

News INETA Community Speakers Program
GeeksWithBlogs.net: WTFNext's hosting!

View Stacy Vicknair's profile on LinkedIn


WTF Next? Dev ramblings from a master of nothing.

This week I had a need for NUnit based unit testing against a class that depended on a provided SqlConnection. Up to this point I had been able to mock external objects and their behavior based on interfaces, but with a SqlConnection I could not mock. There are some options for mocking the SqlConnection such as TypeMock, but I needed a realistic connection to test against. This also proved as a good method for building the expected DB interface.

The solution that worked best for my environment (only SQL Server 2000, all machines have OSQL) was to execute an OSQL process from my TestFixtureSetUp that executed a .sql script I had already made for building the database. So my TestFixtureSetUp looked like this:

<TestFixtureSetUp()> _
Sub FixtureSetUp()
    Dim p As Process = Process.Start("OSQL.exe", "-E -S SERVER -i ""../SQL SCRIPTS/setup.sql""")
    p.WaitForExit()
End Sub

The script itself was quick and assumed that the database and procedures existed already. It deleted all entries from the table and then added some dummy values. However, this method could be used to create the entire DB if needed, but does have the strong assumption that the computer using it has OSQL installed.

I won’t go into much detail about OSQL. OSQL is a tool that comes with SQL Server Tools that allows execution of sql batch scripts from the command-line. Its usage is explained well in the MSDN.

 

Posted on Friday, August 14, 2009 11:55 AM VB .NET | Back to top


Comments on this post: Automating SQL Server 2000 based database generation with OSQL in .NET

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Stacy Vicknair | Powered by: GeeksWithBlogs.net