TestRunner / ExactMagic TestMatrix

by ChrisB May 24, 2007 14:05
I used to use a Visual Studio addin product called TestRunner (www.mailframe.net)  for running my unit tests inside the browser.  I used it mainly because it also had a useful profiler, whereas TestDriven.net (www.testdriven.net) didn't.  Since installing vista, though, I've had problems with TestRunner, and have been using TestDriven.net - it has a load of cool features also, just different from TestRunner. Anyway, I got an email today from Exact Magic - apparently MailFrame has changed it's name to Exact Magic (www.exactmagic.com), and released a combination of their TestRunner product and CodeSpell product (a code spellchecker) called TestMatrix.  I've purchased the upgrade, as it's only $40 (I was a previous registered user of TestRunner) - $40 == ~£20, so it's cheap enough to try out and not use if I don't need it.  Looking at the ExactMagic website, I see they are also planning for Orcas unit testing, and Selenium testing.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

WebAii beta2, Vista & NUnit

by ChrisB May 24, 2007 11:05
After much playing with WebAii (a ".NET automation infrastructure for web testing") I've managed to get some form of test working with vista.I'm using the "Quickstart sample code" to connect to google. The sample solution provided as part of the install just fails miserably. 1. IE7 doesn't work (for me). There are two problems:
  1. From the NUnit GUI (not launched as administrator), I can run the sample code as an NUnit test. This launches IE, and connects to google. The explorerbar addin shows the AT logo and status information. Then it tries to write to a log file, which it can't do (no permission), so IE displays a "LogError: Fatal Exception. Unable to log to event log. Error: System.Security.SecurityException..." error message. This causes the test to fail with an "ArgumentNullException"
  2. If I run the NUnit GUI by launching it as administrator, it launches IE, but the explorerbar addin shows double height, and a blank interface. I suspect this is something to do with it not being properly registered / installed under the administrator profile (as IE is now launched as the administrator, and if I start IE as administrator, I get the same view of the explorerbar). The test just times out.
