Dear ladies and sirs.
In my scenario I create dynamic tests, where each test wraps the
respective statically compiled test. It is essential, that any
metadata found on the static test will be copied to the respective
dynamic test.
Quite conveniently, the TestCase type has Metadata dictionary. So, I
execute a code like this:
var test = new TestCase(...);
var metadataAttrs =
(MetadataAttribute[])methodInfo.GetCustomAttributes(typeof(MetadataAttribute),
false);
metadataAttrs.ForEach(m => test.Metadata.Add(m.MetadataKey,
m.MetadataValue));
BUT, CategoryAttribute is left out, because it does not derive from
MetadataAttribute, but from MetadataPatternAttribute!
My question is why? The Category is still metadata and it is treated
internally as such. When I change the last line of the aforementioned
code sample to this:
metadataAttrs.ForEach(i =>
{
var c = i as CategoryAttribute;
if (c == null)
{
var m = (MetadataAttribute)i;
test.Metadata.Add(m.MetadataKey, m.MetadataValue);
}
else
{
test.Metadata.Add("Category", c.Category);
}
});
The dynamic tests are now treated as though they had the Category
attribute, when what I did is just added the "Category" metadata key
corresponding to the Category attribute.
This Category-not-Metadata business makes the code more ugly.
Another solution would be to raise the scope of the
MetadataPatternAttribute.GetMetadata() method from protected to
public.
What do you think?
--
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/mbunituser?hl=en.