Exemplo n.º 1
0
 /// <summary>
 /// Construct a ParameterSet from an object implementing ITestCaseData
 /// </summary>
 /// <param name="data"></param>
 public TestCaseParameters(ITestCaseData data) : base(data)
 {
     if (data.HasExpectedResult)
     {
         ExpectedResult = data.ExpectedResult;
     }
 }
        public IEnumerable <ITestCaseData> GetTestCasesFor(MethodInfo method)
        {
            List <ITestCaseData> list           = new List <ITestCaseData>();
            IEnumerable          testCaseSource = GetTestCaseSource(method);

            if (testCaseSource != null)
            {
                ParameterInfo[] parameters = method.GetParameters();
                foreach (object item in testCaseSource)
                {
                    ParameterSet  parameterSet = new ParameterSet();
                    ITestCaseData testCaseData = item as ITestCaseData;
                    if (testCaseData != null)
                    {
                        parameterSet = new ParameterSet(testCaseData);
                    }
                    else if (item is object[])
                    {
                        object[] array = item as object[];
                        parameterSet.Arguments = ((array.Length == parameters.Length) ? array : new object[1] {
                            item
                        });
                    }
                    else if (item is Array)
                    {
                        Array array2 = item as Array;
                        if (array2.Rank == 1 && array2.Length == parameters.Length)
                        {
                            parameterSet.Arguments = new object[array2.Length];
                            for (int i = 0; i < array2.Length; i++)
                            {
                                parameterSet.Arguments[i] = array2.GetValue(i);
                            }
                        }
                        else
                        {
                            parameterSet.Arguments = new object[1] {
                                item
                            };
                        }
                    }
                    else
                    {
                        parameterSet.Arguments = new object[1] {
                            item
                        };
                    }
                    if (Category != null)
                    {
                        string[] array3 = Category.Split(',');
                        foreach (string value in array3)
                        {
                            parameterSet.Properties.Add(PropertyNames.Category, value);
                        }
                    }
                    list.Add(parameterSet);
                }
            }
            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a ParameterSet from an object implementing ITestCaseData
        /// </summary>
        /// <param name="data"></param>
        public ParameterSet(ITestCaseData data)
        {
            this.TestName = data.TestName;
            this.RunState = data.RunState;
            this.Arguments = this.OriginalArguments = data.Arguments;
            if (data.HasExpectedResult)
                ExpectedResult = data.ExpectedResult;
            this.Properties = new PropertyBag();

            foreach (string key in data.Properties.Keys)
                this.Properties[key] = data.Properties[key];
        }
Exemplo n.º 4
0
        /// <summary>
        /// Construct a ParameterSet from an object implementing ITestCaseData
        /// </summary>
        /// <param name="data"></param>
        public ParameterSet(ITestCaseData data)
        {
            this.TestName = data.TestName;
            this.RunState = data.RunState;
            this.Arguments = data.Arguments;
            this.exceptionData = data.ExceptionData;

            if (data.HasExpectedResult)
                this.ExpectedResult = data.ExpectedResult;

            foreach (string key in data.Properties.Keys)
                this.Properties[key] = data.Properties[key];
        }
Exemplo n.º 5
0
 public ParameterSet(ITestCaseData data)
 {
     TestName      = data.TestName;
     RunState      = data.RunState;
     Arguments     = data.Arguments;
     exceptionData = data.ExceptionData;
     if (data.HasExpectedResult)
     {
         ExpectedResult = data.ExpectedResult;
     }
     foreach (string key in data.Properties.Keys)
     {
         Properties[key] = data.Properties[key];
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Construct a ParameterSet from an object implementing ITestCaseData
        /// </summary>
        /// <param name="data"></param>
        public ParameterSet(ITestCaseData data)
        {
            this.TestName  = data.TestName;
            this.RunState  = data.RunState;
            this.Arguments = this.OriginalArguments = data.Arguments;
            if (data.HasExpectedResult)
            {
                ExpectedResult = data.ExpectedResult;
            }
            this.Properties = new PropertyBag();

            foreach (string key in data.Properties.Keys)
            {
                this.Properties[key] = data.Properties[key];
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        private IEnumerable <ITestCaseData> GetTestCasesFor(IMethodInfo method)
        {
            List <ITestCaseData> data = new List <ITestCaseData>();

            try
            {
                IEnumerable source = GetTestCaseSource(method);

                if (source != null)
                {
                    foreach (object item in source)
                    {
                        // First handle two easy cases:
                        // 1. Source is null. This is really an error but if we
                        //    throw an exception we simply get an invalid fixture
                        //    without good info as to what caused it. Passing a
                        //    single null argument will cause an error to be
                        //    reported at the test level, in most cases.
                        // 2. User provided an ITestCaseData and we just use it.
                        ITestCaseData parms = item == null
                            ? new TestCaseParameters(new object[] { null })
                            : item as ITestCaseData;

                        if (parms == null)
                        {
                            object[] args = null;

                            // 3. An array was passed, it may be an object[]
                            //    or possibly some other kind of array, which
                            //    TestCaseSource can accept.
                            var array = item as Array;
                            if (array != null)
                            {
                                // If array has the same number of elements as parameters
                                // and it does not fit exactly into single existing parameter
                                // we believe that this array contains arguments, not is a bare
                                // argument itself.
                                var parameters = method.GetParameters();
                                var argsNeeded = parameters.Length;
                                if (argsNeeded > 0 && argsNeeded == array.Length && parameters[0].ParameterType != array.GetType())
                                {
                                    args = new object[array.Length];
                                    for (var i = 0; i < array.Length; i++)
                                    {
                                        args[i] = array.GetValue(i);
                                    }
                                }
                            }

                            if (args == null)
                            {
                                args = new object[] { item };
                            }

                            parms = new TestCaseParameters(args);
                        }

                        if (this.Category != null)
                        {
                            foreach (string cat in this.Category.Split(new char[] { ',' }))
                            {
                                parms.Properties.Add(PropertyNames.Category, cat);
                            }
                        }

                        data.Add(parms);
                    }
                }
            }
            catch (Exception ex)
            {
                data.Clear();
                data.Add(new TestCaseParameters(ex));
            }

            return(data);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        private IEnumerable <ITestCaseData> GetTestCasesFor(IMethodInfo method)
        {
            List <ITestCaseData> data = new List <ITestCaseData>();

            try
            {
                IEnumerable source = GetTestCaseSource(method);

                if (source != null)
                {
                    foreach (object item in source)
                    {
                        // First handle two easy cases:
                        // 1. Source is null. This is really an error but if we
                        //    throw an exception we simply get an invalid fixture
                        //    without good info as to what caused it. Passing a
                        //    single null argument will cause an error to be
                        //    reported at the test level, in most cases.
                        // 2. User provided an ITestCaseData and we just use it.
                        ITestCaseData parms = item == null
                            ? new TestCaseParameters(new object[] { null })
                            : item as ITestCaseData;

                        if (parms == null)
                        {
                            // 3. An array was passed, it may be an object[]
                            //    or possibly some other kind of array, which
                            //    TestCaseSource can accept.
                            var args = item as object[];
                            if (args == null && item is Array)
                            {
                                Array array = item as Array;
#if NETCF
                                bool netcfOpenType = method.IsGenericMethodDefinition;
#else
                                bool netcfOpenType = false;
#endif
                                int numParameters = netcfOpenType ? array.Length : method.GetParameters().Length;
                                if (array != null && array.Rank == 1 && array.Length == numParameters)
                                {
                                    // Array is something like int[] - convert it to
                                    // an object[] for use as the argument array.
                                    args = new object[array.Length];
                                    for (int i = 0; i < array.Length; i++)
                                    {
                                        args[i] = array.GetValue(i);
                                    }
                                }
                            }

                            // Check again if we have an object[]
                            if (args != null)
                            {
#if NETCF
                                if (method.IsGenericMethodDefinition)
                                {
                                    var mi = method.MakeGenericMethodEx(args);
                                    if (mi == null)
                                    {
                                        throw new NotSupportedException("Cannot determine generic Type");
                                    }
                                    method = mi;
                                }
#endif

                                var parameters   = method.GetParameters();
                                var argsNeeded   = parameters.Length;
                                var argsProvided = args.Length;

                                // If only one argument is needed, our array may actually
                                // be the bare argument. If it is, we should wrap it in
                                // an outer object[] representing the list of arguments.
                                if (argsNeeded == 1)
                                {
                                    var singleParmType = parameters[0].ParameterType;

                                    if (argsProvided == 0 || typeof(object[]).IsAssignableFrom(singleParmType))
                                    {
                                        if (argsProvided > 1 || singleParmType.IsAssignableFrom(args.GetType()))
                                        {
                                            args = new object[] { item };
                                        }
                                    }
                                }
                            }
                            else // It may be a scalar or a multi-dimensioned array. Wrap it in object[]
                            {
                                args = new object[] { item };
                            }

                            parms = new TestCaseParameters(args);
                        }

                        if (this.Category != null)
                        {
                            foreach (string cat in this.Category.Split(new char[] { ',' }))
                            {
                                parms.Properties.Add(PropertyNames.Category, cat);
                            }
                        }

                        data.Add(parms);
                    }
                }
            }
            catch (Exception ex)
            {
                data.Clear();
                data.Add(new TestCaseParameters(ex));
            }

            return(data);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        public IEnumerable <ITestCaseData> GetTestCasesFor(MethodInfo method)
        {
            List <ITestCaseData> data = new List <ITestCaseData>();

            IEnumerable source = GetTestCaseSource(method);

            if (source != null)
            {
                ParameterInfo[] parameters = method.GetParameters();

                foreach (object item in source)
                {
                    ParameterSet  parms        = new ParameterSet();
                    ITestCaseData testCaseData = item as ITestCaseData;

                    if (testCaseData != null)
                    {
                        parms = new ParameterSet(testCaseData);
                    }
                    else if (item is object[])
                    {
                        object[] array = item as object[];
                        parms.Arguments = array.Length == parameters.Length
                            ? array
                            : new object[] { item };
                    }
                    //else if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(item.GetType()))
                    //{
                    //    parms.Arguments = new object[] { item };
                    //}
                    else if (item is Array)
                    {
                        Array array = item as Array;

                        if (array.Rank == 1 && array.Length == parameters.Length)
                        {
                            parms.Arguments = new object[array.Length];
                            for (int i = 0; i < array.Length; i++)
                            {
                                parms.Arguments[i] = (object)array.GetValue(i);
                            }
                        }
                        else
                        {
                            parms.Arguments = new object[] { item };
                        }
                    }
                    else
                    {
                        parms.Arguments = new object[] { item };
                    }

                    if (this.Category != null)
                    {
                        foreach (string cat in this.Category.Split(new char[] { ',' }))
                        {
                            parms.Properties.Add(PropertyNames.Category, cat);
                        }
                    }

                    data.Add(parms);
                }
            }

            return(data);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        public IEnumerable <ITestCaseData> GetTestCasesFor(MethodInfo method)
        {
            List <ITestCaseData> data   = new List <ITestCaseData>();
            IEnumerable          source = GetTestCaseSource(method);

            if (source != null)
            {
                try
                {
#if NETCF
                    ParameterInfo[] parameters = method.IsGenericMethodDefinition ? new ParameterInfo[0] : method.GetParameters();
#else
                    ParameterInfo[] parameters = method.GetParameters();
#endif

                    foreach (object item in source)
                    {
                        ParameterSet  parms;
                        ITestCaseData testCaseData = item as ITestCaseData;

                        if (testCaseData != null)
                        {
                            parms = new ParameterSet(testCaseData);
                        }
                        else
                        {
                            object[] args = item as object[];
                            if (args != null)
                            {
#if NETCF
                                if (method.IsGenericMethodDefinition)
                                {
                                    var mi = method.MakeGenericMethodEx(args);
                                    parameters = mi == null ? new ParameterInfo[0] : mi.GetParameters();
                                }
#endif
                                if (args.Length != parameters.Length)
                                {
                                    args = new object[] { item }
                                }
                                ;
                            }
                            // else if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(item.GetType()))
                            // {
                            //    args = new object[] { item };
                            // }
                            else if (item is Array)
                            {
                                Array array = item as Array;

#if NETCF
                                if (array.Rank == 1 && (method.IsGenericMethodDefinition || array.Length == parameters.Length))
#else
                                if (array.Rank == 1 && array.Length == parameters.Length)
#endif
                                {
                                    args = new object[array.Length];
                                    for (int i = 0; i < array.Length; i++)
                                    {
                                        args[i] = array.GetValue(i);
                                    }
#if NETCF
                                    if (method.IsGenericMethodDefinition)
                                    {
                                        var mi = method.MakeGenericMethodEx(args);

                                        if (mi == null || array.Length != mi.GetParameters().Length)
                                        {
                                            args = new object[] { item }
                                        }
                                        ;
                                    }
#endif
                                }
                                else
                                {
                                    args = new object[] { item };
                                }
                            }
                            else
                            {
                                args = new object[] { item };
                            }

                            parms = new ParameterSet(args);
                        }

                        if (this.Category != null)
                        {
                            foreach (string cat in this.Category.Split(new char[] { ',' }))
                            {
                                parms.Properties.Add(PropertyNames.Category, cat);
                            }
                        }

                        data.Add(parms);
                    }
                }
                catch (Exception ex)
                {
                    data.Clear();
                    data.Add(new ParameterSet(ex));
                }
            }

            return(data);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Construct a ParameterSet from an object implementing ITestCaseData
 /// </summary>
 /// <param name="data"></param>
 public TestCaseParameters(ITestCaseData data) : base(data)
 {
     if (data.HasExpectedResult)
         ExpectedResult = data.ExpectedResult;
 }