Testing Arguments of Attributes

Nov 13, 2011 at 10:31 PM


    public class OutputClassifierProvider : IClassifierProvider

I can write the following test:

        public void GetClassifierAttributes()
Which is stunningly cool. Is there a way to assert the arguments of the attributes as well?

Nov 18, 2011 at 3:31 PM

Currently it is not possible to assert the arguments of the attributes.

Jan 8, 2012 at 8:16 AM

@blueonion If you can think of a nice syntax, we might consider it.

Jan 8, 2012 at 11:58 AM

The simplest form I can think of is:


Another form might be:



typeof(OutputClassifierProvider).Should().BeDecoratedWith<ContentTypeAttribute>().WithArgs(new object[] {"output"})

Where WithArgs takes an object array. I don't write fluent interfaces very often but know they're difficult to get right and implement.

Jan 9, 2012 at 6:30 PM

What you are trying to do is not possible. When you query a type for an attribute, Reflection will return you an instance of the attribute, not its definition. So if you want to make sure the attribute was configured properly, you need to expose that data through properties.

Jun 3, 2012 at 7:45 AM

We have created issue 12186 to support this.
See http://fluentassertions.codeplex.com/workitem/12186.