Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture design guidelines, principles and patterns #1340

Closed
dennisdoomen opened this issue May 31, 2020 · 1 comment
Closed

Capture design guidelines, principles and patterns #1340

dennisdoomen opened this issue May 31, 2020 · 1 comment

Comments

@dennisdoomen
Copy link
Member

dennisdoomen commented May 31, 2020

  • High-level principles such as written down in Open up OccurenceConstraint for usage in custom assertion extensions #1281 (comment)
  • Behavioral patterns such as how to deal with null arguments
  • When to return AndWhichConstraint vs AndConstraint.
  • When to use FailWith vs throwing a normal .NET exception type
  • Prefer "Did not expect something to be" over "Expected something not to be"
  • Decisions (like a poor mans Architecture Design Log) such as why we target certain frameworks
  • When using AndWhichConstraint<..., T> the T element must be fetched in way resilient to that FailWith don't throw immediately when encapsulated in a custom AssertionScope.
  • Assertion class over non-sealed classes or interfaces should probably be generic in type to avoid loosing type information.
    E.g instead of MyClassAssertions then MyClassAssertions<T> where T : MyClass
  • Be aware that an assertion might be wrapped in an AssertionScope so FailWith does not halts execution and extra precautions must be taken to avoid e.g. en NullReferenceException after verifying that Subject is not null
  • Don't use predicate.Body to format a predicate in a failure message. Just pass the predicate to FailWith and let the PredicateLambdaExpressionValueFormatter handle formatting it properly
  • Naming and grouping guidelines (based on this post)
    • Group tests for the same API using a nested class such as in NullableNumericSpecs so you don't have to repeat the API name in the name of the test
    • Avoid the use of When and Should in test names and use concise names like Exclusion_of_missing_members_works_with_mapping
  • When writing parameterized tests prefer using [InlineData], unless:
    • the values are not compile-time constants, or
    • there is a good reason to share the parameters between multiple tests.
  • Don't use Should().NotThrow in the assert.

Code style

  • String formatting should use Invariant culture when formatting non-strings.
  • Lines should not be wider than 130 characters.
  • Prefer is null and is not null over !=/== null
@dennisdoomen dennisdoomen added this to the 6.0 milestone May 11, 2021
@dennisdoomen dennisdoomen changed the title Capture design principles and patterns Capture design guidelines, principles and patterns May 11, 2021
@dennisdoomen dennisdoomen removed this from the 6.0 milestone May 22, 2021
@dennisdoomen dennisdoomen pinned this issue Mar 12, 2022
@dennisdoomen
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant