Posts
69
Comments
233
Trackbacks
162
January 2006 Entries
Enterprise Libray for .NET 2.0 is out!
 The waiting is over. Microsofts Patterns & Practices Group has just released the new Enterprise Library for .NET 2.0 to the public. It is an easy to use and graphically configurable collection of application blocks that help you to build Enterprise Scale managed applications. This is release is for:
  1. Anybody who is interested in best programming practices for .NET 2.0.
  2. If you need a good Caching solution which survives an application crash.
  3. You want to log messages to the Event Log, Email them or send it somewhere else (e.g. database).
  4. Access (nearly) any database without the need to deal with the specialties of the underlying database.
  5. Secure your applications by using role based authorization.
  6. Handle exceptions in a common way throughout your application.
  7. Encrypt data using symmetric encryption/Hash passwords.
Gogogogo the MSDN servers might be overloaded for the next few weeks from now on ;-)
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Friday, January 20, 2006 7:06 PM | Feedback (0)
Why Unit Tests and TDD are good

With the advent of unit test frameworks like JUnitNUnit, MBUnit, ... and the new Visual Studio Team System a plethora of articles and books spread the news that unit tests are a nice thing in every programmers toolbox. We all know that solid software engineering requires a certain amount of testing. Everybody knows it and only few actually do it. This might have to do with pressing time schedules and human laziness which most programmers follow: Achieve good results with the least amount of work. Additional testing does not seem to spare work but generates new one. I can't deny that fact but to point out that it is often overlooked that quality will go up right at the beginning of your project. This can help you to reduce your stress level when the release date comes nearer and you are confident that you have squeezed out most bugs of your code base. One relatively new methodology is TDD (Test Driven Development).
At MSDN there was content which did not describe real  TDD. The content has been removed and is reworked at the moment. The essence of TDD is that your code and tests evolve continuously during development. It is not a waterfall model where you define at first all your test cases, then create your code and never look back what you could have made better or (even worse) have missed. Instead you define at first the requirements and design upon your current knowledge the test cases which are the easiest to implement and watch them fail. Now you can implement the desired functionality and have your first green light in your unit test. Look at the code see if it is well designed and move on to the next feature you want to implement a test case ... look back, refactor and so on. A very informative blog about TDD can be found here.

With .NET 2.0 a very nice attribute was introduced to enable you to create separate test assemblies (contains the unit tests) and functional assemblies (the code to be tested) more easily. With the separation of testing and production code you face the problem that you cannot test classes and data types which are marked as internal in the functional assemblies. What you really would like to do is to allow your test assemblies access to your internal types. This is exactly what InternalsVisibleTo attribute allows you to do.

[assembly: InternalsVisibleTo("YourTestAssemblyName")]

Lets hope that this attribute will be always so simple. There are critical voices out there that fear that you should be forced to sign the test assembly to prevent the creation of fake test assemblies and use the internal types in a not intended way. I do not think that this risk is so big of the following two reasons:

  1. You can always inspect other types by using reflection.
  2. Lutz Roeders Reflector  will find anything you every wanted to hide anyway.

Use unit tests and your stress level will decrease after the shipment date of your product because fewer customers will complain about the same obvious bugs which should have been found during the development cycle. At unit test level it is a red light on your screen, after shipment it is a angry customer and a big red light on your managers screen...

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Tuesday, January 10, 2006 9:45 PM | Feedback (3)
Read/Write App.config with .NET 2.0/Enterprise Library
This time I would like to show you the most important changes in the System.Configuration namespace with .NET 2.0.
I have looked at my blog referrer statistics and saw about 20 hits/day by google. Most of them were searching 
infos how to configure the new Enterprise Library but also a significant number of people which seem to seek guidance to the
following questions:
  • How to read/write to App.Config?
  • How to store a list of objects in a config file via the System.Configuration mechanism?
Reason enough for me to shed more light on the System.Configuration namespace.
The main changes from .NET 1.0/1.1 in the System.Configuration namespace are:
  • Write to your App.Config file through the Configuration class.
  • New configuration model for Windows Forms applications.
  • Store complex objects including object collections in your App.Config File.
  • It is possible to store Connection Strings in the App.Config file see ConnectionSettings this enables you to store you settings on a SQL Server. The Enterprise Library for Sample SqlConfiguration exercises this by implementing a SqlConfigurationSource which can store and retrieve a ConfigurationSection.
So where to start? I think I show you at first the config file and explain how you can create it programtically in your application.

The easiest way to read/write AppSettings

If you want to store only key/value pairs in your App.config file there is a special section in reserved which allows you to do exactly that. Simply add an <appsettings> section and add your data as key/value pairs of the form <add key="xxx" value="xxxx" />. Thats all to create new app.config file with settings in it.

App.Config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <appSettings>

    <add key="Setting1" value="Very" />

    <add key="Setting2" value="Easy" />

  </appSettings>

</configuration>



Show more ....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Wednesday, January 04, 2006 11:00 PM | Feedback (3)