Esempio n. 1
0
        static object[] GetTestMethodArguments(ITestMethod testMethod, int attributeNumber, int rowNumber, IMessageSink diagnosticMessageSink)
        {
            try
            {
                IAttributeInfo dataAttribute =
                    testMethod.Method.GetCustomAttributes(typeof(DataAttribute))
                    .Where((x, i) => i == attributeNumber)
                    .FirstOrDefault();

                if (dataAttribute == null)
                {
                    return(null);
                }

                IAttributeInfo discovererAttribute =
                    dataAttribute.GetCustomAttributes(typeof(DataDiscovererAttribute)).First();

                IDataDiscoverer discoverer =
                    ExtensibilityPointFactory.GetDataDiscoverer(diagnosticMessageSink, discovererAttribute);

                return
                    (discoverer.GetData(dataAttribute, testMethod.Method)
                     .Where((x, i) => i == rowNumber)
                     .FirstOrDefault());
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 2
0
        public static IScenarioDiscoverer GetDiscoverer(IMessageSink diagnosticsMessageSink, IAttributeInfo scenarioAttribute)
        {
            if (scenarioAttribute == null)
            {
                throw new ArgumentNullException(nameof(scenarioAttribute));
            }
            var discovererAttribute = scenarioAttribute.GetCustomAttributes(typeof(ScenarioDiscovererAttribute)).SingleOrDefault();

            if (discovererAttribute == null)
            {
                throw new InvalidOperationException(
                          $"{ScenarioAttribute.GetAttributeTypeName(scenarioAttribute)} must be annotated with a single ScenarioDiscovererAttribute");
            }

            var args           = discovererAttribute.GetConstructorArguments().Cast <string>().ToList();
            var discovererType = LoadType(args[1], args[0]);

            if (discovererType == null)
            {
                throw new InvalidOperationException(
                          $"Could not load scenario discoverer of type \"{args[1]}, {args[0]}\" for {ScenarioAttribute.GetAttributeTypeName(scenarioAttribute)}");
            }

            return(GetDiscoverer(diagnosticsMessageSink, discovererType));
        }
        static object[] GetTestMethodArguments(ITestMethod testMethod, int attributeNumber, string rowName, IMessageSink diagnosticMessageSink)
        {
            try
            {
                IAttributeInfo dataAttribute = testMethod.Method.GetCustomAttributes(typeof(DataAttribute)).Where((x, i) => i == attributeNumber).FirstOrDefault();
                if (dataAttribute == null)
                {
                    return(null);
                }

                IAttributeInfo  discovererAttribute = dataAttribute.GetCustomAttributes(typeof(DataDiscovererAttribute)).First();
                IDataDiscoverer discoverer          = ExtensibilityPointFactory.GetDataDiscoverer(diagnosticMessageSink, discovererAttribute);

                IEnumerable <object[]> data = discoverer.GetData(dataAttribute, testMethod.Method);

                if (data is IDictionary <string, object[]> )
                {
                    return(((IDictionary <string, object[]>)data)[rowName]);
                }

                return(data.Where(x => x[0].ToString() == rowName).FirstOrDefault());
            }
            catch
            {
                return(null);
            }
        }
        public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
        {
            if (traitAttribute == null) throw new ArgumentNullException(nameof(traitAttribute));

            var categoryAttributes = traitAttribute.GetCustomAttributes(typeof(CategoryAttribute).AssemblyQualifiedName);

            if (!categoryAttributes.Any())
                yield break;

            var category = categoryAttributes.Single().GetConstructorArguments().Single();
            yield return new KeyValuePair<string, string>("Category", category.ToString());
        }
Esempio n. 5
0
 /// <summary>
 /// Gets all the custom attributes for the given attribute.
 /// </summary>
 /// <param name="attributeInfo">The attribute.</param>
 /// <param name="attributeType">The type of the attribute to find.</param>
 /// <returns>The matching attributes that decorate the attribute.</returns>
 public static IEnumerable <IAttributeInfo> GetCustomAttributes(this IAttributeInfo attributeInfo, Type attributeType)
 {
     return(attributeInfo.GetCustomAttributes(attributeType.AssemblyQualifiedName));
 }
Esempio n. 6
0
 public IEnumerable <IAttributeInfo> GetCustomAttributes(string assemblyQualifiedAttributeTypeName)
 {
     return(inner.GetCustomAttributes(assemblyQualifiedAttributeTypeName));
 }