You can do this if you use an anonymous delegate or lambda:

yield return new TestCase("Test1", () => Test1(p));

Jeff.

On Wed, Jan 21, 2009 at 9:38 AM, max2256 <[email protected]> wrote:

>
> Thanx for the fast reply!
> Concerning the combination of data sources with suites, I was
> wondering if it was possible to call a method and pass a parameter
> like the following:
>
> [DynamicTestFactory]
> [Factory("CreatePersons")]
> public IEnumerable<Test> Suite(Person p)
> {
>     yield return new TestCase("Test1", Test1(p));
>
> }
>
> public void Test1(Person p)
> {
>    // do something with p
> }
>
> Max
>
>
> On Jan 20, 4:46 pm, Jeff Brown <[email protected]> wrote:
> > It looks like you're trying to produce a list of Person objects to pass
> to
> > the tests.
> > Try this:
> >
> > public class TestFixture
> > {
> >    public IEnumerable<Person> CreatePersons()
> >    {
> >        yield return new Person("Mike");
> >        yield return new Person("Jim");
> >    }
> >
> >    [Test]
> >    [Factory("CreatePersons")]
> >    public void Test1(Person p)
> >    {
> >         Assert.AreEqual("Max", p.Name);
> >    }
> >
> >    [Test]
> >    [Factory("CreatePersons")]
> >    public void Test2(Person p)
> >    {
> >         Assert.AreEqual("Max", p.Name);
> >    }
> >
> > }
> >
> > Here the output will look like:
> >
> > - Test1({Mike})
> > - Test1({Jim})
> > - Test2({Mike})
> > - Test2({Jim})
> >
> > It should also be possible to combine data sources with suites like this.
>  I
> > haven't tried it yet...
> >
> > [DynamicTestFactory]
> > [Factory("CreatePersons")]
> > public IEnumerable<Test> Suite(Person p)
> > {
> >     yield return new TestCase("Test1", () => {
> >        // do something with p.
> >     });
> >
> > }
> >
> > Jeff.
> >
> >
> >
> > On Tue, Jan 20, 2009 at 12:52 PM, max2256 <[email protected]> wrote:
> >
> > > Hi,
> >
> > > I'm new to MbUnit. I would like to know if there is a way of doing the
> > > following with MbUnit V3 or any MbUnit version. (mixture of TestSuite
> > > and DataDriven testing) :
> >
> > > [TestFixture]
> > > public class TestFixture
> > >  {
> > >     [Row(typeof(Person), new Person("Max"))]
> > >     [Row(typeof(Person), new Person("Mike"))]
> > >     [Row(typeof(Person), new Person("Frank"))]
> > >     [TestSuite]
> > >     public TestSuite GetSuite(Person p)
> > >     {
> > >          // add tests to TestSuite
> > >     }
> >
> > >    [Test]
> > >    public void Test1(Person p)
> > >    {
> > >         Assert.AreEqual("Max", p.Name);
> > >    }
> >
> > >    [Test]
> > >    public void Test2(Person p)
> > >    {
> > >       Assert.AreEqual("Frank", p.Name);
> > >    }
> > > }
> >
> > > The report generated would look like this:
> >
> > > -Person("Max")
> > >      -- Test1
> > >      -- Test2
> > > -Person("Mike")
> > >      -- Test1
> > >      -- Test2
> > > -Person("Frank")
> > >      -- Test1
> > >      -- Test2
> >
> > > Any suggestions?
> >
> > > Thanx!- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to