coffee-cup explorations of bacardi bryant RSS 2.0
 Friday, May 16, 2008

If someone had mentioned a week ago today that I would be a "PROUD" owner of a MacBook Pro, I would probably reply, "shist, yeah right". Well as I type these words today, I would have to eat those. Yesterday I took the plunge and purchased MacBook Pro and I have to admit that I am impressed by far with the system.

If you read an earlier post "Overheating Laptop!" then you are familiar with the computing woes that plagued me over the past couple of weeks and thus left me shopping for a new primary laptop.

After a week of comparison shopping and some coaxing by some friends (?)…I was convinced that I should give Mac a try. I am yet to be disappointed.

Features that totally rock:

Boot Camp:    Wouldn’t be able to survive without it. The hidden utility that is bundled in the OS, makes partitioning the hard drive and installing Windows Vista seamless.  It even sets Vista as your "DEFAULT" operating system so that when you power on, you’re in Windows Vista.  How's that for humility?

    

Parallels:   So booting directly into Vista is nice, but why buy a Mac to boot into Vista. Yes, I need Vista for development, but I bought a MacBook to boot into Mac OS X.

By downloading and installing Parallels, I was ready to go in about 30 mins. Parallels is a virtual desktop application that allows you to run a virtual computer while using your current computer. It's awesome because it detected the boot camp drive and connected to it as a virtual system so that I didn't have to install another copy of the OS. Presto, I am in business!


 


Bluetooth Mouse:    Love the programable buttons, love the touch > click memory (touch right side with one finger = right click).




Time Machine:   Very cool backup tool. In essence takes a snapshot of your system at a given point in time. Essentially System Restore on the Mac except with a cool ass interface.



iChat, Built-In WebCam, and Microphone:   Amazing!



Bluetooth Hardware and Software installed: Awesome!



DVD Authoring Software!



Imagine…drag and drop a pic directly from a web page to your desktop, library, or document with no right-clicking.

To add to that, installing applications without stopping what you are doing and without restarting…nice!

Well you get the point. So I am finding computing fun again...wicked.


Friday, May 16, 2008 6:27:10 PM UTC  #    Comments [0] - Trackback
General
 Thursday, May 15, 2008

Kevin Brammer has a post hightlighting how you can apply Vista's Aero theme to your ASP.NET GridView controls. The graphically challenged person that I am, I thought the post to be good stuff.

 

Thursday, May 15, 2008 3:38:37 PM UTC  #    Comments [0] - Trackback
ASP.NET
 Wednesday, May 14, 2008

ClickOnce is a great new feature in Windows application development that provides a simple application deployment and update model. While it isn’t the most comprehensive and robust solution, I find that it works for deploying and updating small scaled applications. However, I did find one issue that could easily be overlooked and cause your updates to fail.

In toying around with one of my applications, I began to receive the “DeploymentDownloadException” exception. Upon reading further into the details, I found that my IIS Server was returning the HTTP Error Code: 404 (file not found).

So I opened the project’s properties page to confirm the upload and deployment locations; they were fine. Then I launched FileZilla (ftp client), to view the directories and found that the Publish from VisualStudio had run successfully because the files had been uploaded.

Puzzled, I went back to the error dialog, and read the detailed error message again. I discovered that the .application file was not found and couldn’t begin to understand why it wasn’t uploaded.

Because the updates for this particular application had worked fine before, I knew that it must be something involving my last actions. So, what was my approach to solving this issue you ask?

Well, to use the highly effective and scientifically mystical “think back or re-trace your steps” method of course.

The problem…

By default, the Publish Wizard in VisualStudio saves ClickOnce applications with the .application extension appended. However, the Publish feature in the Properties dialog allows you to save the application files with a .deploy extension. Well if you publish your application using the Properties dialog with the “use .deploy extension” option checked, and then publish a later revision using the Publish Wizard, then on attempting to update the application, the server will return an HTTP 404 error. This is because your original dll has the .deploy extension appended to it and not the .applicatIon extension that the Publish Wizard added.

The solution…this is really tricky, so pay close attention:

Don’t combine the publishing methods.  If you use the Publish Wizard to start, always use it; if you use the Properties form with the “use .deploy extension” selected, then always use the properties form.

Oh, and to fix and existing issue, simply published again using the original method and the application will be back on track.

Happy ClickOnce’ing!

Wednesday, May 14, 2008 5:23:12 PM UTC  #    Comments [0] - Trackback
C# | ClickOnce | Visual Studio
 Sunday, May 11, 2008

The previous post in this series covered downloading and installing the NUnit testing library for .NET. In this post we will:

·         Create a new class library project

·         Create a new unit testing project

·         Create a new test

·         Build the solution

·         Pass the test

 

So let’s get started.

Launch Microsoft Visual Studio and create a new “Class Library” project and name it “BookStore”.

Delete the existing Class1.cs file.

Right-Click on the Solution in the Solution Explorer and SelectAdd > New Project”.

Select a “Class Library” project and name it “BookStoreTests”.

