Extension Configuration

Extensions can be added to Concordion.NET using an attribute in the fixture class and/or using the configuration file.

Attributes

[Extension]

Within a fixture class, fields that are annotated with Concordion.NET.Api.Extension.Extension will be added to Concordion.NET as extensions.

Fields with this attribute must be public and must implement org.concordion.api.extension.ConcordionExtension.

Example - Extensions fields

Executing a class that contains [Extension] attributes on fields with instances of ConcordionExtension:

using org.concordion.api.extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    public class ExampleFixtureWithFieldAttributes
    {
        [NET.Api.Extension.Extension]
        public ConcordionExtension extension = new FakeExtension1();

        [NET.Api.Extension.Extension]
        public FakeExtension2 extension2 = new FakeExtension2();
    }
}   

will install both extensions FakeExtension1, FakeExtension2.

Extensions will be loaded from the fixture class and any of its superclasses in parent-first order. A common pattern is to have the extensions defined in a "base fixture".

Example - Extension fields in superclass

Executing the following fixture:

using org.concordion.api.extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    class ExampleDerivedFixtureWithFieldAttributes : ExampleFixtureBaseWithFieldAttributes
    {
        [NET.Api.Extension.Extension]
        public ConcordionExtension extension = new FakeExtension1("ExampleExtension");
    }
}    

which has superclass

using Concordion.NET.Api.Extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    public class ExampleFixtureBaseWithFieldAttributes
    {
        [Extension]
        public FakeExtension2 extension2 = new FakeExtension2("SuperExtension");
    }
}    

will install both the extensions initialised with parameters ExampleExtension, SuperExtension.

[Extensions]

As an alternative, extensions that require no state from the fixture can be defined statically on the fixture class with the Concordion.NET.Api.Extension.Extensions attribute. This attribute is parameterized with a list of the extension, or extension factory, classes to be installed.

Extensions must implement org.concordion.api.extension.ConcordionExtension. Extension factories must implement org.concordion.api.extension.ConcordionExtensionFactory.

Example - Extensions

Executing the following fixture:

using Concordion.NET.Api.Extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    [Extensions(typeof(FakeExtension1), typeof(FakeExtension2Factory))]
    public class ExampleFixtureWithClassAttributes
    {
    }
}    

will install both extensions FakeExtension1, FakeExtension2FromFactory.

Extensions will be loaded from the fixture class and any of its superclasses in parent-first order. A common pattern is to have the extensions defined in a "base fixture".

Example - Extensions from superclass are loaded

Executing the following fixture:

using Concordion.NET.Api.Extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    [Extensions(typeof(FakeExtension1))]
    public class ExampleDerivedFixtureWithClassAttributes : ExampleFixtureBaseWithClassAttribute
    {
    }
}    

which has superclass

using Concordion.NET.Api.Extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    [Extensions(typeof(FakeExtension2Factory))]
    public class ExampleFixtureBaseWithClassAttribute
    {
    }
}     

will install both extensions FakeExtension1, FakeExtension2FromFactory.

Concordion.NET Configuration File

Alternatively, extensions can be specified by setting Concordion.NET configurations. This can be useful, if the extensions need to be configured independently from the fixtures.

Set the configuration entry <Extension> in the group <ConcordionExtensions> to reference:

All extensions and/or extension factories must be available to the class loader. Extensions must implement org.concordion.api.extension.ConcordionExtension. Extension factories must implement org.concordion.api.extension.ConcordionExtensionFactory.

Examples

Example - Concordion.NET Configuration for Extensions

Given the following configuration content::

<?xml version="1.0" encoding="utf-8" ?>
<Specification>
  <ConcordionExtensions>
    <Extension assembly="Concordion.Spec" type="Concordion.Spec.Concordion.Extension.Configuration.FakeExtension1" />
    <Extension assembly="Concordion.Spec" type="Concordion.Spec.Concordion.Extension.Configuration.FakeExtension2Factory" />
  </ConcordionExtensions>
</Specification>

Concordion.NET fixtures will be run with both extensions FakeExtension1, FakeExtension2FromFactory.

Combining the configuration methods

In some cases, you may wish to combine multiple methods of configuration from above.

Example - Combined configuration methods

Executing the following fixture:

using Concordion.NET.Api.Extension;

namespace Concordion.Spec.Concordion.Extension.Configuration
{
    [Extensions(typeof(FakeExtension1))]
    public class ExampleFixtureWithCombinedConfiguration : FakeExtensionBase
    {
        [Extension]
        public FakeExtension2 extension2 = new FakeExtension2();
    }
}
    

with the following configuration content::

<?xml version="1.0" encoding="utf-8" ?>
<Specification>
  <ConcordionExtensions>
    <Extension assembly="Concordion.Spec" type="Concordion.Spec.Concordion.Extension.Configuration.FakeExtension3" />
  </ConcordionExtensions>
</Specification>

will install the extensions FakeExtension1, FakeExtension2, FakeExtension3.