public void NoTraits() { Type testClassType = typeof(ClassWithTraits); MethodInfo methodInfo = testClassType.GetMethod("MethodDoesNotHaveTestTraits"); var traits = MethodUtility.GetTraits(Reflector.Wrap(methodInfo)); Assert.Equal(0, traits.Count); }
private void HandleTraits() { var traits = MethodUtility.GetTraits(methodInfo); categories = ExtractTraitValues(traits, "category"); owners = ExtractTraitValues(traits, "owner"); descriptions = ExtractTraitValues(traits, "description"); testProperties = ConvertToTestPropeties(traits); }
public void SingleTraitOnATestMethod() { Type testClassType = typeof(ClassWithTraits); MethodInfo methodInfo = testClassType.GetMethod("SingleTraitOnAMethod"); var traits = MethodUtility.GetTraits(Reflector.Wrap(methodInfo)); Assert.Single(traits); string description = Assert.Single(traits["Description"]); Assert.Equal("more than just the test method name", description); }
public void TraitsOnClass() { Type testClassType = typeof(ClassWithClassTraits); MethodInfo methodInfo = testClassType.GetMethod("TestMethod"); var traits = MethodUtility.GetTraits(Reflector.Wrap(methodInfo)); Assert.Equal(2, traits.Count); string description = Assert.Single(traits["Description"]); Assert.Equal("more than just the test method name", description); string author = Assert.Single(traits["Author"]); Assert.Equal("James Newkirk", author); }
public static MultiValueDictionary <string, string> SafelyGetTraits(this IMethodInfo methodInfo) { try { // GetTraits relies on our attribute parsing to get at a property // value. Unless that value is set in the attribute constructor // via a named parameter (property) or a parameter with a name // similar to the required property, we'll return null, and that // can cause exceptions. If we get an exception, fail as nicely // as we can, with an empty collection of traits return(MethodUtility.GetTraits(methodInfo)); } catch (Exception) { return(new MultiValueDictionary <string, string>()); } }