Beispiel #1
0
            public void NoTraits()
            {
                Type       testClassType = typeof(ClassWithTraits);
                MethodInfo methodInfo    = testClassType.GetMethod("MethodDoesNotHaveTestTraits");

                var traits = MethodUtility.GetTraits(Reflector.Wrap(methodInfo));

                Assert.Equal(0, traits.Count);
            }
Beispiel #2
0
        private void HandleTraits()
        {
            var traits = MethodUtility.GetTraits(methodInfo);

            categories   = ExtractTraitValues(traits, "category");
            owners       = ExtractTraitValues(traits, "owner");
            descriptions = ExtractTraitValues(traits, "description");

            testProperties = ConvertToTestPropeties(traits);
        }
Beispiel #3
0
            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);
            }
Beispiel #4
0
            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);
            }
Beispiel #5
0
 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>());
     }
 }