Thursday, June 08, 2006

using NUnit.Mocks DynamicMock with a Property in C#

Starting to use the DynamicMock feature of NUnit.Mocks. I had a class with a property getter that I wanted to use it with.  The code consistently failed.  Grabbed the NUnit source and looked at the covering unit test for DynamicMock.  Guess what, no covering test for a Property to show me how to do it!  I started thinking about it and realized that Property getters and setters are just treated as speciallly named methods under the covers and started playing around.  Finally came up with the following that works:

    8 namespace DynamicMockTest

    9 {

   10     [TestFixture]

   11     public class Class1

   12     {

   13 

   14         [Test]

   15         public void Test1()

   16         {

   17             DynamicMock mock = new DynamicMock(typeof(IMockTest));

   18             mock.ExpectAndReturn("get_Domain", "AMSWORLD");

   19 

   20             Assert.AreEqual("AMSWORLD", ((IMockTest)mock.MockInstance).Domain);

   21         }

   22 

   23     }

   24 

   25 

   26     public interface IMockTest

   27     {

   28         string Domain { get; }

   29     }

   30 }

 

The trick is to precede the property name with get_ or set_

 

Thursday, June 08, 2006 2:17:45 PM (Pacific Standard Time, UTC-08:00)   #      Comments [3]  
 
XP VPN Error 721

Just got a new machine (T60p finally has a Windows key!) and was having some problems connecting to our corporate VPN. Searched google and kept seeing posts about routers not passing GRE.  I knew mine was as my old laptop sitting next to the new one could connect. Couldn’t figure out the issue until it dawned on me that perhaps the Windows Firewall might be blocking GRE.  My first reaction was nah…   This is outbound access by a component built into Windows XP.  The firewall isn’t going to block it.  Well I was wrong.  The trick is to go into the Firewall Advanced Settings and make sure that VPN – Encapsulating Security Payload (ESP) and VPN – General Routing Encapsulation (GRE) are enabled like this:

FireSet

Posting this partly so I remember the next time I hit this and partly because I didn’t see any mention of this in my google search results.

Thursday, June 08, 2006 8:58:46 AM (Pacific Standard Time, UTC-08:00)   #      Comments [2]  
 

  Monday, May 29, 2006

WIX

I have been building some installs with WIX over the long weekend.  Overall I love the toolkit compared to tools I have used in the past but some things are very difficult to find information on.  I have built an MSI without any UI.  i.e. not even WixUI_Minimal.  When the MSI first starts it shows:

 

I can set the title.  I can’t figure out however how to show any text static or progress based.  Any ideas?

Monday, May 29, 2006 6:45:44 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]  
 

  Tuesday, May 16, 2006

SQL Server Integration Services LoadXml fails with a message about an invalid provider

Ran into this today on my laptop. Fired up BIStudio to test some SSIS packages on my local machine.  I couldn’t even load the package due to the LoadXml error mentioned above complaining about the FLATFILE provider.  Come to find out this has to do with something, LEXMARK printer drivers and Flash 8 are suspects, mucking with the security around component categories.  I found some code that when run as a low privileged user will find the bad entries:

 

using System;
using Microsoft.Win32;

namespace CheckClsidPerm
{
    class Program
    {
        static void Main(string[] args)
        {
            RegistryKey clsid = Registry.LocalMachine.OpenSubKey(@"Software\Classes\CLSID");
            string[] clsids = clsid.GetSubKeyNames();
            Console.WriteLine("found {0} keys", clsids.Length);

            foreach (string s in clsids)
            {
                try
                {
                    using (RegistryKey clsidKey = clsid.OpenSubKey(s))
                    {
                        using (RegistryKey ic = clsidKey.OpenSubKey("Implemented Categories"))
                        {
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("error while reading key {0}: {1}", s, e.Message);
                }
            }
        }
    }
}

Run this under a low privilege account.  Then go in and find the CLSIDs in HKEY_CLASSES_ROOT and add Users with read access.  This fixed the issue for me.

Tuesday, May 16, 2006 11:43:02 AM (Pacific Standard Time, UTC-08:00)   #      Comments [1]  
 