Once again, delete the existing Class1.cs file.

Now that the environment is ready,

Right-Click on the References item under the BookStoreTests project tree and SelectAdd Reference”

Since we will be testing the BookStore project, we will need to add a reference to it.

Select the Projects tab and then Select the BookStore project from the list and Click OK.

Now there is one more reference to add; the reference to the NUnit Framework library.

Right-Click on References again and SelectAdd Reference”.

This time Select the .NET tab and scroll down to the nunit.framework assembly, Select It, and Click OK.

Now we are completely set-up and ready to begin coding.

At this point if you were able to follow along, your Solution Explorer should resemble the one below.

Now to create a test.

Right-Click on the BookStoreTests project and follow the “Add” > “New Item” menu sequence.

Select “Class” as the template and name it “BookStoreControllerTests.cs” and ClickAdd”.

The reason that we named our class as such is, one popular design pattern is to place the UI, business logic, and database features in separate layers (projects or files).

So in our design, we will implement a BookStoreController that will represent our business logic layer. The controllers job is to provide data/objects to our UI layer for display. Therefore, we want to test that our controller (business logic layer or bll) is doing just that, hence the BookStoreControllerTests.cs class.

Next we need to let the compiler know that we would like to use classes and methods provided by the nunit.framework library and the BookStore project that we referenced a moment ago.

Do this by adding using directives to the top of the BookStoreControllerTests.cs class and a special attribute to let nunit know to run the tests in the file as such:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

using NUnit.Framework;

using BookStore;

 

namespace BookStoreTests

{

    [TestFixture]

    public class BookStoreControllerTests

    {

    }

}

 

Next we need to add another nunit specific feature referred to as a setup method. A setup method is identified by the [SetUp] attribute. Set up methods allow you to prepare your objects/classes for testing, so during setup you can create instances of the actual classes that you will test and, if necessary, load data.

We will use ours to create an instance of our BookStoreController.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

using NUnit.Framework;

using BookStore;

 

namespace BookStoreTests

{

    [TestFixture]

    public class BookStoreControllerTests

    {

        //here we know that we are testing the BookStoreController

        //so we need to declare one.

        BookStoreController Controller;

 

        //during the setup for our tests we want to actually instantiate the controller;

        [SetUp]

        public void Build()

        {

            Controller = new BookStoreController();

        }

    }

}

 

And now for the actual test method itself. When using NUnit, a test method is identified by the [Test] attribute. The accepted nomenclature for test methods, while verbose, identifies the expected result. For this test, we would like for the BookStoreController to return a particular book when passed an ISBN. For the purposes of this tutorial I will use a book from my personal library, “Windows Communication Foundation Unleashed”. No big deal, we could very well have made up a book title and ISBN.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

using NUnit.Framework;

using BookStore;

 

namespace BookStoreTests

{

    //let nunit know that this is a test class. So run tests inside.

    [TestFixture]

    public class BookStoreControllerTests

    {

        //here we know that we are testing the BookStoreController

        //so we need to declare one.

        BookStoreController Controller;

 

        //Create a setup for tests that instantiate the controller

        //and add data if necessary.

        [SetUp]

        public void Build()

        {

            //create an instance of the book controller.

            Controller = new BookStoreController();

        }

 

        //Create a test method.

        [Test]

        public void ExpectedToReturnABook()

        {

            //call the get book method on the controller passing in an isbn.

            string isbn = "9780672329487";

            Book WCFUnleashed = Controller.GetBook(isbn);

           

            //test that the book return is not null.

            Assert.IsNotNull(WCFUnleashed);

        }

    }

}

Now let’s build the application. If you’re familiar with programming in .NET using VisualStudio, you’re probably thinking to yourself, this thing will not build. You're correct, and that points out our first objective. When using the TDD approach, we first write out our EXPECTATIONS, then we write the code required to meet them. Therefore when we attempt to build our project, we get the following:

This is because we don’t have any of the referenced classes defined (created). So we need to get our application to build by creating them.

Right-Click on the BookStore project and Select “Add” > “New Item” and choose “Class”.

Enter “Book.cs” as the name.

Follow the same steps and create a file named “BookStoreController.cs”.

Then Right-Click on the BookStore project and Click "Build".

Your BookStoreControllerTests project should resemble the figure below. The BookStoreController and Book classes have now been recognized as indicated by the code coloring.

Now try and build the project again by right-clicking on “Solution ‘BookStore’ (2 projects)” and clicking “Build”. Again you should receive an error. This is because, although we have created our classes, the BookStoreController.cs file does not contain a method called GetBook that accepts a string argument. So let’s fix this by adding the method below to the BookStoreController.cs file.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace BookStore

{

    public class BookStoreController

    {

        //Get a book from the store by isbn

        public Book GetBook(string isbn)

        {

            //Create a book instance and set it to a null object.

            Book RequestedBook = null;

 

            //Return the book

            return RequestedBook;

        }

    }

}

 

