<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pushing Pixels &#187; Software Development</title>
	<atom:link href="http://familywhitfield.co.uk/wordpress/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://familywhitfield.co.uk/wordpress</link>
	<description>Computing and Digital Imaging</description>
	<lastBuildDate>Thu, 24 Mar 2011 20:54:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>A simple Perforce backup script for the home</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/07/07/a-simple-perforce-backup-script-for-the-home/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/07/07/a-simple-perforce-backup-script-for-the-home/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 20:46:38 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Perforce]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[PC]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=24</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/07/07/a-simple-perforce-backup-script-for-the-home/' addthis:title='A simple Perforce backup script for the home' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>I use the free license of Perforce on my home network just to ensure version control and management of home coding projects, university thesis stuff, and general files that I just want to ensure I have previous versions of. It&#8217;s a really nice part of the Perforce licensing model that I can get two users [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/07/07/a-simple-perforce-backup-script-for-the-home/' addthis:title='A simple Perforce backup script for the home' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>I use the free license of <a href="http://www.perforce.com">Perforce</a> on my home network just to ensure version control and management of home coding projects, university thesis stuff, and general files that I just want to ensure I have previous versions of. It&#8217;s a really nice part of the Perforce licensing model that I can get two users and five clients for free. My network has my main PC (with Perforce depot), my personal laptop, my wife&#8217;s laptop, and my work laptop all connected. It&#8217;ll get worse when my four-year old starts wanting to source control things from his PC!</p>
<p>Having been responsible for some pretty heavyweight Perforce installations in my working life, I did not want to forget the golden rule of checkpointing and backing up. While it would not be a disaster if my Perforce data got lost or messed up, it would be an inconvenience. The scripts published on Perforce user forums, however, tend to be focussed on industrial installations and can be quite complex. For the home it is nice to have something more simple.<br />
<span id="more-24"></span></p>
<p>So the script here is really aimed at the home user. I don&#8217;t use Perforce everyday at home, and so a nightly checkpoint and backup is a waste of time. I tend to run it every two to four weeks. My environment is that I have my main home PC running Perforce, and hanging off this on a USB-2 link is a Western-Digital MyBook external drive that shows itself as D: .  Sitting in the Perforce root folder (where the P4 db.* files are, and defined by the P4ROOT environment variable), I have a simple batch file called &#8220;backup.bat&#8221; (see code below).</p>
<p>The basic backup mechanism is this:</p>
<ol>
<li>Stop the Perforce server</li>
<li>Take a checkpoint</li>
<li>Copy checkpoint to a location on the MyBook external disk</li>
<li>Copy checkpoints to a location on the main PC &#8211; just duplication for safety</li>
<li>Delete checkpoints from P4ROOT</li>
<li>Use Robocopy to incrementally backup all depot files for each depot</li>
<li>Restart Perforce server</li>
</ol>
<p>Here&#8217;s the script. Just copy it into a .bat file put it into the P4ROOT folder. To run it, either do as a scheduled task or &#8211; as I do &#8211; just run it manually at whatever frequency you are happy with.</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">REM  *** Backs up Perforce</span>
p4 admin stop
p4d -jc -z
<span style="color: #b1b100; font-weight: bold;">copy</span> *.gz d:\Perforce\checkpoints
<span style="color: #b1b100; font-weight: bold;">copy</span> *.gz old_checkpoints
<span style="color: #b1b100; font-weight: bold;">del</span> /Q /F *.gz
<span style="color: #808080; font-style: italic;">rem *** now backup depot files. See following text for explanation</span>
robocopy depot d:\perforce\depotfiles\depot /S /E /MIR /R:1 /W:5 <span style="color: #33cc33;">&amp;</span>gt;robolog-depot.txt
robocopy perforce d:\perforce\depotfiles\perforce /S /E /MIR /R:1 /W:5 <span style="color: #33cc33;">&amp;</span>gt;<span style="color: #33cc33;">&amp;</span>gt;robolog-p4.txt
robocopy work d:\perforce\depotfiles\work /S /E /MIR /R:1 /W:5 <span style="color: #33cc33;">&amp;</span>gt;<span style="color: #33cc33;">&amp;</span>gt;robolog-work.txt
<span style="color: #808080; font-style: italic;">rem *** Restart server</span>
net start Perforce</pre></div></div>

