<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4579304318317852079</id><updated>2012-01-09T15:41:50.893-08:00</updated><category term='delphi is keyword'/><category term='NUnit'/><category term='MSAccess'/><category term='SQL'/><category term='JOIN'/><category term='SQL Server'/><category term='NUnut'/><category term='UPDATE'/><category term='Switch'/><category term='Datta Model'/><category term='SQLServer'/><category term='iteration'/><category term='Matthew MacDonald'/><category term='delphi'/><category term='pascal'/><category term='C#'/><category term='Classes'/><category term='Reflection'/><category term='Visual Studio 2008'/><category term='Syntax'/><category term='TADOQuery'/><category term='TDD'/><category term='Properties'/><category term='DRY Principle'/><category term='PropertyInfo'/><category term='TComponent'/><category term='DELETE'/><category term='Case'/><category term='delphi7'/><category term='CSharp'/><category term='VB.Net'/><category term='Pragmatic Programmer'/><category term='WPF'/><category term='Unit Testing'/><title type='text'>McBean Information Technology</title><subtitle type='html'>Thoughts on Software Development and other types of Punishment</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-7066898709529887716</id><published>2010-06-24T13:25:00.000-07:00</published><updated>2010-06-24T14:12:11.551-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQLServer'/><category scheme='http://www.blogger.com/atom/ns#' term='Datta Model'/><category scheme='http://www.blogger.com/atom/ns#' term='MSAccess'/><category scheme='http://www.blogger.com/atom/ns#' term='Switch'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Case'/><title type='text'>SQL: Case, Switch and Data Models</title><content type='html'>I was trying to remember how to do a &lt;span style="font-style:italic;"&gt;case&lt;/span&gt; statement in an MS-Access Query. Having worked mostly in SQL Server the last while I forgot that MS-Access uses the &lt;span style="font-style:italic;"&gt;switch&lt;/span&gt; keyword instead of &lt;span style="font-style:italic;"&gt;case&lt;/span&gt;. The syntax is very similar.&lt;br /&gt;&lt;br /&gt;A case or switch statement in SQL allows you to translate a specific value of a field into another value. It is often used to translate something meaningless like an enum or numeric identifier into something readable. It is often used in views or reports.&lt;br /&gt;&lt;br /&gt;In the following example the MSAccess switch statement is used to translate an enumeration field into readable text:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt; SELECT switch([T_Member.FamilyTypeId]=1,&amp;quot;parent&amp;quot;,[T_Member.FamilyTypeId]=2,&amp;quot;dependent&amp;quot;) AS SomeFieldName FROM SomeTable&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms181765.aspx"&gt;SQL Server Books Online (2005)&lt;/a&gt; shows a simple example of the case statement:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;USE AdventureWorks2008R2;&lt;br /&gt;GO&lt;br /&gt;SELECT   ProductNumber, Category =&lt;br /&gt;      CASE ProductLine&lt;br /&gt;         WHEN 'R' THEN 'Road'&lt;br /&gt;         WHEN 'M' THEN 'Mountain'&lt;br /&gt;         WHEN 'T' THEN 'Touring'&lt;br /&gt;         WHEN 'S' THEN 'Other sale items'&lt;br /&gt;         ELSE 'Not for sale'&lt;br /&gt;      END,&lt;br /&gt;   Name&lt;br /&gt;FROM Production.Product&lt;br /&gt;ORDER BY ProductNumber;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now that I've shown you how to do these statements properly, I'm going to argue why you should never use them.&lt;br /&gt;&lt;br /&gt;Almost always a case statement means the data model is incomplete. A case statement basically inserts ad hoc lookup tables randomly though-out your SQL statements. As good designers will say, hard-coded text values or numeric literals in any type of code are a maintenance nightmare. How hard is it to extend the data model to provide text definitions of the things you are translating with a case statement?&lt;br /&gt;&lt;br /&gt;I feel the same way about the use of case statements in programming languages. The logic is static and cannot be changed except through rebuilding and redeploying. Adding an additional case label to a statement is out of reach for the system administrator, whether SQL or code.&lt;br /&gt;&lt;br /&gt;Case or switch fields are not editable by the user. In some cases views that use them can make the entire row not editable. But almost all GUIs support editing of foreign keys through drop downs boxes. &lt;br /&gt;&lt;br /&gt;I would argue that case and switch statements should never be used in SQL statements, and focus instead on complete data models, with proper relationships.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-7066898709529887716?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/7066898709529887716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=7066898709529887716' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7066898709529887716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7066898709529887716'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2010/06/sql-case-switch-and-data-models.html' title='SQL: Case, Switch and Data Models'/><author><name>Robert McBean</name><uri>http://www.blogger.com/profile/14635243141745018756</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-i2P4Rr2TXOA/TgOiBm8bGvI/AAAAAAAAA7U/oshGV_WbP48/s220/023%2B-%2BCopy.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-2358176724997612984</id><published>2010-01-12T17:37:00.000-08:00</published><updated>2010-01-12T17:37:20.298-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='DRY Principle'/><category scheme='http://www.blogger.com/atom/ns#' term='PropertyInfo'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='NUnit'/><title type='text'>Testing C# Class Properties With NUnit - Part 2</title><content type='html'>In a previous post I showed how to auto-test object properties in a NUnit test. I forgot to include a function called GetProperties() which was referenced in the code example.  Here it is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;       /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// An test that iterates through an object's properties and does&lt;br /&gt;        /// a very minimal test on get/set integrity.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;patient&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;        public ArrayList GetProperties(Patient patient)&lt;br /&gt;        {&lt;br /&gt;            ArrayList Properties = new ArrayList();&lt;br /&gt;            PropertyInfo[] propertyInfo = patient.GetType().GetProperties();&lt;br /&gt;&lt;br /&gt;            foreach(PropertyInfo item in propertyInfo)&lt;br /&gt;            {&lt;br /&gt;                Properties.Add(item.Name);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            return Properties;&lt;br /&gt;        }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Of course this is pretty simple minded and should be re-factored in any number of ways. Most importantly to get rid of the specific object reference and make it generic. Cut and paste programming makes us angry, very very angry.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-2358176724997612984?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/2358176724997612984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=2358176724997612984' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/2358176724997612984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/2358176724997612984'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2010/01/testing-c-class-properties-with-nunit.html' title='Testing C# Class Properties With NUnit - Part 2'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-4982676070812109246</id><published>2009-05-22T01:02:00.000-07:00</published><updated>2009-05-22T01:09:17.360-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JOIN'/><category scheme='http://www.blogger.com/atom/ns#' term='Syntax'/><category scheme='http://www.blogger.com/atom/ns#' term='DELETE'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>The Weird Syntax of SQL DELETE From a JOIN</title><content type='html'>It is perfectly legal in most SQL dialects to DELETE records that come from a JOIN clause.  However, I never remember the syntax because its kind of strange and I don't do it often.&lt;br /&gt;&lt;br /&gt;I wrote the following example in SQL Server 2005:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;delete from arledger &lt;br /&gt;from arledger&lt;br /&gt;inner join arinvoice on arinvoice.arinvoiceid = arledger.invoicenumber&lt;br /&gt;where arinvoice.brokersaleid = 2259&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Nothing complicated. Just note line 2 where the FROM clause is repeated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-4982676070812109246?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/4982676070812109246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=4982676070812109246' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/4982676070812109246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/4982676070812109246'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2009/05/weird-syntax-of-sql-delete-from-join.html' title='The Weird Syntax of SQL DELETE From a JOIN'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-7492555162062824009</id><published>2009-03-05T23:11:00.000-08:00</published><updated>2009-03-05T23:18:13.342-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='Matthew MacDonald'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Current Reading</title><content type='html'>I'm currently reading Pro WPF in C# 2008 by Matthew MacDonald. So far it seems well written and I'm getting a good feel for WPF. I'm anxious to do my first WPF project but didn't want to just jump in without some background. &lt;br /&gt;&lt;br /&gt;However, ultimately you can't learn a technology without jumping in and making a whole bunch of stupid mistakes.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;iframe src="http://rcm-ca.amazon.ca/e/cm?t=fivoffiv-20&amp;o=15&amp;p=8&amp;l=as1&amp;asins=1590599624&amp;md=07AN74PQXHR1PJRCZ582&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-7492555162062824009?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/7492555162062824009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=7492555162062824009' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7492555162062824009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7492555162062824009'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2009/03/current-reading.html' title='Current Reading'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-7596802133317807321</id><published>2009-03-04T22:51:00.000-08:00</published><updated>2009-03-04T22:53:15.984-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='VB.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Reflection'/><title type='text'>Article on Setting Properties Dynamically</title><content type='html'>For the previous post on NUnit and testing properties using reflection I was indebted to &lt;a href="http://www.wwwcoder.com/tabid/68/type/art/parentid/452/site/6086/default.aspx"&gt;this article&lt;/a&gt;.  The code examples in this article are in VB.Net.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-7596802133317807321?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/7596802133317807321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=7596802133317807321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7596802133317807321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7596802133317807321'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2009/03/article-on-setting-properties.html' title='Article on Setting Properties Dynamically'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-5189762905350896696</id><published>2009-03-04T21:57:00.000-08:00</published><updated>2009-03-04T22:14:33.586-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Unit Testing'/><category scheme='http://www.blogger.com/atom/ns#' term='NUnut'/><category scheme='http://www.blogger.com/atom/ns#' term='Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='TDD'/><category scheme='http://www.blogger.com/atom/ns#' term='Pragmatic Programmer'/><category scheme='http://www.blogger.com/atom/ns#' term='Classes'/><title type='text'>Testing C# Class Properties With NUnit</title><content type='html'>In their book Pragmatic Programing Andrew Hunt and David Thomas argue that all programmers should adhere to the DRY principle.  DRY stands for do not repeat yourself. Its a daily battle to keep my code library from descending into the usual cut and paste mess of massively duplicated code.&lt;br /&gt;&lt;br /&gt;I had a few C# classes that had an high number of properties and I wanted to make sure each property had a unit test to make sure they were assigning correctly. I envisioned this as being massively tedious.  I thought that a better approach might be to iterate through the properties using reflection and test them by setting and retrieving test values. This would also mean I wouldn't have to change the unit test if I added, deleted or renamed properties.&lt;br /&gt;&lt;br /&gt;The code I came up with is very sketchy and preliminary but it does work. It can be refactored any number of ways to suit invididual tastes. In this unit test the class &lt;span style="font-style:italic;"&gt;Patient&lt;/span&gt; is being tested.&lt;br /&gt;&lt;br /&gt;I'm only testing properties of type String and Integer in this example.  You can add any type you want. I am thinking about a way to test these properties that is type independent.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;        [Test]&lt;br /&gt;        public void Properties()&lt;br /&gt;        {&lt;br /&gt;            Patient patient = new Patient();&lt;br /&gt;            int intTestData = 0;&lt;br /&gt;&lt;br /&gt;            foreach (string propertyName in GetProperties(new Patient()))&lt;br /&gt;            {&lt;br /&gt;                Type patientType = patient.GetType();&lt;br /&gt;                PropertyInfo property = patientType.GetProperty(propertyName);&lt;br /&gt;&lt;br /&gt;                &lt;br /&gt;                string stringTestData;&lt;br /&gt;&lt;br /&gt;                if (property.PropertyType == typeof(System.String))&lt;br /&gt;                {&lt;br /&gt;                    intTestData++;&lt;br /&gt;                    stringTestData = String.Format(&amp;quot;Testdata{0}&amp;quot;, intTestData);&lt;br /&gt;                    &lt;br /&gt;                    Console.WriteLine(String.Format(&amp;quot;Testing property {0} of type {1} with value {2}&amp;quot;, propertyName, property.PropertyType.ToString(),stringTestData));&lt;br /&gt;                    &lt;br /&gt;                    if (property.CanWrite == true &amp;amp;&amp;amp; property.CanRead == true)&lt;br /&gt;                    {&lt;br /&gt;                        property.SetValue(patient, stringTestData, null);&lt;br /&gt;                        Assert.AreEqual(stringTestData,property.GetValue(patient,null));&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                if (property.PropertyType == typeof(System.Int32))&lt;br /&gt;                {&lt;br /&gt;                    property.SetValue(patient, intTestData, null);&lt;br /&gt;                    Assert.AreEqual(intTestData, property.GetValue(patient, null));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm-ca.amazon.ca/e/cm?t=fivoffiv-20&amp;o=15&amp;p=8&amp;l=as1&amp;asins=020161622X&amp;md=07AN74PQXHR1PJRCZ582&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-5189762905350896696?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/5189762905350896696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=5189762905350896696' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/5189762905350896696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/5189762905350896696'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2009/03/testing-c-class-properties-with-nunit_04.html' title='Testing C# Class Properties With NUnit'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-2763882763626062554</id><published>2009-01-01T18:46:00.000-08:00</published><updated>2009-01-01T19:46:38.880-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='delphi7'/><category scheme='http://www.blogger.com/atom/ns#' term='delphi'/><category scheme='http://www.blogger.com/atom/ns#' term='TComponent'/><category scheme='http://www.blogger.com/atom/ns#' term='iteration'/><category scheme='http://www.blogger.com/atom/ns#' term='TADOQuery'/><category scheme='http://www.blogger.com/atom/ns#' term='pascal'/><category scheme='http://www.blogger.com/atom/ns#' term='delphi is keyword'/><title type='text'>Delphi: Iterating through components</title><content type='html'>The code example below shows how you can iterate through components in a Delphi form or data module, check the type of a hosted component and examine its properties. I wrote this as a unit test because the programmers were forgetting to remove their local connection strings from data objects. In this test we checked that the object has a reference to a DataConnection object and not a data connection string.&lt;br /&gt;&lt;br /&gt;This is a fairly trivial example. It is the preferred solution if you want to iterate over a set of specific objects and set properties in a consistent way without having to write repetitive code referencing specific objects. &lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;var&lt;br /&gt;  Temp: TComponent;&lt;br /&gt;  &lt;br /&gt;begin&lt;br /&gt;&lt;br /&gt;  for i := ComponentCount - 1 downto 0 do&lt;br /&gt;  begin&lt;br /&gt;    Temp := Components[i];&lt;br /&gt;    if (Temp is TADOQuery) then&lt;br /&gt;    begin&lt;br /&gt;&lt;br /&gt;      if Length(TADOQuery(Temp).ConnectionString)&amp;gt;0 then&lt;br /&gt;        raise Exception.Create('UnitTest(1): The use of a data connection string is not supported in this model.' + Temp.Name);&lt;br /&gt;&lt;br /&gt;      if TADOQuery(Temp).Connection = nil then&lt;br /&gt;        raise Exception.Create('UnitTest(2): A default connection object should be specified. ' + Temp.Name);&lt;br /&gt;&lt;br /&gt;    end;&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Some notes:&lt;br /&gt;&lt;br /&gt;The code &lt;span style="font-weight:bold;"&gt;TADOQuery(Temp).Connection&lt;/span&gt; is shorthand for casting the TComponent object to an TADOQuery object and accessing its property &lt;span style="font-weight:bold;"&gt;Connection&lt;/span&gt; at the same time. A temporary unnamed TADOQuery object is created on the stack and disappears after the code is executed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;ComponentCount&lt;/span&gt; is a property that every object has that is derived from TComponent.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-2763882763626062554?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/2763882763626062554/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=2763882763626062554' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/2763882763626062554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/2763882763626062554'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2009/01/delphi-iterating-through-components.html' title='Delphi: Iterating through components'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4579304318317852079.post-7266589778506926208</id><published>2008-12-30T16:18:00.000-08:00</published><updated>2008-12-30T18:38:04.997-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JOIN'/><category scheme='http://www.blogger.com/atom/ns#' term='UPDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>SQL Update with JOIN</title><content type='html'>I was trying to remember how to do an SQL UPDATE statement using fields from a JOIN. Its one of those things I don't do very often, and the syntax is not exactly intuitive. Its a good example of the power of SQL.&lt;br /&gt;&lt;br /&gt;The general template for such a statement is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;UPDATE [target table]&lt;br /&gt;SET clause&lt;br /&gt;FROM [target table]&lt;br /&gt;JOIN clause&lt;br /&gt;WHERE clause&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In my case I had two tables. The listing table contained items for sale and the pertinent fields were Price and Commission, both money fields.  The CommissionRate table has the same fields.  The goal was to update the Listing.Commission field from the CommissionRate table, by joining on the Price fields.&lt;br /&gt;&lt;br /&gt;The UPDATE statement ended up as:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;UPDATE Listing&lt;br /&gt;SET Listing.Commission = CommissionRate.Commission&lt;br /&gt;FROM Listing&lt;br /&gt;INNER JOIN CommissionRate ON Listing.Price = CommissionRate.SaleAmount&lt;br /&gt;WHERE Listing.Commission &lt;&gt; CommissionRate.Commission&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Refactoring:&lt;br /&gt;&lt;br /&gt;The Commission.SaleAmount field needs to be renamed to Commission.Price to be consistent within the model&lt;br /&gt;&lt;br /&gt;The WHERE clause should include a condition to NOT apply the update to certain records that should not be bulk updated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4579304318317852079-7266589778506926208?l=mcbeanit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mcbeanit.blogspot.com/feeds/7266589778506926208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4579304318317852079&amp;postID=7266589778506926208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7266589778506926208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4579304318317852079/posts/default/7266589778506926208'/><link rel='alternate' type='text/html' href='http://mcbeanit.blogspot.com/2008/12/sql-update-with-join.html' title='SQL Update with JOIN'/><author><name>Robert McBean.</name><uri>http://www.blogger.com/profile/03785114322799288514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_JXJjzAeqmZ8/S1pgZYeM_kI/AAAAAAAAAdc/Vq9U5JSf05M/S220/r+n554391767_830166_9294.jpg'/></author><thr:total>0</thr:total></entry></feed>
