My favorites | Sign in
Project Logo
             
Show all Featured downloads:
1.0.zip
Blogs:
Feeds:

This utility makes it easy to create serialized XML DataSet's based on SQL queries run against a SQL Server.

  1. Run this program to execute a SQL statement
  2. Copy the resulting XML into a file in your .NET unit test project
  3. Embed the XML file you created
  4. In your test code, load the embedded XML, deserialize it back into a DataSet

Screencast available here!

You now have a way to mock a DataSet that would normally be loaded from a database.

How to deserialize the DataTable:

		/// <summary>
		///		Reads a <see cref="DataTable"/> from an embedded XML
		///		document that contains the serialized version.
		/// </summary>
		/// <param name="sourceAssembly">
		///		The assembly that contains the embedded file containing
		///		the XML.
		/// </param>
		/// <param name="resourceName">
		///		The qualified name of the resource to load.
		/// </param>
		/// <returns>
		///		The reconstituted <see cref="DataTable"/>.
		/// </returns>
		public static DataTable ReadEmbeddedDataTable(Assembly sourceAssembly, string resourceName)
		{
			using (Stream readStream = sourceAssembly.GetManifestResourceStream(resourceName))
			{
				XmlSerializer xs = new XmlSerializer(typeof(DataSet));
				DataSet ds = (DataSet)xs.Deserialize(readStream);

				return ds.Tables[0];
			}
		}

Related Blog Posts:









Hosted by Google Code