<p>The three robocopy lines reflect that I have three depots on my server &#8211; &#8216;depot&#8217;, &#8216;perforce&#8217;, and &#8216;work&#8217;. Change these to reflect your own depots.</p>
<p>Robocopy is a free utility that runs under Windows that provides extremely flexible folder copy functionality. See the <a href="http://en.wikipedia.org/wiki/Robocopy">Wikipedia entry</a> for more details. Just make sure it is either on your search path, or place the EXE in the P4ROOT folder.</p>
<p>The options given to Robocopy just tell it to only copy files that are different to those that already exist. In otherwords, it synchronises one folder structure to another. I pipe the output into a log file so I can see exactly what new files have been copied if I need to.</p>
<p>And that&#8217;s it. Dead simple &#8211; will take you two minutes to set up, but could save you hours of hassle should something go awry in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/07/07/a-simple-perforce-backup-script-for-the-home/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughts on a &#8216;Powerful&#8217; API</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 16:02:41 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=17</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/' addthis:title='Thoughts on a &#8216;Powerful&#8217; API' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>One of the words that keeps coming up when I have conversations about new products is that the API must be &#8220;powerful&#8221;. While intuitively this sounds good &#8211; after all, who wants to develop an API that is a bit wimpy &#8211; how can you measure and judge the power of one API over another? [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/' addthis:title='Thoughts on a &#8216;Powerful&#8217; API' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>One of the words that keeps coming up when I have conversations about new products is that the API must be &#8220;powerful&#8221;. While intuitively this sounds good &#8211; after all, who wants to develop an API that is a bit wimpy &#8211; how can you measure and judge the power of one API over another? I&#8217;m pretty sure that you can&#8217;t assign a wattage to a function call.<br />
<span id="more-17"></span></p>
<p>Say we have a scene graph that lets a caller insert objects into a hierarchy. An object can reference other objects using  a standard instancing metaphor. Lets say this manifests itself like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Add child node to parent</span>
<span style="color: #0000ff;">int</span> SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">AddObject</span> <span style="color: #008000;">&#40;</span>Node <span style="color: #000040;">*</span>parent, <span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>child<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Such an API makes it easy to put in a circular dependency, which would cause subsequent scene graph traversals to loop ad-infinitum. So it would be trivial here to make the method check that parent and child are not the same. But what if parent is indirectly reference by child? E.g.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">start with A <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span> B <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span> C
call SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">AddObject</span> <span style="color: #008000;">&#40;</span>C, A<span style="color: #008000;">&#41;</span></pre></div></div>

<p>So, if AddObject were to be &#8220;powerful&#8221;, would it check for this and return an error? It would certainly make the method robust, as you could not poke invalid data at it. But does robust==powerful?</p>
<p>I would say no. Because even though it stops a user doing something daft that could be hard to diagnose, it does not scale. If the code has to traverse the graph every time a new node is added to the scene graph, then the act of building a model with hundreds or thousands of objects will execute in O(n^2) time complexity. By making this API robust, you actually reduce its power by imposing an overhead upon the user.</p>
<p>Most scene building code will be well behaved &#8211; there will be enough knowledge at the application end to &#8220;know&#8221; that the data is good. And for those times when the application does not know, we can supply a method like:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Check if one object is a child of another</span>
<span style="color: #0000ff;">bool</span> SceneGraph<span style="color: #008080;">::</span><span style="color: #007788;">IsChild</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>n0, <span style="color: #0000ff;">const</span> Node <span style="color: #000040;">*</span>n1<span style="color: #008000;">&#41;</span></pre></div></div>

