{"action":"created","issue":{"url":"https://api.github.com/repos/xunit/xunit/issues/588","labels_url":"https://api.github.com/repos/xunit/xunit/issues/588/labels{/name}","comments_url":"https://api.github.com/repos/xunit/xunit/issues/588/comments","events_url":"https://api.github.com/repos/xunit/xunit/issues/588/events","html_url":"https://github.com/xunit/xunit/issues/588","id":106324836,"number":588,"title":"Programmatically get traits","user":{"login":"MichaelLogutov","id":405031,"avatar_url":"https://avatars.githubusercontent.com/u/405031?v=3","gravatar_id":"","url":"https://api.github.com/users/MichaelLogutov","html_url":"https://github.com/MichaelLogutov","followers_url":"https://api.github.com/users/MichaelLogutov/followers","following_url":"https://api.github.com/users/MichaelLogutov/following{/other_user}","gists_url":"https://api.github.com/users/MichaelLogutov/gists{/gist_id}","starred_url":"https://api.github.com/users/MichaelLogutov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichaelLogutov/subscriptions","organizations_url":"https://api.github.com/users/MichaelLogutov/orgs","repos_url":"https://api.github.com/users/MichaelLogutov/repos","events_url":"https://api.github.com/users/MichaelLogutov/events{/privacy}","received_events_url":"https://api.github.com/users/MichaelLogutov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/xunit/xunit/labels/[a]%20xunit","name":"[a] xunit","color":"5319e7"},{"url":"https://api.github.com/repos/xunit/xunit/labels/[r]%20Fixed","name":"[r] Fixed","color":"eb6420"},{"url":"https://api.github.com/repos/xunit/xunit/labels/[t]%20Feature","name":"[t] Feature","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/xunit/xunit/milestones/20","html_url":"https://github.com/xunit/xunit/milestones/2.1-rc2","labels_url":"https://api.github.com/repos/xunit/xunit/milestones/20/labels","id":1315449,"number":20,"title":"2.1-rc2","description":"","creator":{"login":"bradwilson","id":16944,"avatar_url":"https://avatars.githubusercontent.com/u/16944?v=3","gravatar_id":"","url":"https://api.github.com/users/bradwilson","html_url":"https://github.com/bradwilson","followers_url":"https://api.github.com/users/bradwilson/followers","following_url":"https://api.github.com/users/bradwilson/following{/other_user}","gists_url":"https://api.github.com/users/bradwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/bradwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradwilson/subscriptions","organizations_url":"https://api.github.com/users/bradwilson/orgs","repos_url":"https://api.github.com/users/bradwilson/repos","events_url":"https://api.github.com/users/bradwilson/events{/privacy}","received_events_url":"https://api.github.com/users/bradwilson/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":3,"state":"closed","created_at":"2015-09-20T21:50:25Z","updated_at":"2015-09-26T05:42:18Z","due_on":null,"closed_at":"2015-09-26T05:42:18Z"},"comments":3,"created_at":"2015-09-14T11:48:41Z","updated_at":"2015-09-28T11:04:52Z","closed_at":"2015-09-19T19:03:22Z","body":"I need to enforce developers to decorate tests with trait \"Category=IntegrationTests\" if they used internal method, that performs restoring of test database. We currently using MSTests and it's quite simple to do - you get call stack of the current method, find the one that has TestMethod attribute, get all CategoryAttribute instances and check if there is one with \"IntegrationTests\" as a name.\r\n\r\nIn xUnit I can get TraitAttribute programmatically but I can't get actual name and value from it, because the instance of TraitAttribute does not stores parameters passed to it's constructor. Is there a way to get traits from the method programmatically?"},"comment":{"url":"https://api.github.com/repos/xunit/xunit/issues/comments/143713599","html_url":"https://github.com/xunit/xunit/issues/588#issuecomment-143713599","issue_url":"https://api.github.com/repos/xunit/xunit/issues/588","id":143713599,"user":{"login":"MichaelLogutov","id":405031,"avatar_url":"https://avatars.githubusercontent.com/u/405031?v=3","gravatar_id":"","url":"https://api.github.com/users/MichaelLogutov","html_url":"https://github.com/MichaelLogutov","followers_url":"https://api.github.com/users/MichaelLogutov/followers","following_url":"https://api.github.com/users/MichaelLogutov/following{/other_user}","gists_url":"https://api.github.com/users/MichaelLogutov/gists{/gist_id}","starred_url":"https://api.github.com/users/MichaelLogutov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichaelLogutov/subscriptions","organizations_url":"https://api.github.com/users/MichaelLogutov/orgs","repos_url":"https://api.github.com/users/MichaelLogutov/repos","events_url":"https://api.github.com/users/MichaelLogutov/events{/privacy}","received_events_url":"https://api.github.com/users/MichaelLogutov/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T11:04:52Z","updated_at":"2015-09-28T11:04:52Z","body":"Sorry to bring this up again, but I've just tried xunit version 2.1.0 with this test:\r\n\r\n    [Fact, Trait (\"Category\", \"Abc\")]\r\n    public void Test ()\r\n    {\r\n        // arrange\r\n        var call_stack = GetCallStackMethods ();\r\n\r\n\r\n        // act\r\n        var xunit_categories = call_stack.SelectMany (x => TraitHelper.GetTraits ((MethodInfo) x))\r\n                                            .Where (x => x.Key == \"Category\")\r\n                                            .Select (x => x.Value);\r\n\r\n\r\n        // assert\r\n        Assert.Equal (xunit_categories, new[] { \"Abc\" });\r\n    }\r\n\r\n\r\n    public static IEnumerable<MethodBase> GetCallStackMethods ()\r\n    {\r\n        var stack_frames = new StackTrace ().GetFrames ();\r\n\r\n        if (stack_frames != null)\r\n            return stack_frames.Select (x => x.GetMethod ());\r\n\r\n        return new[] { new StackFrame ().GetMethod () };\r\n    }\r\n\r\n\r\nAnd I've got this exception:\r\n\r\n    System.TypeLoadException: Could not load type 'Xunit.Sdk.TraitHelper' from assembly 'xunit.execution.desktop, Version=99.99.99.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c'.\r\n       at Bug.Tests.<Test>b__0(MethodBase x)\r\n       at System.Linq.Enumerable.<SelectManyIterator>d__1`2.MoveNext()\r\n       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n       at Xunit.Sdk.AssertEqualityComparer`1.CheckIfEnumerablesAreEqual(T x, T y) in C:\\BuildAgent\\work\\cb37e9acf085d108\\src\\xunit.assert\\Asserts\\Sdk\\AssertEqualityComparer.cs:line 100\r\n       at Xunit.Sdk.AssertEqualityComparer`1.Equals(T x, T y) in C:\\BuildAgent\\work\\cb37e9acf085d108\\src\\xunit.assert\\Asserts\\Sdk\\AssertEqualityComparer.cs:line 75\r\n       at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in C:\\BuildAgent\\work\\cb37e9acf085d108\\src\\xunit.assert\\Asserts\\EqualityAsserts.cs:line 34\r\n       at Xunit.Assert.Equal[T](IEnumerable`1 expected, IEnumerable`1 actual) in C:\\BuildAgent\\work\\cb37e9acf085d108\\src\\xunit.assert\\Asserts\\CollectionAsserts.cs:line 194\r\n       at Bug.Tests.Test() in C:\\My\\Bug (xUnit GetTraits)\\Bug\\Tests.cs:line 26\r\n\r\n\r\nAm I supposed to install some package other than \"xunit\" ?"}}