tpierrain/NFluent

Add HasAttribute<TAttr>() check

Closed this issue · 8 comments

I've tried to create my own check but since FluentCheck is internal, it's difficult to implement.
This check would check if a class or method had a specific attribute.

hello
thanks for reaching out. If you have not read it already, I suggest you read @rhwy articles on how to create your own checks : http://www.codedistillers.com/rui/2013/11/26/nfluent-extensions/

can you please elaborate a bit on what you try to achieve and why such check is useful?
We try to gather as much as we can regarding usage of the library

I try to create unit test that check is a method had specific attribute, such as HttpPostAttribute. For that, I would like to write :
Check.That(MyClass.MyMethod).HasAttribute<HttpPostAttribute>()
I've check the article but here, I must work on type level and the API doesn't seem to help me... ;)

Thanks for the clarification, I am trying to achieve the same result,
but I struggle to get the proper signature for your check. Since it seems you are confortable doing that, and disregarding the current design of NFluent, what is the proper signature for Check.That(MyClass.MyMethod)?

In fact, the proposed check could not compile like that since MyMethod couldn't be static.
Perhaps something like
Check.That<MyClass>().HasAttribute<MyAttribute>() To check if a class had an attribute
Check.That<MyClass>(m=>m.MyMethod(A<int>._)).HasAttribute<MyAttribute>() to check if the method had the attribute (I've used the place holder of FakeItEasy for the parameter of MyMethod)

Thanks, I have implemented your first proposal. You can see the code in the NFluent/Nfluent repo:
Implementation
Tests

Can you please confirm this is what you have in mind?

Yes, it seems really cool and you gave me a pattern to check other reflexion properties.
Thx a lot!

Cool. Well done @dupdob !

released