<p>Application code can then query only when needed. The &#8220;power&#8221; here is in enabling the user to make the decision on balancing cost against convenience.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/04/18/thoughts-on-a-powerful-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips for returning IDENTITY values from INSERT</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/#comments</comments>
		<pubDate>Sun, 14 Jan 2007 17:04:00 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=16</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/' addthis:title='Tips for returning IDENTITY values from INSERT' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>There&#8217;s a good article by Scott Guthrie here that describes the basics. Just scroll down to Tutorial 5 for the INSERT specific bit &#8211; it is pretty straightforward and there is no point my repeating it here. One point to note, however, and why I wrote this particular post. The key step in getting this [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/' addthis:title='Tips for returning IDENTITY values from INSERT' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>There&#8217;s a good article by Scott Guthrie <a href="http://aspalliance.com/914_Building_a_DAL_using_Strongly_Typed_TableAdapters_and_DataTables_in_VS_2005_and_ASPNET_20">here</a> that describes the basics. Just scroll down to Tutorial 5 for the INSERT specific bit &#8211; it is pretty straightforward and there is no point my repeating it here.</p>
<p>One point to note, however, and why I wrote this particular post. The key step in getting this working is changing the query type from NonQuery to Scalar. But this can get reset by Visual Studio if you choose the Configure option on the ObjectDataSource&#8217;s smart tags to modify the query in any way. If you don&#8217;t notice this, then suddenly the identity value stops getting returned and your code breaks.</p>
<p>The second tip is that by default the type returned by the insert query is decimal. This can cause some extra casting in your code if you were expecting it to be int. To fix this, just modify the SQL in Scott&#8217;s original article to be this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">CAST</span> <span style="color: #66cc66;">&#40;</span>SCOPE_IDENTITY<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/14/tips-for-returning-identity-values-from-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining row counts for all tables in a database</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 22:02:33 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[test driven development]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=13</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/' addthis:title='Determining row counts for all tables in a database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>Here is a usful snippet if you want a way to get the number of rows in each table in your database. I use this in an admin-only page of the web application to provide some at-a-glance statistics. It is also really useful in unit tests for checking the correctness of business logic that may [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/' addthis:title='Determining row counts for all tables in a database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>Here is a usful snippet if you want a way to get the number of rows in each table in your database. I use this in an admin-only page of the web application to provide some at-a-glance statistics. It is also really useful in unit tests for checking the correctness of business logic that may create new entries in several tables in one transaction.</p>
<p><span id="more-13"></span></p>
<h3>SQL snippet</h3>
<p>The bit of SQL is quite straightforward, once you delve down into the depths of SQLServer&#8217;s system tables:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
   so<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TableName<span style="color: #66cc66;">,</span>
   <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>si<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">ROWS</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>RowCount<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
   sys<span style="color: #66cc66;">.</span>sysobjects <span style="color: #993333; font-weight: bold;">AS</span> so
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span>
   sys<span style="color: #66cc66;">.</span>sysindexes <span style="color: #993333; font-weight: bold;">AS</span> si
   <span style="color: #993333; font-weight: bold;">ON</span> OBJECT_ID<span style="color: #66cc66;">&#40;</span>so<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> si<span style="color: #66cc66;">.</span>id
<span style="color: #993333; font-weight: bold;">WHERE</span>
   <span style="color: #66cc66;">&#40;</span>so<span style="color: #66cc66;">.</span>xtype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'U'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> so<span style="color: #66cc66;">.</span>name
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> TableName</pre></div></div>

