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
More Assertions on types #645
Comments
Is this something you need yourself? If not, I really need some help to finish https://github.com/fluentassertions/fluentassertions/milestone/10 |
I have a case that could be more readable with |
Checking |
In that same light, you could also think of something like: noClasses()
.that()
.resideIn("..model..")
.should()
.dependOnClassesThat()
.resideIn("..application.."); Not sure how you would phrase that, but the idea here is to make assertions on the design of the code. |
@jnyrup Hey sorry to bother! I am genuinely interested in knowing in which situation you are using tests which ensure a modifier or a keyword. As for now, I have always written tests targeting the "feature" provided by the method but not the "how". |
@Evangelink No need to apologize. At work I've used the type assertion API, as a poor man's code analyzer, to avoid some coding pitfalls. For example a [RangeValidator(0, RangeBoundaryType.Inclusive, 100, RangeBoundaryType.Inclusive)] but should have been [RangeValidator(0.0, RangeBoundaryType.Inclusive, 100.0, RangeBoundaryType.Inclusive)] IIRC the Then I wrote a |
Oh, I see! I had a few cases like that in the past but I went for the analyzer option :) Thank you @jnyrup |
I think this is extremely useful. I am doing similar things to the RangeValidator test above in my projects to enforce certain project specific implementation policies without having to create code analyzers (which I did not study yet).
|
+ public TypeSelector ThatImplement(Type interfaceType) + public TypeSelector ThatDoNotImplement(Type interfaceType) + public TypeSelector ThatAreDecoratedWith(Type attribute) + public TypeSelector ThatAreDecoratedWithOrInherit(Type attribute) + public TypeSelector ThatAreNotDecoratedWith(Type attribute) + public TypeSelector ThatAreNotDecoratedWithOrInherit(Type attribute)
I think this issues needs some updates. A lot of things seem to have been implemented over the past years. |
@jnyrup Just a gut feel when I looked at it. I'll try to have a thorough look next week. |
The ones in #1700 are for typeof(MyType)
.Methods() // <-- returns a MethodInfoSelector
.ThatAreAsync() // <-- MethodInfoSelector
.Should() // <-- returns a MethodInfoSelectorAssertions
.BeDecoratedWith<MyAttribute>(); // <-- MethodInfoSelectorAssertions |
OK, thanks for the clarification. Now I get it. Sorry. |
@jnyrup Is there an ordered list of top 10 requests? |
For the APIs from this issue? |
hi @jnyrup |
You can run one of the |
@jnyrup And as i understand If yes, then i will make a pull request for
evtl.
To extend
|
When I created this ticket 5 years ago I spend little to no time thinking about what APIs would actually be useful - I even see that I wrote
Over the years that have passed we have become much more aware about what the value of an API is before adding it. As I re-read this issue I suspect that the
I'm not sure I understand your question, but in general we want to test functionalities through their public APIs, so |
…or (as mentioned in More Assertions on types fluentassertions#645)
…PropertyInfoSelector (as mentioned in More Assertions on types fluentassertions#645)
Thanks for all the implementations contributed over the years ❤️ For the remainder of the APIs, if you would find it useful in your usage of Fluent Assertions, please open a new issue describing the use-case, then we can discuss the it there. |
We do have an impressive amount of type assertions.
I've tried to lookup the .net type hierarchy and keywords to see what we might be missing.
See the bottom for types and keywords.
Here's a rough sketch of what such APIs could look like, but please notice that I haven't checked if they are:
FieldInfoAssertions : MemberInfoAssertions<FieldInfo, FieldInfoAssertions>[Not]BeVolatile[Not]BeConstFieldInfoSelectorThatAre[Not]VolatileThatAre[Not]Const[Not]BeOverridableThatAreAsync()
andThatAreNotAsync()
toMethodInfoSelector
#1725ThatAre[Not]OverridableThatAre[Not]Abstract
toMethodInfoSelector
#2060ThatAre[Not]OverridableThatAre[Not]Abstract
,ThatAre[Not]Static
andThatAre[Not]Virtual
toPropertyInfoSelector
#2054ThatAre[Not]Abstract
,ThatAre[Not]Static
andThatAre[Not]Virtual
toPropertyInfoSelector
#2054ThatAre[Not]Abstract
,ThatAre[Not]Static
andThatAre[Not]Virtual
toPropertyInfoSelector
#2054StructAssertions : TypeAssertionsStructSelector : TypeSelectorThatAre[Not]Abstract
toTypeSelector
#2058ThatAre[Not]Sealed
toTypeSelector.cs
#2059ThatAre[Not]Structs
inTypeSelector.cs
#2056ThatAre[Not]Interfaces
toTypeSelector.cs
#2057References:
Type hierachy:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/members
Keywords and which type they apply to:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
The text was updated successfully, but these errors were encountered: