Beispiel #1
0
 protected bool Equals(AnnotatedTest other)
 {
     return(string.Equals(EquivalanceClass, other.EquivalanceClass) && IndividualTest.Equals(other.IndividualTest) &&
            Concepts.OrderBy(o => o).SequenceEqual(other.Concepts.OrderBy(o => o)));
 }
        public List <AnnotatedTest> GetAnnotations(Assembly dll)
        {
            List <AnnotatedTest> annotatedTests = new List <AnnotatedTest>();
            var dType = dll.DefinedTypes;

            //Assumes custom attributes will have the word "custom" in them!
            var type = dType
                       .Where(x => !x.ToString().Contains("Custom"));

            foreach (var t in type)
            {
                //Find all method names in test file
                var methodNames = t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                                  .Select(x => x.Name)
                                  .Distinct()
                                  .OrderBy(x => x);

                MethodInfo methodInfo;
                List <Tuple <List <Attribute>, string> > attributes = new List <Tuple <List <Attribute>, string> >();

                //Loop through names grabbing only ones with CustomAttribute
                foreach (string s in methodNames)
                {
                    methodInfo = t.GetMethod(s, BindingFlags.Public | BindingFlags.Instance,
                                             null,
                                             CallingConventions.Any,
                                             new Type[] { },
                                             null);

                    if (methodInfo != null)
                    {
                        var AnnotatedTest         = new AnnotatedTest();
                        List <Attribute> attrList = new List <Attribute>();

                        var testinfo = methodInfo.GetCustomAttributes();
                        if (methodInfo.GetCustomAttributes().Count() > 1)
                        {
                            foreach (Attribute at in methodInfo.GetCustomAttributes())
                            {
                                attrList.Add(at);
                            }
                        }

                        test.Add(type.ToString() + '.' + methodInfo.Name);
                        nameSpaceStrings.Add(methodInfo.Name);

                        foreach (var attr in attrList)
                        {
                            //Assumes that custome attributes will contain "Custom" in the name!
                            if (attr.ToString().Contains("Custom"))
                            {
                                dynamic c = Activator.CreateInstance(attr.GetType());

                                c = attr;
                                AnnotatedTest.Concepts         = c.concepts;
                                AnnotatedTest.EquivalanceClass = c.equivalenceClass;
                            }
                        }

                        AnnotatedTest.IndividualTest.TestName = t.ToString() + '.' + methodInfo.Name;
                        annotatedTests.Add(AnnotatedTest);
                    }
                }
            }
            return(annotatedTests);
        }