<h2>Presenting in a page</h2>
<p>There are a number of ways of getting this into an ASP2 page. I chose to do this via a new table adaptor, and to wrap the query in an Administration class in the business logic layer.</p>
<p>Paste the SQL snippet from above into the query builder to create a new table adapter on the data designer &#8211; I have a separate &#8220;admin.xsd&#8221; to keep these non-user level types away from the core application data types. By default you will get an  adapter called &#8220;sysobjectsTableAdapter&#8221; as it picks its name up from the first table in the query. You can change this if you need to.</p>
<p>You can now go direct to an ASP page by pointing an ObjectDataSource directly at this table adapter, or you can wrap it in an intermediate layer.</p>
<h2>Unit test example</h2>
<p>My unit test framework has a database reset mechanism that empties all tables and then creates a small set of known test data using the business logic layer (BLL). This empty and reset is done in the test fixture setup, and the subsequent raft of tests use a variety of methods to valid the integrity of the data.</p>
<p>A key test is ensuring that the expected number of rows in various tables have been created. This is particularly important as there are a number of linking and cross reference tables that are not directly seen by a user, but are there for the efficiency of the schema. So checking  all these have been set correctly after the BLL has done its work is vital.</p>
<p>In the test class I have something like this :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>TestFixture<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> DBReset
<span style="color: #008000;">&#123;</span> <span style="color: #008000;">....</span>
   <span style="color: #0600FF; font-weight: bold;">private</span> Dictionary TableRowCounts  <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary <span style="color: #008000;">;</span>
   <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#91;</span>TestFixtureSetup<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> FixtureSetup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Addresses&quot;</span>, <span style="color: #FF0000;">6</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span> <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Agencies&quot;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This sets up a list of all the tables I am interested in and maps the expected number of rows for each table after my fixture setup has initialised the database with known data.</p>
<p>I then have the following unit test as part of this fixture:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
 <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> CheckRowCountsExpected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Verifies that the correct number of rows in each database</span>
    <span style="color: #008080; font-style: italic;">// has been created as a result of the reset and test</span>
    <span style="color: #008080; font-style: italic;">// data initialisation.</span>
    AdminBll abll <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AdminBll<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    Admin<span style="color: #008000;">.</span><span style="color: #0000FF;">sysobjectsDataTable</span> tabs <span style="color: #008000;">=</span> abll<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTableRowCounts</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Admin<span style="color: #008000;">.</span><span style="color: #0000FF;">sysobjectsRow</span> trow <span style="color: #0600FF; font-weight: bold;">in</span> tabs<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
       <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>TableRowCounts<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span> <span style="color: #008000;">&#40;</span>trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
       <span style="color: #008000;">&#123;</span>
          <span style="color: #008080; font-style: italic;">//Only check the tables specified in the dictionary</span>
          Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>TableRowCounts<span style="color: #008000;">&#91;</span>trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#93;</span>,
             trow<span style="color: #008000;">.</span><span style="color: #0000FF;">RowCount</span>,
             <span style="color: #666666;">&quot;Wrong rowcount for table &quot;</span> <span style="color: #008000;">+</span> trow<span style="color: #008000;">.</span><span style="color: #0000FF;">TableName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
       <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>I also have a second test that verifies the admin query against each table one at a time using direct SELECT COUNT queries in SQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/11/determining-row-counts-for-all-tables-in-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful CSV reader</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/#comments</comments>
		<pubDate>Wed, 10 Jan 2007 09:51:04 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=12</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/' addthis:title='Useful CSV reader' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>To aid my unit testing I needed to populate a database with a load of test data. This data needs to be generated by some of the less technical guys on the project and so exporting CSV (Comma Separated Values) files from Excel seemed a sensible approach. So I then cast around for any existing [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/' addthis:title='Useful CSV reader' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p>To aid my unit testing I needed to populate a database with a load of test data. This data needs to be generated by some of the less technical guys on the project and so exporting CSV (Comma Separated Values) files from Excel seemed a sensible approach. So I then cast around for any existing code that would save me having to write a robust CSV parser. The search turned up this on <a href="http://www.codeproject.com/">CodeProject</a>:</p>
