public ExpectedExceptionTestCase AddThrow(int parameterIndex, Object value, Type exceptionType) { // copy parameters Object[] ps = new Object[this.parameters.Length]; this.parameters.CopyTo(ps, 0); ps[parameterIndex] = value; string pname = this.parameterInfos[parameterIndex].Name; pname = Char.ToUpper(pname[0]) + pname.Substring(1, pname.Length - 1); // create new name string caseName = String.Format("{0}With{1}NulledShouldThrow{2}", this.method.Name, pname, exceptionType.Name ); // create type // create case MethodTestCase tc = MbUnit.Framework.TestCases.Case(caseName, testedInstance, method, ps); ExpectedExceptionTestCase etc = MbUnit.Framework.TestCases.ExpectedException(tc, exceptionType); this.Suite.Add(etc); return(etc); }
public static MethodTestCase Case(string name, Object testedInstance, MethodInfo test, params Object[] parameters) { if (name == null) throw new ArgumentNullException("name"); if (name.Length == 0) throw new ArgumentException("name is empty"); if (test == null) throw new ArgumentNullException("test"); if (testedInstance==null) throw new ArgumentNullException("testedInstance"); MethodTestCase tc = new MethodTestCase(name, testedInstance, test, parameters); return tc; }
//public override void GetDomains(IDomainCollection domains, ParameterInfo parameter, object fixture) //{ // domains.Add(domain); //} public override ITestCase[] CreateTests(ITestFixture fixture, System.Reflection.MethodInfo method) { ITestCase[] tc = new ITestCase[this._intStepCount]; for (int intCount = this._intStepCount; intCount < this._intStepCount; intCount++) { Object[] obj = new Object[0]; obj[0] = intCount; MethodTestCase mtc = new MethodTestCase(fixture.Name, method, obj); tc[intCount] = mtc; } return tc; //return new ITestCase[] { new MethodTestCase(fixture.Name, method, this.args) }; }
/// <summary> /// Wraps a <see cref="MethodInfo">method</see> in a <see cref="MethodTestCase"/> class /// </summary> /// <param name="name">The name of the method.</param> /// <param name="testedInstance">The instance of the object to call the method on.</param> /// <param name="test">a <see cref="MethodInfo"/> object identifying the test method.</param> /// <param name="parameters">The parameters to pass to the method when run</param> /// <returns>A <see cref="MethodTestCase"/> object</returns> /// <exception cref="ArgumentNullException">Thrown if either /// <paramref name="name"/>, <paramref name="test"/> or <paramref name="testedInstance"/> is null</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is an empty string</exception> public static MethodTestCase Case(string name, Object testedInstance, MethodInfo test, params Object[] parameters) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("name is empty"); } if (test == null) { throw new ArgumentNullException("test"); } if (testedInstance == null) { throw new ArgumentNullException("testedInstance"); } MethodTestCase tc = new MethodTestCase(name, testedInstance, test, parameters); return(tc); }
public ExpectedExceptionTestCase AddThrow(int parameterIndex, Object value, Type exceptionType) { // copy parameters Object[] ps = new Object[this.parameters.Length]; this.parameters.CopyTo(ps, 0); ps[parameterIndex] = value; // create new name string caseName = String.Format("{0}{1}ModifiedShouldThrow{2}", this.name, this.parameterInfos[parameterIndex].Name, exceptionType.Name ); // create case MethodTestCase tc = MbUnit.Framework.TestCases.Case(caseName, method, ps); ExpectedExceptionTestCase etc = MbUnit.Framework.TestCases.ExpectedException(tc, exceptionType); this.testCases.Add(etc.Name, etc); return(etc); }
public override ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method) { ArrayList testList = new ArrayList(); ParameterInfo[] parameters = method.GetParameters(); // create the models DomainCollection domains = new DomainCollection(); Type[] parameterTypes = new Type[parameters.Length]; int index = 0; foreach (ParameterInfo parameter in parameters) { parameterTypes[index] = parameter.ParameterType; DomainCollection pdomains = new DomainCollection(); foreach (UsingBaseAttribute usingAttribute in parameter.GetCustomAttributes(typeof(UsingBaseAttribute), true)) { try { usingAttribute.GetDomains(pdomains, parameter, fixture); } catch (Exception ex) { throw new Exception("Failed while loading domains from parameter " + parameter.Name, ex); } } if (pdomains.Count == 0) { throw new Exception("Could not find domain for argument " + parameter.Name); } domains.Add(Domains.ToDomain(pdomains)); index++; } // we make a cartesian product of all those foreach (ITuple tuple in Products.Cartesian(domains)) { // create data domains DomainCollection tdomains = new DomainCollection(); for (int i = 0; i < tuple.Count; ++i) { IDomain dm = (IDomain)tuple[i]; tdomains.Add(dm); } // computing the pairwize product foreach (ITuple ptuple in GetProduct(tdomains)) { ITestCase test = new MethodTestCase(fixture.Name, method, ptuple.ToObjectArray()); testList.Add(test); } } return (ITestCase[])testList.ToArray(typeof(ITestCase)); }