  Monday, May 15, 2006

CodePlex is Live

Remember the good old days of GotDotNet?  Before the interminable slow downs and the littering of the various areas with samples of dubious value?

Sandy Khahund and Jim Newkirk from the Patterns and Practices group moved to MSOPS to bring back those good old days. Their first effort, CodePlex (http://www.codeplex.com), hopes to solve many of those issues.  Still in beta but looking very good.

Check it out when you get a chance.

Monday, May 15, 2006 10:29:24 AM (Pacific Standard Time, UTC-08:00)   #      Comments [2]  
 

  Tuesday, April 18, 2006

MSH Convert an Absolute Directory to a Relative Directory

Still working on the conversion.  Now I am working up a script to create solution files that will be consumed by Team Build.  Solution files however require relative references to the projects.  Come to find out there is no functionality built into .NET to do this conversion.  Since I didn't want to pick up any dependencies in my MSH script I created the function in MSH with inspiration from Paul Welter:

 

# function that takes an absolute path and turns it into a relative path
function relativePath([string]$absolutePath, [string]$relativeTo)
{
    # Add some error checking
    
    # split up the paths
    $absoluteDirectories = $absolutePath.Split("\")
    $relativeDirectories = $relativeTo.Split("\")
    
    # Get the shortest of the two paths
    [int] $length = [System.Math]::Min($absoluteDirectories.length, $relativeDirectories.length)
    
    # Use to determine where in the loop we exited
    [int] $lastCommonRoot = -1
    
    # Find common root
    for( $i = 0 ; $i -lt $length ; $i++ )
    {
        if($absoluteDirectories[$i] -ne $relativeDirectories[$i])
        {
            break
        }
        
        $lastCommonRoot = $i            
    }
    
    
    # If we didn't find a common prefix then throw
    if($lastCommonRoot -eq -1)
    {
        throw "The paths $absolutePath and $relativeTo do not have a common prefix path."
    }
    
    # build up the relative path
    [System.Collections.Specialized.StringCollection] $relativePath = new-object System.Collections.Specialized.StringCollection
    
    # add on the ..
    for( $i = $lastCommonRoot + 1 ; $i -lt $absoluteDirectories.length ; $i++ )
    {
        if($absoluteDirectories[$i].length -gt 0)
        {
            $relativePath.Add("..") > null
        }
    }
    
    # add on the folders
    for( $i = $lastCommonRoot + 1 ; $i -lt $relativeDirectories.length ; $i++ )
    {
        $relativePath.Add($relativeDirectories[$i]) > null
    }
    
    [string[]] $relativeParts = new-object String[]($relativePath.Count)
    $relativePath.CopyTo($relativeParts, 0)
    [string] $newPath = [System.String]::Join("\", $relativeParts)
    
    return $newPath
}

relativePath "C:\dir1\dir2\dir5" "C:\dir1\dir2\dir3\dir4\dir6" 
Tuesday, April 18, 2006 4:26:07 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]   MSH
 
MSH Upgrade all CSProj files in a directory

I am currently working on our .NET 1.1 to .NET 2.0 conversion project at Vertafore.  After recently listening to the Hanselminutes on Msh I figured I would give it a spin.

One of the items we needed to do was run the command line upgrade across all of our projects.  At last count we had around 400 so this was a tall order.

Turns out it was only 5 lines of MSH!

Here it is for anyone else that wants it:

$devenv = "C:\program files\Microsoft Visual Studio 8\Common7\IDE\devenv.com"

foreach ($project in get-childitem -include *.csproj -recurse) {

   write-host "Upgrading Project: " $project

   & $devenv $project /Upgrade

}

Tuesday, April 18, 2006 4:20:53 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]   MSH
 

  Tuesday, March 21, 2006

Recruiting from Guy Kawasaki

You may be noticing a theme today.  I am finding a number of good links today I am posting for posterity.

http://blog.guykawasaki.com/2006/03/the_art_of_recr.html

Tuesday, March 21, 2006 1:47:03 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]  
 
Versioning Strategies for Data http://toadbalancing.blogspot.com/2005/12/preparing-for-backwards-compatibility.html Tuesday, March 21, 2006 1:42:14 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]  
 
Negotiation

Great article on Negotiation.  I see myself unconsciously doing many of the things mentioned in the article but learned a few new tricks while reading through it.  Posted here so I don't lose it!

http://www.agilekiwi.com/negotiation.htm

Tuesday, March 21, 2006 1:40:57 PM (Pacific Standard Time, UTC-08:00)   #      Comments [0]  
 


Administration
Sign In