<p><a href="http://www.codeproject.com/cs/database/CsvReader.asp">LumenWorks.Framework </a></p>
<p>The neat thing about it is that you can get field values either by index position or column name, assuming you put column headers in your file. The column name feature really helps out with maintainance of the test data as we evolve and vary the schema slightly &#8211; we can insert columns with no worries about upsetting existing reader code.<br />
It&#8217;s easy to use and install in your own project, and the CodeProject article describes the basic usage pattern. At the moment it is just linked in to the unit test framework, but is so useful I will probably make it a part of the core application libary to facilitate importing data from customers as we anticipate some of our customers could have thousands of records to import when they move to our system.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/10/useful-csv-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t believe NUnit</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/05/dont-believe-nunit/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/05/dont-believe-nunit/#comments</comments>
		<pubDate>Fri, 05 Jan 2007 11:07:39 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP2]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Nunit]]></category>
		<category><![CDATA[test driven development]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=11</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/05/dont-believe-nunit/' addthis:title='Don&#8217;t believe NUnit' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>Just a quick note about a little problem I found using Nunit (2.2.9, but affects earlier revisions too). After a bunch of edits to my project, I suddenly started getting messages from NUnit GUI &#8220;could not load file or assembly nunit.core&#8221;. Try as I could, this would not go away. This included everything from reinstalling [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/05/dont-believe-nunit/' addthis:title='Don&#8217;t believe NUnit' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p><em>Just a quick note about a little problem I found using Nunit (2.2.9, but affects earlier revisions too).</em></p>
<p>After a bunch of edits to my project, I suddenly started getting messages from NUnit GUI &#8220;could not load file or assembly nunit.core&#8221;. Try as I could, this would not go away. This included everything from reinstalling NUnit to tracking DLL loading via SysInternal&#8217;s Process Explorer tool.<br />
My project is non trivial &#8211; a top level solution containing an ASP2 web project, a couple of library DLL&#8217;s for the business logic, a unit test executable, and a testing helper library to help cross reference test results against direct SQL calls. As I&#8217;ll be writing about in another post shortly, incorporating unit testing into an ASP project is a pain in the rear and so I had been restructuring things. My natural assumption based on the error message was I had messed up something in the linking/referencing.</p>
<p>But it turned out to be an error in the application config file &#8211; for some reason NUnit reports this as a DLL missing, not that you have mistyped a bit of config text. I simply had a closing  tag in the wrong place &#8211; still syntactically correct, however.<br />
<a title="Nunit DLL load issue" href="http://vibhu.info/2007/01/02/wierd-issue-could-not-load-file-or-assembly-nunitcore/">This link</a> is by someone else who hit the exact same problem, and he has written about in more detail.</p>
<p>So remember folks: <em>never assume a system generates the correct error message for all circumstances. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/05/dont-believe-nunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perforce server logging problem</title>
		<link>http://familywhitfield.co.uk/wordpress/2007/01/02/perforce-server-logging-problem/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2007/01/02/perforce-server-logging-problem/#comments</comments>
		<pubDate>Tue, 02 Jan 2007 13:04:30 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Perforce]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=6</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/02/perforce-server-logging-problem/' addthis:title='Perforce server logging problem' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>When setting up a server it is often useful to enable one of the logging levels. The admin guide states that you need to do this: p4 set P4DEBUG=server=2 which sets the server logging level to 2. You then need to restart the Perforce server. However, if Perforce is running as a service (the default [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2007/01/02/perforce-server-logging-problem/' addthis:title='Perforce server logging problem' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p class="MsoNormal"><span lang="EN-GB">When setting up a server it is often useful to enable one of the logging levels. The <a href="http://www.perforce.com/perforce/doc.061/manuals/p4sag/03_superuser.html#1079236" target="_blank">admin guide</a> states that you need to do this:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN-GB">p4 set      P4DEBUG=server=2 </span></li>
