PageRenderTime 72ms CodeModel.GetById 65ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/Extensibility/DataPointProviders.cs

#
C# | 116 lines | 70 code | 15 blank | 31 comment | 10 complexity | dece62c5f880811a9357ff2614823048 MD5 | raw file
  1// ****************************************************************
  2// Copyright 2008, Charlie Poole
  3// This is free software licensed under the NUnit license. You may
  4// obtain a copy of the license at http://nunit.org.
  5// ****************************************************************
  6
  7using System;
  8using System.Reflection;
  9using System.Collections;
 10
 11namespace NUnit.Core.Extensibility
 12{
 13    class DataPointProviders : ExtensionPoint, IDataPointProvider2
 14    {
 15        public DataPointProviders(ExtensionHost host)
 16            : base("DataPointProviders", host) { }
 17
 18        #region IDataPointProvider Members
 19
 20        /// <summary>
 21        /// Determine whether any data is available for a parameter.
 22        /// </summary>
 23        /// <param name="parameter">A ParameterInfo representing one
 24        /// argument to a parameterized test</param>
 25        /// <returns>True if any data is available, otherwise false.</returns>
 26        public bool HasDataFor(ParameterInfo parameter)
 27        {
 28            foreach (IDataPointProvider provider in Extensions)
 29                if (provider.HasDataFor(parameter))
 30                    return true;
 31
 32            return false;
 33        }
 34
 35        /// <summary>
 36        /// Return an IEnumerable providing data for use with the
 37        /// supplied parameter.
 38        /// </summary>
 39        /// <param name="parameter">A ParameterInfo representing one
 40        /// argument to a parameterized test</param>
 41        /// <returns>An IEnumerable providing the required data</returns>
 42        public IEnumerable GetDataFor(ParameterInfo parameter)
 43        {
 44            ArrayList list = new ArrayList();
 45
 46            foreach (IDataPointProvider provider in Extensions)
 47                if (provider.HasDataFor(parameter))
 48                    foreach (object o in provider.GetDataFor(parameter))
 49                        list.Add(o);
 50
 51            return list;
 52        }
 53        #endregion
 54
 55        #region IDataPointProvider2 Members
 56
 57        /// <summary>
 58        /// Determine whether any data is available for a parameter.
 59        /// </summary>
 60        /// <param name="parameter">A ParameterInfo representing one
 61        /// argument to a parameterized test</param>
 62        /// <returns>True if any data is available, otherwise false.</returns>
 63        public bool HasDataFor(ParameterInfo parameter, Test suite)
 64        {
 65            foreach (IDataPointProvider provider in Extensions)
 66            {
 67                if (provider is IDataPointProvider2)
 68                {
 69                    IDataPointProvider2 provider2 = (IDataPointProvider2)provider;
 70                    if (provider2.HasDataFor(parameter, suite))
 71                        return true;
 72                }
 73                else if (provider.HasDataFor(parameter))
 74                    return true;
 75            }
 76
 77            return false;
 78        }
 79
 80        /// <summary>
 81        /// Return an IEnumerable providing data for use with the
 82        /// supplied parameter.
 83        /// </summary>
 84        /// <param name="parameter">A ParameterInfo representing one
 85        /// argument to a parameterized test</param>
 86        /// <returns>An IEnumerable providing the required data</returns>
 87        public IEnumerable GetDataFor(ParameterInfo parameter, Test suite)
 88        {
 89            ArrayList list = new ArrayList();
 90
 91            foreach (IDataPointProvider provider in Extensions)
 92            {
 93                if (provider is IDataPointProvider2)
 94                {
 95                    IDataPointProvider2 provider2 = (IDataPointProvider2)provider;
 96                    if (provider2.HasDataFor(parameter, suite))
 97                        foreach (object o in provider2.GetDataFor(parameter, suite))
 98                            list.Add(o);
 99                }
100                else if (provider.HasDataFor(parameter))
101                    foreach (object o in provider.GetDataFor(parameter))
102                        list.Add(o);
103            }
104
105            return list;
106        }
107        #endregion
108
109        #region ExtensionPoint Overrides
110        protected override bool IsValidExtension(object extension)
111        {
112            return extension is IDataPointProvider;
113        }
114        #endregion
115    }
116}