AdFactum ObjectMapper .NET Blog

Official blog of the AdFactum ObjectMapper .NET

How to setup database tables instantly

Posted by Gerhard Stephan on August 9th, 2006

If you think on NUnit testing it is mandatory to ensure that your starting position is always the same. Especially when working with data that changes during a test run.

One solution for writing NUnit test is to setup new database tables before running the tests. Using the ObjectMapper .NET this can be done with a few lines.

            SqlPersister persister = new SqlPersister();

            ObjectMapper mapper = new ObjectMapper(…);



             * Add the types


            ArrayList types = new ArrayList();

            types.Add(typeof (Contact));

            types.Add(typeof (Company));



             * Create the tables instantly


            StreamWriter writer = new StreamWriter(new MemoryStream());

            persister.WriteSchemaDif(writer, types, mapper);

            writer.BaseStream.Seek(0, SeekOrigin.Begin);


            SqlFile file = new SqlFile(writer.BaseStream);



The hint is to export the tables to a memory stream and to use this stream for executing the SqlFile.


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>