This library is used to define architecture rules as expectations that can be run and checked as part of the unit test execution.
-
Test classes should have
Tests
as suffix:[Fact] public void ExpectTestClassesToBeSuffixedWithTests() { IRule rule = Expect.That.Types .Which(Have.Method.WithAttribute<FactAttribute>().OrAttribute<TheoryAttribute>()) .ShouldMatchName("*Tests"); rule.Check .InAllLoadedAssemblies() .ThrowIfViolated(); }
-
Methods that return
Task
should haveAsync
as suffix:[Fact] public void AsyncMethodsShouldHaveAsyncSuffix() { IRule rule = Expect.That.Methods .WithReturnType<Task>().OrReturnType(typeof(Task<>)) .ShouldMatchName("*Async") .AllowEmpty(); rule.Check .InTestAssembly() .ThrowIfViolated(); }