I have a com+ component that I have been involved with for years. It lacks tests but I wrote functional tests at the interface level which surprisingly has fairly good coverage of the code.

The issue with this is that the component HAS to impersonate an identity for the tests to work properly. So I have a pre/post build condition that installs / uninstall's it from the gac/com+ catalog. My only manual intervention was to set the identity (every freaking time I wanted to run my tests).

To help with this issue I installed autohotkey which is a great keyboard & mouse record and replay tool (and its free). I then recorded a script to set the identity of the component. This works fairly well but will break when something changes on the com+ snap in screen (things are not where it expects it). Or if the CPU is taxed things might try to be clicked while a screen is still loading.

Searching the web I could not find a way to programmatically configure the identity of the app but finally found this little gem; Com+ Admin.

I created a new app and added a reference to the comAdmin type library

The code to create an application is relatively simple:

catalog = New COMAdmin.COMAdminCatalog

applications = catalog.GetCollection("Applications")

applications.Populate()

Dim application As COMAdmin.COMAdminCatalogObject

application = applications.Add()

application.Value("IsEnabled") = True 'there are about 30-40 different properties for here

application.Value("Identity") = "DOMAIN\User.Name"

application.Password="MyPasswordHere"

applications.SaveChanges()

catalog.InstallComponent(application.value("ID"), "c:\build\mycomapp.dll, "", "") 'add assemblies to the component

Pretty freakin easy! What I hate is that you have to remember the strings and proper types for the Value collection. What I did was create a wrapper around the application object that exposes all the properties in an easy fashion

i.e.

Public Class ComApplicationWrapper

Private application As COMAdmin.COMAdminCatalogObject

Public Sub New(ByVal application As COMAdmin.COMAdminCatalogObject)

Me.application = application

End Sub

Private Property Config(ByVal key As String) As Object

Get

Return application.Value(key)

End Get

Set(ByVal Value As Object)

application.Value(key) = Value

End Set

End Property

Public Property _3GigSupportEnabled() As Boolean

Get

Return Config("3GigSupportEnabled")

End Get

Set(ByVal Value As Boolean)

Config("3GigSupportEnabled") = Value

End Set

End Property

Public Property AccessChecksLevel() As COMAdmin.COMAdminAccessChecksLevelOptions

Get

Return Config("AccessChecksLevel")

End Get

Set(ByVal Value As COMAdmin.COMAdminAccessChecksLevelOptions)

Config("AccessChecksLevel") = Value

End Set

End Property

...

Now at least my com+ application can be easily installed so my tests will run. Next step is to create more granular unit tests that can be run in isolation instead of having to be run as an identity.

 You can download the beta code here of my com installer app.