Friday, June 24, 2011

Database Unit Tests - Config Transforms

I wanted to have a configuration for the other environments to run the same tests.


  1. started out adding the sit configuration to the solution and the test project.
  2. I added the following to my Db.Tests.csproj:
    1. top property group under projectguid:
      1. <ProjectConfigFileName>App.Config</ProjectConfigFileName>
    2. and just below outputType:
      1. <OutputExtension Condition="'$(OutputExtension)' == '' ">dll</OutputExtension>
    3. then in the item group with app.config:
      1. <Content Include="App.Sit.config">      <DependentUpon>app.Config</DependentUpon>    </Content>
    4. finally just before /Project tag:



<Import Condition="'$(Configuration)' == 'Sit'" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
  <Target Condition="'$(Configuration)' == 'Sit'" Name="PostTransformAppConfig" AfterTargets="TransformWebConfig">
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\$(AssemblyName).$(OutputExtension).config" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\$(AssemblyName).vshost.$(OutputExtension).config" />
  </Target>
  <Target Condition="'$(Configuration)' == 'Sit'" Name="PostTransformAppConfig" AfterTargets="Build">
    <CallTarget Targets="TransformWebConfig" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\$(AssemblyName).$(OutputExtension).config" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" DestinationFiles="$(OutputPath)\$(AssemblyName).vshost.$(OutputExtension).config" />
  </Target>



Here's my app.sit.config transform file:

<ExecutionContext xdt:Transform="Replace" Provider="System.Data.SqlClient" ConnectionString="Data Source=SitServer;Initial Catalog=Init1_SIT;Integrated Security=True;Pooling=False"
        CommandTimeout="30" />
    <PrivilegedContext xdt:Transform="Replace" Provider="System.Data.SqlClient" ConnectionString="Data Source=SitServer;Initial Catalog=Init1_SIT;Integrated Security=True;Pooling=False"
          CommandTimeout="30" />



Based on

Wednesday, June 1, 2011

Workflow quirk: cannot access this inline location reference

Activity '{0}' cannot access this inline location reference because it is only valid for activity '{1}'. Only the activity which obtained the inline location reference is allowed to use it.

Inside my assign activity:
' foundfiles is IEnumerable(of String)
foundFiles.Where(Function(file As String) FileNameBlacklist.Any(Function(blacklistItem) System.IO.Path.GetFileName(file).StartsWith(blacklistItem)) = False)

Not sure if this or the subsequent access was failing, however changing it to this fixed it:

foundFiles.Where(Function(file As String) FileNameBlacklist.Any(Function(blacklistItem) System.IO.Path.GetFileName(file).StartsWith(blacklistItem)) = False).ToList().AsEnumerable