Geoffroy’s Weblog

November 29, 2007

ASP.NET AJAX (UpdatePanel)

Filed under: AJAX, VSTS 2008 — gseive @ 8:10 pm

I had done some reading on ASP.NET AJAX throughout the year but hadn’t had a chance to apply it. On my current project a perfect opportunity presented itself. On one page there is a list of folders the user can choose from. When a folder is selected it displays a list of photos. Each time a different folder is selected this causes a postback and the entire page is refreshed causing that annoying flickering (like on MSDN when browsing methods and properties of a class…). Since the site is designed with a master page and following the advice in “ASP.NET in Action” I added the ScriptManager to the master page and wrapped the controls with an UpdatePanel. And Voilà! Wow effect guaranteed! I knew what to expect, but it was still amazing to watch. Très cool!

When using VSTS 2008 the Web.config file includes all the needed configuration settings. Enhancing an existing ASP.NET 2.0 application requires adding the new settings, detailed in the section Configuring ASP.NET AJAX on ASP.NET – AJAX.

Of course, there is more to ASP.NET AJAX than UpdatePanel, and on that to-do list I have the web method / page method approach to investigate.

Some of the articles I read on the topic (in MSDN Magazine):

There’s always something to learn from Jeff Prosise and Dino Esposito!

Unit testing with VSTS 2008 (Orcas Beta 2) – Continued

Filed under: Unit Testing, VSTS 2008 — gseive @ 5:27 pm

So, after experimenting with the on-line tutorial I went ahead and added some tests to my project. I had already done some refactoring as my page was getting bloated. I had created a separate class with public methods exposing the required services and had put it in the App_Code folder (in a subfolder to keep things neat and tidy). But since I couldn’t get the asp.net unit test approach to work, I decided to take another step and created a separate project. Sooner or later this would have been needed since the functionality deals with file manipulation and is generic enough that it can live on its own! I ended up with a new project, a new namespace and a new class. Much cleaner! From there it was easy to generate the test project (right click on the class name and select “Create Unit Tests…”). The testing framework is nicely integrated with VSTS, even though it feels “heavier” than NUnit at first. I used the templates generated to create the test methods I needed, tested them individually (right click on the method name and select “Run tests”) and then as a batch (“Test” / “Run” / “All Tests in Solution” or Ctrl+R, A).

Now it’s just a matter of doing more of it to develop those VSTS unit testing muscles! On the testing side, a couple things I’ve added to my to-do list is to look into Code Coverage (http://msdn2.microsoft.com/en-us/library/ms182534(VS.90).aspx) and Data-Driven Unit Tests (http://msdn2.microsoft.com/en-us/library/ms182519(VS.90).aspx).

November 25, 2007

Unit testing with VSTS 2008 (Orcas Beta 2)

Filed under: Unit Testing, VSTS 2008 — gseive @ 11:32 pm

I was looking for a tutorial on how to do unit testing with VSTS 2008. Since I am developing an ASP.NET application I first found and read the topic “How to: Create an ASP.NET Unit Test” at http://msdn2.microsoft.com/en-us/library/ms182526(VS.90).aspx, but I couldn’t get it to work! After some more searching I found something else that looked promising, “Walkthrough: Creating and Running Unit Tests”, on MSDN again at http://msdn2.microsoft.com/en-us/library/ms182532(VS.90).aspx.

The sections on testing the public methods went well (light discrepancies between the text in the article and the code provided in the zip file though, TeamTest Samples.zip). Things started breaking down with the section on testing private methods.

The text in the article looks like this:

Within the GetAccountTypeTest() method, find the three assignment statements that are marked with // TODO: comments. Change them to read as follows:

string customerName = "Mr. Bryan Walton";
double balance = 7.00;
TestProject1.BankAccountNS_BankAccount_accountTypeAccessor val = TestProject1.BankAccountNS_BankAccount_accountTypeAccessor.Gold;

Run the GetAccountTypeTest test.
In the Result column in the Test Results window, the final test status appears as Passed. This is the expected result because with the account balance set to 7.00, the accountType should be Gold.

Now the test code generated from the code in the zip file looks like this:

        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void GetAccountTypeTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            BankAccount_Accessor target = new BankAccount_Accessor(param0); // TODO: Initialize to an appropriate value
            BankAccount_Accessor.accountType actual;
            actual = target.GetAccountType;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

Final test code for private GetAccountType()

Updating the code wasn’t obvious. But after some trial and error I got the test method to work with the following code:

        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void GetAccountTypeTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value - Actually not used
            string customerName = "Mr. Bryan Walton";
            double balance = 7.00;
            BankAccount_Accessor target = new BankAccount_Accessor(customerName, balance); // Now initialized to an appropriate value!
            BankAccount_Accessor.accountType actual;
            actual = target.GetAccountType;
            //Assert.Inconclusive("Verify the correctness of this test method.");
            Assert.AreEqual(BankAccount_Accessor.accountType.Gold, actual); // Expecting Gold, are we getting Gold?
        }

I haven’t used the PrivateObject type and haven’t looked into what those are yet.

Next step is to apply my new discoveries to my project and see if it works there!

Hello world!

Filed under: Uncategorized — gseive @ 7:41 am

Welcome to my blog on WordPress.com. This is my first post. I’ll be blogging on technical topics as I explore various aspects of software development, either on projects for clients or on personal projects.

Create a free website or blog at WordPress.com.