Brian Orrell's Blog
My Links
Blog Stats
  • Posts - 30
  • Stories - 0
  • Comments - 13
  • Trackbacks - 4
Archives
Post Categories
Image Galleries
Blogroll

Friday, October 26, 2007

For those who came to our talk on Microsoft's Language Integrated Query, here are links to the code and deck.

LINQ PowerPoint Deck

Code and SQL

posted @ 2:00 AM

Monday, July 02, 2007

I was trying to use FxCop 3.5 to make up for some of the missing features in the current version of Team System Code Analysis.  Specifically, the spell checker.

I ran FxCop on my (fairly) clean development machine running Vista, Office 2007 and Visual Studio 2005 Team Suite SP1.

Everything ran, but it found no spelling errors even when I purposely put them in to confirm that spelling was being checked.

The solution? Install Office 2003 Proofing Tools - available on MSDN Subscriber Downloads.  Evidently the API changed significantly between 2003 and 2007.  The next version of FxCop will ship with its own non-Office-dependent spell checker and this fix won't be required.

posted @ 3:24 PM

Sunday, May 20, 2007

Say you have a page like this:

<asp:TextBox ID="NameTextBox" runat="Server" /><asp:Button ID="SubmitButton" Text="Submit" runat="server" OnClick="SubmitButton_Click" />
<asp:Label ID="MessageLabel" runat="server" />

With the following code behind.

using System;

namespace AspUnitTest

{

    public partial class _Default : System.Web.UI.Page

    {

        protected void SubmitButton_Click(object sender, EventArgs e)

        {

            MessageLabel.Text = string.Format("Hello, {0}", NameTextBox.Text);

        }

    }

}

Create a unit test with the following code to test it.

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Microsoft.VisualStudio.TestTools.UnitTesting.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System;

 

namespace AspUnitTest.Test

{

    ///

    /// Summary description for DefaultAspxTest

    ///

    [TestClass]

    public class DefaultAspxTest

    {

        private TestContext testContextInstance;

 

        public TestContext TestContext

        {

            get { return testContextInstance; }

            set { testContextInstance = value; }

        }

 

 

        [TestMethod()]

        [HostType("ASP.NET")]

        [UrlToTest("http://localhost:50551/default.aspx")]

        [AspNetDevelopmentServerHost("C:\\Users\\brian.orrell.PARIVEDA\\Documents\\Source\\Samples\\AspUnitTest\\AspUnitTest")]

        public void TestNameEntry()

        {

            Page page = testContextInstance.RequestedPage;          //1

 

            TextBox NameTextBox = (TextBox)page.FindControl("NameTextBox");

            Assert.IsNotNull(NameTextBox);

            Button SubmitButton = (Button)page.FindControl("SubmitButton");    //2

            Assert.IsNotNull(SubmitButton);

            Label MessageLabel = (Label)page.FindControl("MessageLabel");

            Assert.IsNotNull(MessageLabel);

 

            PrivateObject po = new PrivateObject(page);            //3

            string name = "Brian Orrell";

            NameTextBox.Text = name;

            po.Invoke("SubmitButton_Click", SubmitButton, EventArgs.Empty);

            Assert.AreEqual(string.Format("Hello, {0}", name), MessageLabel.Text);

 

        }

    }

}

Pretty easy.

posted @ 8:38 PM

Saturday, May 19, 2007

At Pariveda, we typically use a standard Config project in Visual Studio to keep track of all our configuration files and accessor classes.  We then write MSBuild scripts to deploy them to the appropriate web, service, winform, wpf, wcf directories as appropriate.  This provides the ability to maintain a single set of config files even if they are being deployed to multiple application source environments.

This is especially appropriate with testing frameworks such as nUnit and Team Test.  In order to test effectively, many files need to be copied to the running test directory as well as the main application directory.  Instead of having to write duplicate msbuild tasks for copying to these directories, it would be nice if we could iterate through a list of directories that the files needed to be copied to.

You see this question being asked all the time: How do I recursively copy a series of files to another folder?  That question has been answered multiple times on multiple sites. But what about needing to copy that same series of files to multiple different deployment folders?  The scenario is like the one I described above or if you were wanting to automate deployment of files to a web farm.  The answer is using the ItemGroup appropriately.  If you can create an ItemGroup that contains the list of deployment directories that need to receive the files, you can write the script once that will iterate over this list of deployment directories and copy them to all of them.

MSBuild is certainly not as intuitive to me as NAnt.  NAnt seems to be more understandable proceduraly (foreach tasks, etc) while MSBuild is more geared towards XSL type transformations.  Once I got the hang of how to use ItemGroups, however, I can see how powerful MSBuild as a scripting language can be.

<Project DefaultTargets="CopyConfig" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!-- Define the list of directories to be copied to -->

    <PropertyGroup>

        <ConfigFolder>c:\msbuild\config</ConfigFolder>

       </PropertyGroup>

 

    <!-- Setup the directories to deploy to -->

    <ItemGroup>

        <ConfigDeploy Include="Service">

            <Path>c:\msbuild\Service</Path>

        </ConfigDeploy>

        <ConfigDeploy Include="Test">

            <Path>c:\msbuild\Test</Path>

        </ConfigDeploy>

    </ItemGroup>

 

    <!-- Now the task that copies the config files-->

    <Target Name="CopyConfig" Condition="'@(ConfigDeploy)'!=''">

 

        <!-- Delete any pre-existing deployment folders (Optional but good for testing) -->

        <RemoveDir Directories="%(ConfigDeploy.Path)" />

 

        <!-- Get all Files within the config directory and create multiple sets of the files

            with metadata that describes where the files are to be deployed to -->

        <CreateItem Include="$(ConfigFolder)\**\*.*"

            AdditionalMetadata="ToDir=%(ConfigDeploy.Path)">

            <Output TaskParameter="Include" ItemName="ConfigFilesToDeploy" />

        </CreateItem>

 

        <!-- Now copy all of the files to the appropriate folders -->

        <Copy SourceFiles="@(ConfigFilesToDeploy)"

            DestinationFolder="%(ToDir)\%(RecursiveDir)" />

    </Target>

</Project>

posted @ 12:43 PM

Monday, April 09, 2007

Better late than never. Here are the links to our AJAX Presentation we presented at the January Dev Cares event.

Session 1

Session 2

 

posted @ 5:32 PM
Brian Orrell