{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Creating a configuration class","type":"basic","slug":"defining-conventions","excerpt":"","body":"Before you can define conventions for your specs, you need to add a SpecsForConfiguration class to your spec project.  In the root of your project (or in a subfolder if you only want the conventions to apply to a subset of your specs), create a new class named \"Configuration.\"   Make this class derive from the SpecsFor.SpecsForConfiguration class, and decorate it with the NUnit SetUpFixture attribute:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using NUnit.Framework;\\nusing SpecsFor.Configuration;\\n\\nnamespace Conventions.Basics\\n{\\n    [SetUpFixture]\\n    public class Configuration : SpecsForConfiguration\\n    {\\n    }\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nYou can use the helper methods on the base class to define your conventions.  You'll do this within a constructor on your Configuration class.  \n\nThere are three methods you can use to define your conventions:\n\n* WhenTestingAnything - Begins defining a convention that will apply to **all** of your SpecsFor specs.  Note that any specs that do not derive from SpecsFor<T> will not have this convention applied to them.\n* WhenTesting - Begins a convention that applies to all specs that satisfy a specified filter.  For example: WhenTesting(s => s.Name.Contains(\"Foo\"))  \n* WhenTesting<T> - Begins a convention that applies to all specs that can be cast to type T.  \n\nEach of the above methods returns a fluent builder that you can use to either attach behaviors or customize how the spec's [SUT](doc:the-system-under-test-sut) is instantiated.\n\n* EnrichWith<T> - Applies the specified [behavior](doc:creating-a-behavior) to specs matching the convention.\n* CreateClassUnderTestingUsing - Uses the specified factory function to create the SUT for specs matching the convention. \n\n[Continue on to see how to define a behavior that applies to all classes](doc:applying-a-behavior-to-all-specs).","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"56ac1ec3aa91300d00bede9b","__v":9,"project":"54471fc9e12a270800028adc","category":{"sync":{"isSync":false,"url":""},"pages":["5447ef8d0319802200fc0713","56ac1ec3aa91300d00bede9b","56ac213d0bbe170d00f11272","56ac21d2c69a430d008aabb3","56b1401d4b05c50d001ceb3b","56c72ca5862f940d0056475d","56c75ec053cafe0d00a53d7b"],"title":"Convention System","slug":"convention-system","order":6,"from_sync":false,"reference":false,"_id":"5447ed230319802200fc0702","__v":7,"version":"54471fc9e12a270800028adf","createdAt":"2014-10-22T17:45:07.793Z","project":"54471fc9e12a270800028adc"},"githubsync":"","createdAt":"2016-01-30T02:24:03.167Z","user":"54471f91beb6320800da6f75","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["54471fc9e12a270800028ae0","5447b9e7b96a63140077d747","5447be130319802200fc0620","5447ed118d7af31a00dd411c","5447ed230319802200fc0702","5448524c4544c30800241f41","544854504544c30800241f4d","544854af4544c30800241f50","544854e74544c30800241f51","54485557c1b42e08005b82bf"],"_id":"54471fc9e12a270800028adf","__v":10,"project":"54471fc9e12a270800028adc","releaseDate":"2014-10-22T03:08:57.750Z","createdAt":"2014-10-22T03:08:57.750Z"}}

Creating a configuration class


Before you can define conventions for your specs, you need to add a SpecsForConfiguration class to your spec project. In the root of your project (or in a subfolder if you only want the conventions to apply to a subset of your specs), create a new class named "Configuration." Make this class derive from the SpecsFor.SpecsForConfiguration class, and decorate it with the NUnit SetUpFixture attribute: [block:code] { "codes": [ { "code": "using NUnit.Framework;\nusing SpecsFor.Configuration;\n\nnamespace Conventions.Basics\n{\n [SetUpFixture]\n public class Configuration : SpecsForConfiguration\n {\n }\n}", "language": "csharp" } ] } [/block] You can use the helper methods on the base class to define your conventions. You'll do this within a constructor on your Configuration class. There are three methods you can use to define your conventions: * WhenTestingAnything - Begins defining a convention that will apply to **all** of your SpecsFor specs. Note that any specs that do not derive from SpecsFor<T> will not have this convention applied to them. * WhenTesting - Begins a convention that applies to all specs that satisfy a specified filter. For example: WhenTesting(s => s.Name.Contains("Foo")) * WhenTesting<T> - Begins a convention that applies to all specs that can be cast to type T. Each of the above methods returns a fluent builder that you can use to either attach behaviors or customize how the spec's [SUT](doc:the-system-under-test-sut) is instantiated. * EnrichWith<T> - Applies the specified [behavior](doc:creating-a-behavior) to specs matching the convention. * CreateClassUnderTestingUsing - Uses the specified factory function to create the SUT for specs matching the convention. [Continue on to see how to define a behavior that applies to all classes](doc:applying-a-behavior-to-all-specs).