Extensions can be added to Concordion.NET using an attribute in the fixture class and/or using the configuration file.
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
.
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".
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.
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
.
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".
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.
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
.
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.
In some cases, you may wish to combine multiple methods of configuration from above.
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.