Skip to content

Alternative Bindings

Charlie Mott edited this page Nov 18, 2017 · 6 revisions

Wiki: Home > Tips and Tricks

Requirements

The Alternative Bindings technique was first described by Michael Stephenson in his testing series of blogs. On developer machines and lower test environments, it is often necessary to isolate dependencies from external systems using stubs. This stub may require some alterations to the bindings that go beyond just environment settings. It could be that an entirely different adapter needs to be used.

Solution

Add XmlPreprocess syntax as follows to the PortBindingsMaster.xml file

<!-- #ifdef _xml_preprocess -->
   ... Rest of bindings file. All ${ReplacementTokens} must be wrapped within xml pre-processor.
<!-- #endif -->
<!-- #if GetProperty("Environment")=="Local Development" -->
   <TransportTypeData>...${Setting1}...</TransportTypeData>
<!-- #endif -->
<!-- #if GetProperty("Environment")!="Local Development" -->
   <TransportTypeData>...${Setting1}...</TransportTypeData>
<!-- #endif -->
<!-- #ifdef _xml_preprocess -->
   ... Rest of bindings file. All ${ReplacementTokens} must be wrapped within xml pre-processor.
<!-- #endif -->

Note: I could not get this to work using #else syntax. It would not substitute the ${MySetting2} tag. Instead, I have used two #if statements.

Guidance

  • Try to replace the minimum amount of configuration so that as much of the target port bindings are included in your tests. e.g. Replace just the WCF Bindings in the TransportTypeData field rather than the whole send port.
  • Check you need to introduce the technique above. Sometimes there is a more simple way. For example, if you need to disable a custom pipeline component, try using the "opt-in" pattern by including an IsEnabled property. This pipeline component can then be disabled more easily using a standard replacement token.
  • Also see TransMock for an alternative approach to Alternative Bindings. In this framework, the Mockifier replaces the actual adapter configuration in receive locations and send ports that are marked for mocking in the binding file.

References