Yes the latter using a static factory method.

Is it not working?

Jeff.

On Fri, Jan 23, 2009 at 9:26 AM, max2256 <[email protected]> wrote:

>
> Sorry again, is this what you mean?
>
> public class Fixture
> {
>   private  Person person;
>
>   public Fixture( [Factory("CreatePersons")] Person p)
>   {
>      person = p;
>   }
>
>   public static IEnumerable<Person> CreatePersons()
>    {
>       yield return new Person("Mike");
>       yield return new Person("Jim");
>   }
>
>   [Test]
>    public void Test1()
>   {
>        // do something with person
>   }
>
>   [Test]
>   public void Test2()
>   {
>        // do something with person
>    }
>
> }
>
>
> On Jan 23, 11:42 am, max2256 <[email protected]> wrote:
> > Ok, this is exactly what I need to do, but not sure on how to
> > implement this.
> >
> > eg:
> >
> > public class Fixture
> > {
> >
> >    [Factory("CreatePersons")]
> >    public Fixture(Person p)
> >    {
> >       // how do I add the steps to the fixture
> >       // how do I pass the Person p parameter to Test1 and Test2
> >    }
> >
> >    public IEnumerable<Person> CreatePersons()
> >    {
> >        yield return new Person("Mike");
> >        yield return new Person("Jim");
> >    }
> >
> >    [Test]
> >    public void Test1(Person p)
> >    {
> >         // do something with p
> >    }
> >
> >    [Test]
> >    public void Test2(Person p)
> >    {
> >         // do something with p
> >    }
> >
> > }
> >
> > Thanx
> >
> > On Jan 22, 8:27 pm, Jeff Brown <[email protected]> wrote:
> >
> > > If you put the factory on the constructor then the tests will appear as
> if
> > > the fixture was parameterized.
> >
> > > Like this:
> >
> > > Fixture({Mike})
> > >  - Test1
> > >  - Test2
> > > Fixture({Jim})
> > >  - Test1
> > >  - Test2
> >
> > > The presentation above with {Mike} and {Jim} assumes that Person has an
> > > overridden ToString that returns the name of the Person.  If ToString
> hasn't
> > > been overridden then you will probably see (at least in the current
> trunk
> > > versions) a description of the properties that make up the person.
> >
> > > eg. Fixture({Person: Name="Jim"})
> >
> > > On Thu, Jan 22, 2009 at 10:24 AM, max2256 <[email protected]> wrote:
> >
> > > >  Hi,
> >
> > > >    Sorry if you have to repeat yourself, but what would happen if you
> > > > put
> > > >    the factory attribute on the constructor???
> >
> > > >    Would the ouptut on the runner (Icarus) look like this?
> >
> > > >    -Person("Mike")
> > > >      -- Test1
> > > >      -- Test2
> > > >    -Person("Jim")
> > > >      -- Test1
> > > >      -- Test2
> >
> > > > Thanx
> >
> > > > On Jan 21, 3:50 pm, Jeff Brown <[email protected]> wrote:
> > > > > There are several options here.  Here are two of them:
> >
> > > > > 1. Put the row or factory attribute on the constructor.
> >
> > > > > 2. Put the attributes instead on one or more writable properties or
> > > > fields of the class.
> >
> > > > > (Fields, properties, constructor parameters and generic type
> parameters
> > > > can also be bound positionally or by name using a data source
>  attribute on
> > > > the class level.  This is useful if you want to use multiple columns
> of
> > > > values from the same source.)
> >
> > > > > However it is not possible to parameterize setup.  I think you'll
> find
> > > > the alternatives more than compensate.
> >
> > > > > Jeff.
> >
> > > > > -----Original Message-----
> > > > > From: "[email protected]" <[email protected]>
> > > > > Date: Wednesday, Jan 21, 2009 12:28 pm
> > > > > Subject: MbUnit Re: mixture of TestSuite and DataDriven testing
> > > > > To: "MbUnit.User" <[email protected]>Reply-To:
> > > > [email protected]
> >
> > > > > Hi,
> >
> > > > > Suppose I want to do a similar thing AAA style. Namely, I have
> several
> > > > > persons created by the CreatePersons method, and for each person, I
> > > > > want to run the Setup method (with a Person argument) and several
> > > > > tests. So, the questions are:
> > > > > - Can we run a parametrized [Setup] the same way as [Test]?
> > > > > - Can we have it class-wide, i.e., put [Factory("CreatePersons")]
> at
> > > > > the class level?
> >
> > > > > Same question regarding the Row-style testing: can I apply the Row
> > > > > attribute at the class level, and have all my Setup and Test
> methods
> > > > > parametrized the same way, parameters taken from the class level
> > > > > attribute?
> >
> > > > > Thanks
> >
> > > > > ulu
> >
> > > > > On Jan 21, 12:46 am, 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
> > > > > > >     }- 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