-
Notifications
You must be signed in to change notification settings - Fork 29
Custom Conventions
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:
- Extend
ConventionSpecification
,AsyncConventionSpecification
,AssemblyConventionSpecification
,DatabaseConventionSpecification
, orSolutionConventionSpecification
, depending on your use-case. The most common, if you are enforcing type conventions, isConventionSpecification
. - Locate an appropriate derived convention to extend, such as
PropertyConventionSpecification
,MustNotUseMethodSpecification
, orMustNotUsePropertyGetterSpecification<TClass, TMember>
. - 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);