/// <summary> /// Construct one or more TestMethods from a given MethodInfo, /// using available parameter data. /// </summary> /// <param name="method">The MethodInfo for which tests are to be constructed.</param> /// <param name="suite">The suite to which the tests will be added.</param> /// <returns>One or more TestMethods</returns> public IEnumerable <TestMethod> BuildFrom(MethodInfo method, Test suite) { List <TestMethod> tests = new List <TestMethod>(); #if NETCF // TODO: Requires each data provider to have ability to probe a generic method. May require change to IParameterData interface. if (method.ContainsGenericParameters) { return(tests); } #endif ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 0) { IEnumerable[] sources = new IEnumerable[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { sources[i] = _dataProvider.GetDataFor(parameters[i]); } foreach (var parms in _strategy.GetTestCases(sources)) { tests.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)parms)); } } return(tests); }
/// <summary> /// Construct one or more TestMethods from a given MethodInfo, /// using available parameter data. /// </summary> /// <param name="method">The MethodInfo for which tests are to be constructed.</param> /// <param name="suite">The suite to which the tests will be added.</param> /// <returns>One or more TestMethods</returns> public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite) { List <TestMethod> tests = new List <TestMethod>(); IParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 0) { IEnumerable[] sources = new IEnumerable[parameters.Length]; try { for (int i = 0; i < parameters.Length; i++) { sources[i] = _dataProvider.GetDataFor(parameters[i]); } } catch (InvalidDataSourceException ex) { var parms = new TestCaseParameters(); parms.RunState = RunState.NotRunnable; parms.Properties.Set(PropertyNames.SkipReason, ex.Message); tests.Add(_builder.BuildTestMethod(method, suite, parms)); return(tests); } foreach (var parms in _strategy.GetTestCases(sources)) { tests.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)parms)); } } return(tests); }
private CombiningStrategy GetStrategy(MethodInfo method) { ParameterInfo[] parameters = method.GetParameters(); IEnumerable[] array = new IEnumerable[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { array[i] = dataPointProvider.GetDataFor(parameters[i]); } if (method.IsDefined(typeof(SequentialAttribute), inherit: false)) { return(new SequentialStrategy(array)); } if (method.IsDefined(typeof(PairwiseAttribute), inherit: false) && method.GetParameters().Length > 2) { return(new PairwiseStrategy(array)); } return(new CombinatorialStrategy(array)); }
/// <summary> /// Construct one or more TestMethods from a given MethodInfo, /// using available parameter data. /// </summary> /// <param name="method">The MethodInfo for which tests are to be constructed.</param> /// <param name="suite">The suite to which the tests will be added.</param> /// <returns>One or more TestMethods</returns> public IEnumerable <TestMethod> BuildFrom(MethodInfo method, Internal.Test suite) { ParameterInfo[] parameters = method.GetParameters(); List <TestMethod> tests = new List <TestMethod>(); if (parameters.Length > 0) { IEnumerable[] sources = new IEnumerable[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { sources[i] = _dataProvider.GetDataFor(parameters[i]); } foreach (var parms in new CombinatorialStrategy().GetTestCases(sources)) { tests.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)parms)); } } return(tests); }
/// <summary> /// Gets the strategy to be used in building test cases for this test. /// </summary> /// <param name="method">The method for which test cases are being built.</param> /// <returns></returns> private CombiningStrategy GetStrategy(MethodInfo method) { ParameterInfo[] parameters = method.GetParameters(); IEnumerable[] sources = new IEnumerable[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { sources[i] = dataPointProvider.GetDataFor(parameters[i]); } if (method.IsDefined(typeof(NUnit.Framework.SequentialAttribute), false)) { return(new SequentialStrategy(sources)); } if (method.IsDefined(typeof(NUnit.Framework.PairwiseAttribute), false) && method.GetParameters().Length > 2) { return(new PairwiseStrategy(sources)); } return(new CombinatorialStrategy(sources)); }
/// <summary> /// Construct one or more TestMethods from a given MethodInfo, /// using available parameter data. /// </summary> /// <param name="method">The MethodInfo for which tests are to be constructed.</param> /// <param name="suite">The suite to which the tests will be added.</param> /// <returns>One or more TestMethods</returns> public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite) { List <TestMethod> tests = new List <TestMethod>(); #if NETCF if (method.ContainsGenericParameters) { var genericParams = method.GetGenericArguments(); var numGenericParams = genericParams.Length; var o = new object(); var tryArgs = Enumerable.Repeat(o, numGenericParams).ToArray(); IMethodInfo mi; try { // This fails if the generic method has constraints // that are not met by object. mi = method.MakeGenericMethodEx(tryArgs); if (mi == null) { return(tests); } } catch { return(tests); } var par = mi.GetParameters(); if (par.Length == 0) { return(tests); } var sourceData = par.Select(p => _dataProvider.GetDataFor(p)).ToArray(); foreach (var parms in _strategy.GetTestCases(sourceData)) { mi = method.MakeGenericMethodEx(parms.Arguments); if (mi == null) { var tm = new TestMethod(method, suite); tm.RunState = RunState.NotRunnable; tm.Properties.Set(PropertyNames.SkipReason, "Incompatible arguments"); tests.Add(tm); } else { tests.Add(_builder.BuildTestMethod(mi, suite, (TestCaseParameters)parms)); } } return(tests); } #endif IParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 0) { IEnumerable[] sources = new IEnumerable[parameters.Length]; try { for (int i = 0; i < parameters.Length; i++) { sources[i] = _dataProvider.GetDataFor(parameters[i]); } } catch (InvalidDataSourceException ex) { var parms = new TestCaseParameters(); parms.RunState = RunState.NotRunnable; parms.Properties.Set(PropertyNames.SkipReason, ex.Message); tests.Add(_builder.BuildTestMethod(method, suite, parms)); return(tests); } foreach (var parms in _strategy.GetTestCases(sources)) { tests.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)parms)); } } return(tests); }
/// <summary> /// Construct one or more TestMethods from a given MethodInfo, /// using available parameter data. /// </summary> /// <param name="method">The MethodInfo for which tests are to be constructed.</param> /// <param name="suite">The suite to which the tests will be added.</param> /// <returns>One or more TestMethods</returns> public IEnumerable <TestMethod> BuildFrom(MethodInfo method, Test suite) { List <TestMethod> tests = new List <TestMethod>(); #if NETCF if (method.ContainsGenericParameters) { var genericParams = method.GetGenericArguments(); var numGenericParams = genericParams.Length; var o = new object(); var tryArgs = Enumerable.Repeat(o, numGenericParams).ToArray(); var mi = method.MakeGenericMethodEx(tryArgs); if (mi == null) { return(tests); } var par = mi.GetParameters(); if (par.Length == 0) { return(tests); } var sourceData = par.Select(p => _dataProvider.GetDataFor(p)).ToArray(); foreach (var parms in _strategy.GetTestCases(sourceData)) { mi = method.MakeGenericMethodEx(parms.Arguments); if (mi == null) { var tm = new TestMethod(method, suite); tm.RunState = RunState.NotRunnable; tm.Properties.Set(PropertyNames.SkipReason, "Incompatible arguments"); tests.Add(tm); } else { tests.Add(_builder.BuildTestMethod(mi, suite, (ParameterSet)parms)); } } return(tests); } #endif ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 0) { IEnumerable[] sources = new IEnumerable[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { sources[i] = _dataProvider.GetDataFor(parameters[i]); } foreach (var parms in _strategy.GetTestCases(sources)) { tests.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)parms)); } } return(tests); }