</ul>
<p class="MsoNormal"><span lang="EN-GB"><br />
which sets the server logging level to 2. You then need to restart the Perforce server.</span></p>
<p>However, if Perforce is running as a service (the default under Windows), then this does not work. The reason is that &#8220;p4 set&#8221; only sets the variable in for HKEY_CURRENT_USER in the Windows registry. However, when running as a service, p4d picks up its environment variables from HKEY_LOCAL_MACHINE. To do this you need to set the &#8216;-s&#8217; flag. E.g.</p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN-GB">p4 set -s      P4DEBUG=server=2 </span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2007/01/02/perforce-server-logging-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding ASP Role tables to your own database</title>
		<link>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/#comments</comments>
		<pubDate>Fri, 29 Dec 2006 23:17:25 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=5</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/' addthis:title='Adding ASP Role tables to your own database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>This is still work in progress, but I want to incorporate the user role management tables within my own database, as the concept of users and their distinct roles ties right in with the core business model of the new site. The following link explains the standalone tool to create the tables: ASP.NET SQL Server [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/' addthis:title='Adding ASP Role tables to your own database' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p class="MsoNormal" style="margin-bottom: 12pt;"><span lang="EN-GB">This is still work in progress, but I want to incorporate the user role management tables within my own database, as the concept of users and their distinct roles ties right in with the core business model of the new site.<br />
The following link explains the standalone tool to create the tables:<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms229862.aspx" target="_blank">ASP.NET SQL Server Registration Tool</a></span></p>
<p>Invoking the exe runs a wizard requesting the database service &#8211; it needs to match the connection string as mentioned in the gotcha above. Since no parameters are specified, it then creates a database &#8220;aspnetdb&#8221; with all the role tables. This is not quite what I want, as I need these added to my application database.</p>
<p>The answer is to use the command line:<br />
aspnet_regsql -S  -E -A all -d</p>
<p>If you run SQL Management Server Studio Express before and after &#8211; not forgetting to hit &#8216;refresh&#8217; &#8211; then a bunch of new tables are added: aspnet_Applications, aspnet_Roles, aspnet_SchemaVersions, aspnet_Users, aspnet_UsersInRoles etc. Now it is just a matter of hooking those up with the application tables.</p>
<p>Since I wanted membership and roles as well as basic authentication I used the &#8220;-A all&#8221; option to add everything in. Of course I get profile and web-part support too with this, but I may choose to exploit such features in the future.<a name="References"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2006/12/29/adding-asp-role-tables-to-your-own-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gotcha on setting up a data connection</title>
		<link>http://familywhitfield.co.uk/wordpress/2006/12/29/gotcha-on-setting-up-a-data-connection/</link>
		<comments>http://familywhitfield.co.uk/wordpress/2006/12/29/gotcha-on-setting-up-a-data-connection/#comments</comments>
		<pubDate>Fri, 29 Dec 2006 14:26:51 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP2]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://familywhitfield.co.uk/wordpress/?p=3</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/gotcha-on-setting-up-a-data-connection/' addthis:title='Gotcha on setting up a data connection' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div>This one gets me every time. When you set up a new data connection to a database running on a local copy of Sql Server Express, in the &#8220;Add Connection&#8221; dialog you need to prefix your machine name to the defaulted value of &#8220;SQLEXPRESS&#8221;. E.g. if the network name of your PC is called &#8220;devpc&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://familywhitfield.co.uk/wordpress/2006/12/29/gotcha-on-setting-up-a-data-connection/' addthis:title='Gotcha on setting up a data connection' ><a class="addthis_button_twitter"></a><a class="addthis_button_facebook"></a><a class="addthis_button_email"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_digg"></a><a class="addthis_button_compact"></a></div><p class="MsoNormal"><span lang="EN-GB">This one gets me every time. When you set up a new data connection to a database running on a local copy of Sql Server Express, in the &#8220;Add Connection&#8221; dialog you need to prefix your machine name to the defaulted value of &#8220;SQLEXPRESS&#8221;. E.g. if the network name of your PC is called &#8220;devpc&#8221;, then the connection string is:</span></p>
<ul>
<li>DEVPC\SQLEXPRESS</li>
</ul>
<p>While this is the obvious choice and works for many circumstances, a subtle variation is to use the following instead:</p>
<ul>
<li>localhost\SQLEXPRESS</li>
</ul>
<p>This now points the connection to an instance of SQL Server Express running on your local machine. If working in a team where each developer needs their own local copy of a database, then setting this in the web.config file can be a real help.</p>
]]></content:encoded>
			<wfw:commentRss>http://familywhitfield.co.uk/wordpress/2006/12/29/gotcha-on-setting-up-a-data-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

