Skip to content
Andrew Best edited this page Feb 3, 2020 · 1 revision

Conventional has been designed with extensibility in mind. It ships with a boat-load of its own conventions, but it is likely you will need something particular to suit your own codebases.

Eddie Would has written a post that serves as a fantastic illustration of what you can accomplish - building his own convention to ensure MockBehavior.Strict is set throughout his codebase when using the popular mocking framework Moq.

To create your own convention, you have a few options:

  1. Extend ConventionSpecification, AsyncConventionSpecification, AssemblyConventionSpecification, DatabaseConventionSpecification, or SolutionConventionSpecification, depending on your use-case. The most common, if you are enforcing type conventions, is ConventionSpecification.
  2. Locate an appropriate derived convention to extend, such as PropertyConventionSpecification, MustNotUseMethodSpecification, or MustNotUsePropertyGetterSpecification<TClass, TMember>.
  3. Go from bare metal from an interface such as IConventionSpecification.

All of these will still allow you to use Conventional's simple fluent interface for applying conventions:

new[] { typeof(MyType), typeof(MyOtherType) }
    .MustConformTo(Convention.PropertiesMustHavePublicGetters)
    .AndMustConformTo(new MyCustomConvention())
    .WithFailureAssertion(Assert.Fail);