UnitDriven for Windows Phone 7

I have extended UnitDriven to provide support for (the current beta release of) Windows Phone 7. This means you can write a unit test that runs on .NET, Silverlight and Windows Phone. This is an Alpha release for now, hopefully if we get a few people to use it I can make a more stable release when the final version of the  WindowsPhone7 SDK is released.

Download: http://unitdriven.codeplex.com/releases/view/50214

Here is a screenshot of UnitDriven running tests on the WindowsPhone7 emulator.

UnitDrivenPhone

One interesting thing is that all I had to do to support this was link files from the Silverlight version of UnitDriven into a new Phone project. It all compiled and ran on the first try.

However, even though it ran it wasn’t actually usable. I had to create new versions of the Views to accomodate the smaller screen size and default layout differences (buttons are relatively bigger for example). Also the scroll bars are only visible while scrolling and you have to click and drag on a Circle or the text to actually do the scrolling.

Please feel free to comment on the UnitDriven forums if you have any comments or questions!

UnitDriven v0.0.5 Available

http://unitdriven.codeplex.com/releases/view/46068

I applied some updates to UnitDriven and released a new version recently. The updates provide some nicer nesting of namespaces in the test runner UI as well as improved disabling of ‘Run’ buttons and correctly functioning Timeouts.

Also the update is paired with updates to StatLight so you can run your Silverlight unit tests in a purely automated fashion.

Also, if you find yourself trying to remember why you would want to use UnitDriven instead of one of the other unit test frameworks for Silverlight, here are the main features.

  • First class support for asynchronous tests.
  • Supports the ability to author identical tests for Silverlight and .NET (file linking).
  • Parallels either MSTest or NUnit seamlessly.

DSLs in Boo – Tech Review

The book DSLs in Boo: Domain-Specific Languages in .NET written by Oren Eini writing as Ayende Rahien has finally shipped. The final version is available online at Manning Press and I highly recommend it.

I was one of the technical reviewers so I have already read this book and I can tell you first hand it’s definitely one for your book shelf. The first few chapters describe the generalities of DSLs and Boo then the subsequent chapters describe all of the details you might need to know to implement an internal DSL in your application.

If you’ve been wondering about the whole DSL thing, this book would be a good gateway to the world. It’ll stretch your brain and certainly expose you to some new ideas. In addition the author makes a good case for some practical business applications and introduces a new addition to the open source scene: Rhino DSL.

I also got an honorable mention in the acknowledgments section of the book and a special quote on the Manning Press web site that’s pretty cool! Check out it out!

NUnit for .NET 4.0

I recently upgraded one of my projects to .NET 4.0 only to find that NUnit would no longer run my tests. Rather than waiting for the next version of NUnit to come with a .NET 4 build I decided to download the source code and build it myself. I’m including a zipfile with the required solution and project files to build NUnit yourself.

This should tide you over until the official build is released.

http://cid-dfcd2d88d3fe101c.skydrive.live.com/embedrowdetail.aspx/blog/justnbusiness/vs2010.zip

Build Steps

  1. Download the latest source code of NUnit
  2. Place the unzipped contents of this folder at $(NUnit)\solutions\
  3. Open nunit.sln and build
    1. You will get some build errors on one of the assemblies but most of the core assemblies will work fine.
  4. Copy the newly built assemblies into your applications lib folder.

NBusiness v2.0.1 Released

This release fixes a few issues that were reported to me related to sibling relationships, the schema updater and the schema updater menu items. Let me know if you still have problems with the menu items because I can’t seem to duplicate the issue on my development machine or test VPC. I have done a few things that I think might help but it’s really hard to say 100%.
Anyway, with the sibling relationships I realized that there was no guarantee as to the order of the relationships. Meaning if you had Person and Address entities, in order to create the intermediate tables in the sql scripts template, the template would either name it PeopleAddresses or AddressesPeople… depending on the order of the entities. With no guarantee as to the order there was no guarantee what the table would be named. This would cause custom scripts to blow up or running the schema updater on a database with a table of the other name would result in the database not being rebuilt properly either. So now the template will order all of the entities alphabetically before attempting to create sibling related scripts, which will guarantee that all of the tables will be predictably named. In the example above you should alwasy get AddressesPeople from now on.

Hosted Website Installations

 
After working with a hosted website for a little while it’s easy to come to the conclusion that deployment can be a real pain in the neck. Large 3rd party web hosts such as Go Daddy (which is who hosts this site currently) certainly do not give you an easy way to migrate certain changes to your website. If your website is simple HTML and you’re doing some minor incremental changes from time to time then it’s not really a big deal but when it comes to a dynamic, datadrive website site, even one as simple as this one, deployment is painful.
 
The problem comes from not having direct access to the database. The database is securely hidden behind a firewall but as annoying as this is you wouldn’t really want it any other way. VPN access would be nice but it’s understandable why this isn’t available. As a solution they typically give you access to some web front end to your database and while this is better than nothing, frankly, these applications usually suck. I’ve found that not only are they usually pretty slow and visually confusing but they are typically not compatible with the same transactional scripts that you would run in your own development environment.
 
[Example of GoDaddy’s Web DB Frontend]
 
So this is the cruxt of the problem. The first time I went to deploy my site I had a rather long script full of table creates and primary keys and foreign keys and lengthy stored procedures only to attempt to run it in this web front end and have it fail miserably. I then removed the GO statements from my srcript, since it didn’t seem to like them, and I ended up with a spattering of tables and sprocs and had to go through and manually delete a lot of things. It was very painful and tiresome.
 
So after doing this about once you quickly realize there must be a better solution. The sample code posted with this blog is an example of how to make a reusable hosted website installation package. It’s pretty simple but that’s usually the best way to do things. You’ll probably want to refactor the code in this example to fit in with your project but here is the basic idea behind everything.
 
First off, you have your installer classes. You have an abstract InstallVersion class which is essentially a collection of InstallActions along with some version information. You will create one of these classes for each version you roll out to your server. It’s probably a good idea (and not much work) to keep all of your scripts and install version classes along the way rather than just upgrading the same one over and over. The reason for this is just in case you need to rebuild a database due to a migration, a crash or perhaps a new deployment without any of the old data. In those cases you may be stuck with nothing but ALTER TABLEs at the end and you’ll need to install everything from step 1 to 100 to get back to where you want to be.
 
Your first script will have mostly CREATE statments (probably from the complete.sql generated by NBusiness) but each subsequent one will have ALTERS as well as other things needed to massage your data into the new formats.
 
There are a couple of already made InstallActions created for running sql scripts but you can imagine all sorts of other actions such as ones that delete files, create/edit/delete Users and Roles if you’re using ASP.NET Role/Membership providers. You could also imagine some actions that might do something like send an email to make sure you have your sites SMTP configurations setup correctly.
 
To configure your installer simply add a custom install configuration section to your web.config. Check out the sample to see how to do this. Then you create a page in a secure directory (accessible only by admins) and add the Installer control to that page. The installer control will look at your configuration settings and load your install classes and ask them if they have been installed or not. If they have not then buttons will be created for that version, ready for you to execute the install actions. We’re using NBusiness here to keep track of installed versions but you could just as easily come up with a scheme for saving files or something. Just remember that you don’t always have write permissions in medium trust like you do in your full trust development environement so always be sure to add the <trust level=”Medium” /> to your web.config so you can have a development environment with the same restrictions!
 
This is just one way to accomplish these goals. I’ve tried to add some semblance of a pattern and reuse to this problem and while this isn’t perfect (notably a lack of transactions across InstallActions) it’s MUCH better than nothing while still remaining pretty simple.
 
Enjoy!