Reputation: 9113
The .NET FluentAssertions library (version 2.1.0) has several BeDecoratedWith<T>()
implementations for asserting that a type (or type member) has a given attribute applied to it. These calls look like this:
typeof(X).Should()
.BeDecoratedWith<SomeAttribute>(attr => attr.Name == expectedValue);
The lambda expression asserts that the attribute has a Name
equal to some expectedValue
.
This is great when the sut
is a type, but when it is a member there is no overload of BeDecoratedWith<T>
that takes a lambda expression.
// compiler error: Cannot convert lambda expression to type 'string' because it is not a delegate type
typeof(X).GetProperty("xyz").Should()
.BeDecoratedWith<SomeAttribute>(attr => attr.Name == expectedValue);
The documentation quickly covers extensibility, but I'm having trouble working out how I'd create an overload (or extension method) of BeDecoratedWith<T>
on the PropertyInfoAssertions
class that accepts a lambda like the one above.
Could someone show me the proper way to extent Fluent Assertions to accomplish this?
Upvotes: 1
Views: 1110
Reputation: 8909
You have two options:
Upvotes: 2
Reputation: 35911
One possible answer is to wait a while and then get the latest version, as this issue seems to have been fixed recently :)
http://fluentassertions.codeplex.com/workitem/12455
Upvotes: 0