public override void Reflect(RunInvokerTree tree, RunInvokerVertex parent, Type t) { foreach (MethodInfo method in TypeHelper.GetAttributedMethods(t, typeof(RepeatTestAttribute))) { try { foreach (RepeatTestAttribute rep in method.GetCustomAttributes(typeof(RepeatTestAttribute), true)) { for (int i = 0; i < rep.Count; i++) { // Get invoker IRunInvoker invoker = new RepeatMethodRunInvoker(this, method, i + 1); // Decorate invoker invoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker); // Add to tree tree.AddChild(parent, invoker); } } } catch (Exception ex) { MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method); tree.AddChild(parent, invoker); } } }
protected IRunInvoker InstanceInvoker(MethodInfo mi) { Object[] args = new Object[2]; args[0] = this; args[1] = mi; IRunInvoker invoker = (IRunInvoker)this.invokerConstructor.Invoke(args); return(DecoratorPatternAttribute.DecoreInvoker(mi, invoker)); }
public override void Reflect(RunInvokerTree tree, RunInvokerVertex parent, Type t) { MethodInfo method = t.GetMethod(this.methodName, Type.EmptyTypes); if (method == null) { return; } MethodRunInvoker invoker = new MethodRunInvoker(this, method); IRunInvoker decoratedInvoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker); tree.AddChild(parent, decoratedInvoker); }
public void Reflect(RunInvokerTree tree, RunInvokerVertex parent, Type t) { // add tests methods foreach (MethodInfo mi in TypeHelper.GetAttributedMethods( this.testerType, this.targetAttributeType) ) { CustomRunInvoker cr = new CustomRunInvoker( this, InstanceTester(), mi, this.feedSender ); // adding decoration and to tree tree.AddChild(parent, DecoratorPatternAttribute.DecoreInvoker(mi, cr) ); } }
public override void Reflect( RunInvokerTree tree, RunInvokerVertex parent, Type t) { foreach (MethodInfo method in t.GetMethods()) { if (method.IsSpecialName) { continue; } if (!method.Name.EndsWith(this.methodNameSuffix)) { continue; } MethodRunInvoker invoker = new MethodRunInvoker(this, method); IRunInvoker decoratedInvoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker); tree.AddChild(parent, decoratedInvoker); } }
/// <summary> /// Initializes a new <see cref="TestCase"/> instance /// with <paramref name="name"/>, <paramref name="testDelegate">delegate</paramref> and /// <paramref name="parameters"/> if applicable. /// </summary> /// <param name="name">Name of the test case</param> /// <param name="testDelegate">Delegate called by the test case</param> /// <param name="parameters">Parameters of the delegate</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="name"/> or <paramref name="testDelegate"/> is null /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="name"/> is the empty string. /// </exception> public TestCase(string name, Delegate testDelegate, params Object[] parameters) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("name is empty"); } if (testDelegate == null) { throw new ArgumentNullException("testDelegate"); } this.name = name; this.testDelegate = testDelegate; this.parameters = parameters; DelegateRunInvoker delegateInvoker = new DelegateRunInvoker(new TestCaseRun(), testDelegate, parameters); this.invoker = DecoratorPatternAttribute.DecoreInvoker(testDelegate.Method, delegateInvoker); }
public void Reflect(RunInvokerTree tree, RunInvokerVertex parent, Type t) { // getting methods ICollection mis = TypeHelper.GetAttributedMethods( t, typeof(ForEachTestAttribute) ); // first get the DataProviderFixtureDecorator... foreach (DataProviderFixtureDecoratorAttribute dp in t.GetCustomAttributes(typeof(DataProviderFixtureDecoratorAttribute), true)) { // for each node foreach (XmlNode node in dp.GetData()) { // for each test method foreach (MethodInfo mi in mis) { // get attribute ForEachTestAttribute fe = (ForEachTestAttribute)TypeHelper.GetFirstCustomAttribute( mi, typeof(ForEachTestAttribute)); // select nodes foreach (XmlNode childNode in node.SelectNodes(fe.XPath)) { // create invokers IRunInvoker invoker = new ForEachTestRunInvoker(this, mi, fe, childNode); //decorage invoker = DecoratorPatternAttribute.DecoreInvoker(mi, invoker); // add invoker tree.AddChild(parent, invoker); } } } } }
public override void Reflect( RunInvokerTree tree, RunInvokerVertex parent, Type t) { foreach (MethodInfo method in TypeHelper.GetAttributedMethods(t, typeof(RowTestAttribute))) { try { foreach (RowAttribute row in method.GetCustomAttributes(typeof(RowAttribute), true)) { // get invoker IRunInvoker invoker = new RowMethodRunInvoker( this, method, row ); if (row.ExpectedException != null) { invoker = new ExpectedExceptionRunInvoker( invoker, row.ExpectedException, row.Description ); } // decore invoker invoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker); tree.AddChild(parent, invoker); } } catch (Exception ex) { MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method); tree.AddChild(parent, invoker); } } }
protected IRunInvoker InstanceCriticalStepInvoker(MethodInfo mi) { IRunInvoker invoker = new MethodRunInvoker(this, mi); return(DecoratorPatternAttribute.DecoreInvoker(mi, invoker)); }
private IRunInvoker InstanceInvoker(MethodInfo mi) { IRunInvoker invoker = new MethodRunInvoker(this, mi); return(DecoratorPatternAttribute.DecoreInvoker(mi, invoker)); }
private void ReflectTestMethod( RunInvokerTree tree, RunInvokerVertex parent, object fixture, MethodInfo method, IgnoreAttribute ignore, ExplicitAttribute expl) { // Check if fixture/method is ignored/explicit if (ignore == null && TypeHelper.HasCustomAttribute(method, typeof(IgnoreAttribute))) { ignore = TypeHelper.GetFirstCustomAttribute(method, typeof(IgnoreAttribute)) as IgnoreAttribute; } if (expl == null && TypeHelper.HasCustomAttribute(method, typeof(ExplicitAttribute))) { expl = TypeHelper.GetFirstCustomAttribute(method, typeof(ExplicitAttribute)) as ExplicitAttribute; } if (ignore != null) { // Do not generate unnecessary test cases IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, ignore.Description); tree.AddChild(parent, invoker); } else if (expl != null) { // Do not generate unnecessary test cases IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, expl.Description); tree.AddChild(parent, invoker); } else { CombinatorialTestAttribute testAttribute = TypeHelper.GetFirstCustomAttribute(method, typeof(CombinatorialTestAttribute)) as CombinatorialTestAttribute; ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == 0) { Exception ex = new Exception("No parameters"); MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method); tree.AddChild(parent, invoker); return; } // 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) { Exception pex = new Exception("Failed while loading domains from parameter " + parameter.Name, ex); MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, pex, method); tree.AddChild(parent, invoker); } } if (pdomains.Count == 0) { Exception ex = new Exception("Could not find domain for argument " + parameter.Name); MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method); tree.AddChild(parent, invoker); return; } domains.Add(Domains.ToDomain(pdomains)); index++; } // get the validator method if any MethodInfo validator = null; if (testAttribute.TupleValidatorMethod != null) { validator = fixture.GetType().GetMethod(testAttribute.TupleValidatorMethod, parameterTypes); if (validator == null) { Exception ex = new Exception("Could not find validator method " + testAttribute.TupleValidatorMethod); MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method); tree.AddChild(parent, invoker); return; } } // 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 testAttribute.GetProduct(tdomains)) { if (validator != null) { bool isValid = (bool)validator.Invoke(fixture, ptuple.ToObjectArray()); if (!isValid) { continue; } } TupleRunInvoker invoker = new TupleRunInvoker(this, method, tuple, ptuple); IRunInvoker dinvoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker); tree.AddChild(parent, dinvoker); } } } }