2. Firefox, however runs fine, whether NUnit GUI is run as administrator or not. I tend to use a Visual Studio plugin to run my NUnit tests (TestRunner or TestDriven.net) (rather than using the NUnit GUI directly), and I run VS2005 "As Administrator," (as per Microsoft recommendation's) which means that any tests are also run "as administrator". I suspect that if the Explorerbar problem were to be sorted, the tests would run fine, as the Log file wouldn't occur. I intend to link this with my cruisecontrol.net server, so I'll post the results here. If anyone has more success, please let me know! [tags]webaii, vista, visual studio, nunit, testing[/tags]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Using Visio 2003 for Database Design

by ChrisB May 18, 2007 12:05
This articles was first published at CodeProject.com^.

Introduction

Although it has many quirks, Visio 2003 for Enterprise Architects (available with MSDN premium and above), is a great tool to use when you're laying out your database design, and can be used to organize your thoughts, annotate tables and views, store stored procedures, and remain in sync with your SQL Server database. The best bit about it, though, is that although it sounds obvious, you can use multiple pages within the visio diagram.

Background

When planning a recent database project (with an anticipated 30-40 tables), I decided to make use of Visio to lay out my ideas first, rather than using something like Access, or just diving in and creating the tables in SQL Server. For this example, I will be using a very simple database design based around a membership database. I want to record the following entities:
  • Members
  • Members Notes
  • Members Subscriptions received
These entities rougly translate to the tables I will use. Also, the design is purposely simplistic.

Getting Started

Create a Database Model Diagram in Visio. Check you have Database > Generate on the menu. If you don't, then you probably have Visio Standard rather than the Enterprise Architect version. The first thing to do is to let Visio know that you're planning on using SQL Server. On the menu, go to Database > Options > Drivers and select the Microsoft Sql Server driver. The window is devided into 3 panes: Shapes, the diagram pages, and Database Properties (at the bottom).

Creating the tables

Drag an "Entity" shape onto the diagram page. In the database properties window, change the Physical name to "Member". Now click the "Columns" option in the Database Properties pane. We need to add the following columns, so just type into the boxes provided (starting with Physical Name)
Physical Name   | Data Type     | Req'd |  PK  | Notes
memberID        | int identity  | tick  | tick |
emailAddress    | varchar(200)  | tick  |      |
surname         | varchar(100)  | tick  |      |
forename        | varchar(100)  | tick  |      |
You'll notice that "int identity" and "varchar(200)" aren't in the datatype drop-down list. That's fine, you just need to type it in, rather than select from the list. You can also type in any notes to remind you what a column is for. This can prove useful at the early stages of design. Another tip is to use the space bar to tick or untick the tickable fields, and use the tab key to move between boxes. This makes it quite fast to create columns. We now have our Customer table created. On the menu, select Database > View > Tables and Views. A new pane will appear showing the list of tables that you have in your model. Now create the following tables with the following columns:
Table Name: Subscription
Physical Name   | Data Type     | Req'd |  PK  | Notes
subscriptionID  | int identity  | tick  |      |
amountDue       | smallmoney    | tick  |      |
datePaid        | smalldatetime |       |      | null if not paid.

Table Name: Note
Physical Name   | Data Type     | Req'd |  PK  | Notes
noteID          | int identity  | tick  | tick |
noteTimestamp   | smalldatetime | tick  |      | (see below).
noteText        | varchar(max)  | tick  |      |
For the noteTimestamp column of the Note table, click the Edit button, and enter get_date() into the default value field, and change the radio button so that "Is an expression or function call" is selected. We now have 3 tables that we want to link together.

Linking the tables

Drag the relationship connector shape onto the diagram. Drag the pointy end onto the Member table (let go when the table turns red), drag the blunt end onto the Note table. This will create a new foreign key column in the note table. Do the same for the subscription table. The Member table should now be linked to both the Note and Subscription table. Of course, you can also rename the new memberID column to one of your choosing, or create the memberID column first and associate it with the link later. Imagine now that we have 30 tables - they would get quite cluttered on one sheet, even if you changed the paper size, so we're going to organise things a bit better.

Using Pages to organise the tables

At the bottom of the diagram it will have a page name of "Page-1" (like worksheet names in Excel). - Rename this by double clicking it to Notes Right click that page name and click Insert Page. Call this one Subscriptions Go back to the notes page, select the Subscription table and press the delete key. When it asks if you want to Remove selected item from underlying model? select NO. We've only removed the table from that sheet, it should still be in the Table and Views pane to the left. Change back to the Subscriptions page, and drag the Member table and Subscription table (both in the Tables an Views pane) onto the blank sheet. This, in my opinion, is one of the best bits about visio - you can have multiple copies of one table visible on as many sheets as you want. If at a later date you decided to add another section, say Meetings to record what meetings the members had attended, you could create a new page or two, drag the member table onto it, and model it without the clutter of the notes and subscriptions related tables.

Annotating etc...

You can now add more visible notes by selecting different shape (File > Shapes > Visio Extras > Callouts for example) and attaching a callout to a table. It's very useful for reminding yourself 3 months down the line what that table was for. When you've finished adding various documentation, it's time to create your database.

Creating your database on the server

Visio makes use of ODBC driver connections to connect to your database. I find it useful to create the database in Enterprise Manager (or Management Studio) first, and set up a DSN in the ODBC settings (found in control panel). Once you have an empty database with an ODBC connection do the following: On the menu, click Database > Generate. Tick Generate new database and untick Generate a text file... . Click Next. Click Database already exists and click Next. Select your database from the list and click Next - depending upon your authenticathion method, you may need to authenticate yourself to the database. A summary of tasks that will be performed will now be shown - in this case, it should be creating 3 tables. Click Next and Finish.

Keeping in sync

You can update your model based upon the live database. Switch to Enterprise Manager (or Management Studio) and add the column dateJoined: smallDateTime to the member table. Switch back to visio, and change the amountDue column of the Subscription table to amountPaid. On the menu, select Database > Update. Tick Update the database and click Next. Select your database and authenticate if necessary. Next you will see a summary of changes detected in the live database. For each item in the list (or selecting the root), select the resolution you would like to choose - in this case, we want to bring the changes into the model, so select the Refresh Model radio button. Click next a couple more times, and it will show a summary of changes that have been made to the model - these changes will sent back to the database. Click Finish. Now your Member table in the model should have a column called dateJoined and in the live database the amountDue column in the Subscription table should now be called amountPaid (you may need to refresh).

Tips and Tricks (and Quirks)

Visio has a number of oddities. Stored Procedures: Click Database > View > Code will open a new tab in the Tables and Views pane called Code. This shows any stored procedures and triggers that have been bought in from the database. Unfortunately, the Update command (detailed above) doesn't pull in stored procedures that were created in the database, so you need to use the Database > Reverse Engineer menu option. The Update command does, however, update stored procedures that have been previously Reverse Engineered, or created within the model. The reverse engineer command is much like the Update option except that it doesn't send model changes to the database. Deselect the Tables and Views, and select all Stored Procedures (it will update or add new or updated ones, and ignore unchanged ones). Any stored procedures will now appear in the Code pane. No, you can't drag them onto the diagram (annoyingly), but you can edit them by double clicking them. Creation Order: The tables and views by default are sorted alphabetically. You may occasionally receive an error about not being able to create a foreign key table because another table doesn't yet exist. Right click the tables in Tables and Views remove the tick in Sort. Then drag the tables into the correct order based upon dependancies (usually just drag the one mentioned in the error so that it's above the one that was being created). Update command - Multiple Roots: The update command asks whether you want to Refresh the model or update the database, or do nothing. Refreshing the model copies the database changes into the model. Updating the database sends the changes in the model to the database. The screen that asks you what you want to do may show a long list of changes, and the treeview actually has 3 roots. An obvious mistake that I made was to select the first line (the root of the tree view) and change all sub items to update the database. When I looked at the database, only the tables had changed, the views and stored procs hadn't been updated. This was becuase I should have paged down a bit and set the Views to update the database, and then do the same for stored procs.

Using it in practice

To get a complete database creation script, you need to start with an empty database, otherwise the database script generated by Visio will only show the changes found during the update. To achieve this I delete and recreate the database every now and then so that I get an updated create script. I then attach that script to a database project in a visual studio solution, along with a load of other scripts. One of those scripts deletes the database and creates it so that it is empty. I then have the DDL script generated by Visio also as part of that database project, so I can delete the database, and rebuild it based upon the model. I then have other scripts to populate it with test data etc... The benefit of doing it this way means I can run an msbuild script that will create the database and tables, views, stored procs, populate it with my test data, and then run my nunit tests, all from the Visual Studio command line. I can go an get a coffee while it runs. :) If there's interest, I will write an article detailing the msbuild part.

History

Created - 3/Jan/2007. [tags]visio, msbuild, sql server, database[/tags]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Vista Application Crash Recovery in C#

by ChrisB May 18, 2007 12:05
This article was first published at CodeProject.com^.

Introduction

Using the new Vista API, your application can now attempt to recover from a crash. Download:

Background

A new feature available in Vista is the ability to have a callback when your application crashes. This can allow you to attempt to persist your applications data before it is terminated. Upon restart, you can then reload that persisted data, thus giving your user a better experience (of course, it shouldn't crash in the first place, but we're being realistic, right!).

Using the code

I've created a class called ApplicationRecovery. You can use this in your own applications to be notified when there is a crash and attempt to persist the data. The main areas you should make note of: The Main() function in Program.cs needs modifying
static void Main(){

//Turn off global exception handling.

Application.SetUnhandledExceptionMode(

UnhandledExceptionMode.ThrowException);

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

using (Form1 form = new Form1())

{

//Add the event handler

ApplicationRecovery.OnApplicationCrash +=

new ApplicationRecovery.ApplicationCrashHandler(

form.ApplicationRecovery_OnApplicationCrash);

//Let Windows Vista know that your 

//application wants notification when it crashes.

ApplicationRecovery.RegisterForRestart();

Application.Run(form);

}

}
In the Form1() constructor (or another appropriate place) you need to check if there is recovery data that the application should attempt to load.
public Form1(){

InitializeComponent();  
//Check to see if the recovery file exists.  

//If it does, attempt to recover the data.

if (System.IO.File.Exists(Application.UserAppDataPath +

@"\" + RECOVERY_FILENAME))

{

if (RecoverData())

{

//Change the form title

this.Text += "- Recovered";

}

else

{

//Change the form title

this.Text += "- Could not recover";

}

}

tmrCrashCountdown.Start();

}
In the sample application there is a timer tmrCrashCountdown which prevents the user from crashing the application before 60 seconds. The application needs to be running for at least 60 seconds before windows will attempt to recover and restart. This is so that you don't get an application continually crashing and restarting. Finally, you need to implement the handler for the ApplicationRecovery.OnApplicationCrash event and the RecoverData() method. This is referenced in the Main() function.
public void ApplicationRecovery_OnApplicationCrash()

{

  try

  {

    //Save the data to recover to a text file.  

    //You may use any method you deem fit.

    System.IO.File.WriteAllText(Application.UserAppDataPath +

        @"\" + RECOVERY_FILENAME, DataToRecover);    
        //Let the application recovery know that you
        //finished successfully.

    ApplicationRecovery.ApplicationRecoveryFinished(true);

  }

  catch

  {

    //Or let it know that recovery failed.

    ApplicationRecovery.ApplicationRecoveryFinished(false);

  }

}

private bool RecoverData()

{

  bool result;

try

  {

    txtData.Text = System.IO.File.ReadAllText(

        Application.UserAppDataPath + @"

" + RECOVERY_FILENAME);

    System.IO.File.Delete(Application.UserAppDataPath +

        @"\" + RECOVERY_FILENAME);

    result = true;

  }

  catch

  {

    result = false;

  }  return result;

}
Our application saves the data to a text file, and reloads it on restart. You can implement any method you prefer to persist your data.

A quick look at the ApplicationRecovery class

The ApplicationRecovery class imports the following 4 functions from the new Vista API:
RegisterApplicationRestart

RegisterApplicationRecoveryCallback

ApplicationRecoveryInProgress

ApplicationRecoveryFinished
RegisterApplicationRestart notifies windows that we would like the application to be automatically restarted in the event of a crash. The RegisterApplicationRecoveryCallback function is the one which is called by Vista when it notifies your application that it is going to be shutdown. The callback function itself calls our function HandleApplicationCrash which rasises our OnApplicationCrash event. If the user clicks cancel whilst waiting for us to recover, we get notified by the output parameter of ApplicationRecoveryInProgress (which we check every second thanks to a timer in our callback function). When we have finished, we let windows know by using the ApplicationRecoveryFinished passing either true of false (depending upon our success at recovery).

Points of Interest

The method for debugging the recovery code is worth noting. 1. Remember to run the application outside of the visual studio debugger (Start Without Debugging). 2. When it crashes, and before you click on either the "Send To Microsoft" or "Cancel" button in the Error Reporting dialog you should use Debug > Attach To Process and attach to your process. Your code will now jump into callback function (HandleApplicationCrash).

History

4th March 07 - Modified ResgtartFlags enum definitions in source code to match updated MSDN documentation. [tags]vista, msdn, api, [/tags]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C# to HTML formatting

by ChrisB May 18, 2007 12:05
I've been adding some of my codeproject articles to my blog, and decided that the code snippets needed tidying up. As such, I've found this rather excellent code formatter at http://www.manoli.net/csharpformat/ I've made extensive use of it in my article on Vista Crash Recovery. I've also made the decision to blog more, mainly to improve my writing style. I'm aiming for a post a day! [tags]blogging, html, c#[/tags]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Articles

by ChrisB May 18, 2007 11:05
I have written a couple of articles which I have published and have been well received at the CodeProject.com^. I have reproduced theme here for completeness.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET UI unit testing - WebAii & Vista

by ChrisB May 14, 2007 16:05
Today I've been looking for ideas for unit testing asp.net sites (specifically the UI rather than the class libraries, which I do with NUnit). I've looked at Selenium, which looks ok, and had some recommendations on CodeProject.com, but at the moment i've settled on WebAii from http://www.artoftest.com. The only problem is that it's in beta, and the site says it needs XP (I'm using vista). The msi install failed with an error message. Anyway, I managed to install it on Vista by running the MSI from the Visual Studio Command Prompt, which itself was launched using R/click and "Run As Administrator" - I've tried the tutorial and it runs the NUnit sample tests ok. I'll let you know in future posts how it works, as my intention is to integrate it with my CruiseControl.net server. [tags]asp.net, webaii, vista, visual studio[/tags]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

About the author

Chris Buckett develops .net applications in C# and VB.Net, and is being persuaded to start developing for Java.

Tag cloud

Page List