Since OOP principles are beyond the scope of this tutorial, we will go with some basic implementations just to get our projects to build, and our unit tests to pass.  There is one change to the class files that I should point out, and that is the use of the public keyword. The public keyword indicates that a class is accessible outside of its current assembly (dll) or project however you would like to look at it. By default, VisualStudio does not add the public keyword to newly created classes. So for each of the classes that were created, Book.cs and BookStoreController.cs,

Change:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace BookStore

{

    class BookStoreController

    {

To read:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace BookStore

{

    public class BookStoreController

    {

Now with our GetBook() method in place, lets attempt to build our project again.

Right-Click on the BookControllerTests project and select “Build”.

If you have followed along successfully, your Visual Studio Output window should display the text below, with an emphasis on the statement indicating that the build of our 2 projects succeeded.

------ Build started: Project: BookStore, Configuration: Debug Any CPU ------

BookStore -> C:\Users\Bacardi\Documents\Visual Studio 2008\Projects\BookStore\BookStore\bin\Debug\BookStore.dll

------ Build started: Project: BookStoreTests, Configuration: Debug Any CPU ------

BookStoreTests -> C:\Users\Bacardi\Documents\Visual Studio 2008\Projects\BookStore\BookStoreTests\bin\Debug\BookStoreTests.dll

========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

 

Now for the reason that we went through all of this, THE TEST!

At this point let’s launch NUnit and run the tests just as we did in the first lesson of this series.

From the NUnit application, SelectFile” > “Open Project” and navigate to the BookStore project in the Visual Studio > Projects directory. Since we are testing our BookStoreTests assembly, we will navigate to the BookStoreTests/Bin/Debug folder and select the BookStoreTests.dll file.

For a normal installation on Windows Vista, the directory path would be:

C:\Users\[username]\Documents\Visual Studio 2008\Projects\BookStore\BookStoreTests\bin\Debug

You should see your project appear in the NUnit Gui’s left panel and then click “RUN” to run the test. If you have followed along successfully you should see the following:

Just as we should have suspected, our test failed. This is because we explicitly set our book object to a null object in the BookStoreController’s GetBook() method, and then used the BookControllerTests' ExpectedToReturnABook() method to test that the book was not null.

So again in TDD, we want to specify our expectations first, then write the code that fulfills ONLY THAT expectation. There are some theories on increased efficiency and the like surrounding this, but again that is beyond the scope here. Therefore, in sticking with the program, lets get the test to pass.

In order to do so, we need for our BookStoreController to return a book object that is not null, and the code below accomplishes this. So replace the existing code in your BookStoreController.cs file with this modified code.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace BookStore

{

    public class BookStoreController

    {

        //Get a book from the store by isbn

        public Book GetBook(string isbn)

        {

            //Create a book instance.

            Book RequestedBook = new Book();

 

 

            //Set the properties for the book. For this tutorial

            //lets pretend that the controller actually pulled book details

            //from the database, xml repository, or webservice where ever.

            //One approach is to call a service that returns the requested book

            //overriding the null on created above. So that might look like:

            //

            //  try{

            //       RequestedBook = _bookService.getBook(isbn);

            //  }

            //

            //Where _bookService represents a service layer that handles calls to

            //a repository of some type, hosted somewhere.

            RequestedBook.Isbn = isbn;

            RequestedBook.Title = "Windows Communication Foundation Unleashed";

 

            //Return the book

            return RequestedBook;

        }

    }

}

 

Also, we need our Book object to actually have the properties that we are setting in our BookStoreController.cs file defined. So modify your Book.cs file to resemble the code below.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace BookStore

{

    public class Book

    {

        private string _isbn;

        private string _title;

 

        public string Isbn

        {

            get { return this._isbn; }

            set { this._isbn = value; }

        }

        public string Title

        {

            get { return this._title; }

            set { this._title = value; }

        }

    }

}

 

Build the solution again.

Go to NUnit and ClickRUN”, and as the French would say it “voila” our test has passed.

And that’s a wrap. In this very detailed part of the series we created a class library project, created a unit testing project, created a new test, wrote the code necessary to build the solution, and finally wrote the code necessary to pass the test.

As basic as it is, I hope this helps you conceptualize test driven development. Future tutorials in this series will not be as in-depth, as I would assume that the fundamentals of tests and how they work are understood. So tune back for the tutorials on the RhinoMocks and MoQ testing frameworks.

The series:

Happy Testing!

Sunday, May 11, 2008 9:28:17 PM UTC  #    Comments [0] - Trackback
TDD | NUnit
 Sunday, May 04, 2008

First word of caution, Gateway MT6821 is probably not a good buy. I purchased this laptop about a year ago and was pretty excited as it was a major upgrade from my previous Compaq system. It was well equipped for my needs with a dual core processor, 2GB RAM, and most importantly, 2MB L2 cache.

Often times overlooked, the L2 cache is a major player in overall system performance. While I won't go into the specifics, the next time you are out shopping, take some time to compare systems with varying cache capaci