BenMorris / NetArchTest

A fluent API for .Net that can enforce architectural rules in unit tests.
MIT License
1.36k stars 81 forks source link

Conditions.OnlyHaveDependenciessOn fails when switch expression is used #101

Closed TipluSebastian closed 2 years ago

TipluSebastian commented 2 years ago

Hi,

we want to assert that a project only depends on certain assemblies. This check fails if we use a switch-expression in the project under test.

net-arch-switch-bug is a minimal example repository to show the unexpected behaviour of the test: We would expect the test to pass, but it fails.

It is odd, that the test passes if there are 7 or less statements inside the switch-expression (see NotFailingLocalNameTranslator).

Thank you for this nice library.

NeVeSpl commented 2 years ago

7 is the magic number for the Roslyn compilator, it generates different code for switch statements and expressions when there are more than 7 options available. In that case, Roslyn introduced a new compiler-generated type of which NetArchTest was not aware of.