Blog Home  Home Feed your aggregator (RSS 2.0)  
Code to Live, Live to Code - Friday, September 21, 2007
Randy Patterson's BLog
 
 Friday, September 21, 2007

This is one of the most useless unit tests I've encountered

/// <summary>
///A test for GetByLegalCaseID (int)
///</summary>
[TestMethod()]
public void GetTicketByLegalCaseID_Test()
{
    TicketEntityModel target = new TicketEntityModel();
    int ID = 1;
    TicketDataSet actual = target.GetByLegalCaseID(ID);
 
    Assert.IsNotNull(actual, "TicketDataSet was not returned.");
    Assert.IsNotNull(actual.Citation, "No Citation table was returned.");
    Assert.IsTrue(actual.Citation.Rows.Count > 0, "No Citation rows were returned.");
    Assert.IsNotNull(actual.Ticket, "No Ticket table was returned.");
    Assert.IsTrue(actual.Ticket.Rows.Count > 0, "No Ticket rows were returned.");
}

 

Unit tests in the Entity Model should concentrate on testing business logic, not Data Access Layer (DAL) logic. Unit tests for DAL objects test data access issues.   Furthermore,  this Unit Test simply checks to see if the current database has a record with an ID of 1 and, therefore, is non-deterministic. It can fail for many reasons that have nothing to do with the business logic. If GetByLegalCaseID has any business logic in it then unit tests should to be written to test that logic and the dependencies on the DAL would be mocked so a previously setup DataSet is returned with known values. This falls under the "What Burns Me" category. 

Friday, September 21, 2007 8:10:15 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [5]   What Burns Me  |  Trackback
 Tuesday, September 18, 2007

The very flexible generic collection List<T> contains several methods that take a predicate as it's parameter.  Coupled with Anonymous Methods this provides powerfully concise code for filtering, searching and sorting your collections.

 

List<Person> People = new List<Person>();
 
People.Add(new Person("Randy", "Patterson", 40));
People.Add(new Person("John", "Smith", 15));
People.Add(new Person("Caity", "Johnson", 13));
People.Add(new Person("Jody", "Patterson", 39));
People.Add(new Person("Chloe", "Dog", 30));
People.Add(new Person("Corey", "Patterson", 18));

 

For Example,  to filter the collection and display only my family members requires a single line of code

IList<Person> family = People.FindAll(delegate(Person person) { return person.LastName == "Patterson"; });
 

And produces the following output

image

To remove the teenagers (not a bad proposition) also requires a single line

People.RemoveAll(delegate(Person person) { return person.Age > 12 && person.Age < 20; });

Sorting

Sorting requires a Comparison<T> delegate instead of Predicate<T> but operates in much the same fashion.

For example, sorting by last name requires this single line of code:

People.Sort(delegate(Person x, Person y) {return x.LastName.CompareTo(y.LastName) ;});

a slight modification will sort the list in descending order:

People.Sort(delegate(Person x, Person y) { return y.LastName.CompareTo(x.LastName); });

To sort by Last Name then First Name would look something like this:

People.Sort(delegate(Person x, Person y)
    {
        if (x.LastName == y.LastName)
            return x.FirstName.CompareTo(y.FirstName);
        else
            return x.LastName.CompareTo(y.LastName);
    });

 

Conclusion

I've just scratched the surface on what the generic List collection is capable of providing. There are several other generic methods that take delegates as parameters, such as ForEach and ConvertAll, that open up interesting possibilities in your code.   Overall I find the Anonymous Method syntax a bit kludgy but C# 3.0 promises to reduce the syntactical noise and give us true (almost) Lambda Expressions

kick it on DotNetKicks.com

Tuesday, September 18, 2007 8:40:57 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [8]   C#  |  Trackback
 Saturday, September 15, 2007

Not really related to software development but Instant Conference is one of those gems occasionally found while surfing the tubes.

image 

You just give them an email address and you get back a conference number and an access code........that's it! The dial in number and access code are dedicated to you and never expire.  While in the conference there are many advanced features such as Conference Recording and Presentation Mode.

image

I've used my number several times and found the quality to be pretty good and the features easy to use.  If you record your conference you'll get an email in an hour or so that will allow you to download an MP3 file.  A nice feature for verifying your notes.

Saturday, September 15, 2007 7:50:29 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]   Deals  |  Trackback

Welcome back to my Blog.  I've had a blog for awhile but, due to a heavy work load,  I haven't posted anything in over a year.  In the past year I've implemented many of the principles of GTD to better manage my professional, personal and online time.  This will, hopefully, allow me to Work, Live and Play without the stress involved in miss-managing time.

I've also removed my previous Blog and blog postings and started fresh with a new version of DasBlog and new postings. It was a pleasant surprise to see the maturity of the blog engines as well as the software to help you post your content.  I am currently using Windows Live Writer for content publishing, which has a very active community for Plug-in's.

Saturday, September 15, 2007 4:09:49 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]    |  Trackback
Copyright © 2008 Randy Patterson. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.