Hi Jeff.
Thanks for prompt reply (as usual).
One picture is worth a thousand words, so here it is:
using MbUnitTest = MbUnit.Framework.Test;
[EntityFrameworkTestFixture]
public abstract class BaseTestEntityFramework<TEntity, TTestEntities>
{
[StaticTestFactory]
public static IEnumerable<MbUnitTest> CreateStaticTests()
{
var testName = ...;
var testAction = ...
var test = new TestCase(testName, testAction);
test.SetUp = () =>
{
// How do I refer to the active test fixture instance in order to
invoke the TestInitialize
// method?
};
test.TearDown = () =>
{
// How do I refer to the active test fixture instance in order to
invoke the TestCleanup
// method?
};
}
[SetUp]
public void TestInitialize()
{
...
}
[TearDown]
public void TestCleanup()
{
...
}
}
Where EntityFrameworkTestFixtureAttribute is TestTypePatternAttribute
derived attribute which allows me to have an abstract generic base type
responsible for creating dynamic tests - related to the issue
http://code.google.com/p/mb-unit/issues/detail?id=525.
How do I implement the SetUp/TearDown delegates of the dynamic TestCase in
order to invoke the TestInitialize/TestCleanup methods on the active fixture
instance? Because by the time the dynamic TestCase is run there is an active
fixture instance of type TTestEntities (this is the second generic parameter
of the BaseTestEntityFramework class).
Thanks.
On Sun, Nov 1, 2009 at 10:19 AM, Jeff Brown <[email protected]> wrote:
> No, there's an instance of the fixture that contains the static test case
> factory, but probably not an instance of the other fixture that you're
> copying...
>
> Jeff.
>
> ------------------------------
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *Mark Kharitonov
> *Sent:* Saturday, October 31, 2009 3:17 PM
> *To:* [email protected]
> *Subject:* MbUnit Re: SetUp/TearDown rules.
>
> But by the time the dynamic TestCases are called the instance already
> exists!
> Creating it again, means there are two instances of the same fixture, which
> is not good for me.
>
> On 01/11/2009, at 00:03, Jeff Brown wrote:
>
>
> You need to create an instance of the fixture in order to call the
> SetUp and TearDown methods.
>
>
>
> On Oct 31, 2009, at 2:22 PM, Mark Kharitonov
> <[email protected]> wrote:
>
>
> I have found how to check within a SetUp/TearDown method whether the
> current test is a TestSuite, so this is not a problem.
>
> However, I have difficulty writing dedicated SetUp/TearDown methods
> for the dynamic TestCases. The problem is that the StaticTestFactory
> method is static, but the type declaring that method declares SetUp/
> TearDown methods as instance methods, in order to let the derived
> types override them, if necessary. The dynamically generated TestCases
> must have the same SetUp/TearDown logic as the regular statically
> compiled tests found in that type. But how can I refer to the
> statically compiled SetUp/TearDown instance methods from the SetUp/
> TearDown delegates of the dynamically generated TestCase?
> Thanks.
>
> On Oct 31, 10:41 pm, Mark Kharitonov <[email protected]>
> wrote:
>
> Hi.
> Given:
> 1. A StaticTestFactory method belonging to a type declaring SetUp and
> TearDown methods.
> 2. Dynamically created TestSuite with several TestCases using the
> aforementioned StaticTestFactory method. Neither the generated
> TestSuite neither the generated TestCases define their own SetUp or
> TearDown.
>
> When I run the tests, I notice that the type's SetUp method is called
> just once - before the first TestCase, the same is true for the
> TearDown method - it is invoked just once, after the last TestCase.
> Is it by design or is there some kind of a problem?
>
> Should I implement dedicated SetUp/TearDown per each generated
> TestCase?
>
> Can I know from the type's SetUp/TearDown method that it is being
> invoked for a dynamically generated TestSuite?
>
> Thanks.
>
>
>
>
>
> ==========================================================================
> There are two kinds of people. Those whose guns are loaded and those who
> dig.
> *(The good, the bad and the ugly).*
> So let us raise our cups for our guns always be loaded.
>
>
> >
>
--
Be well and prosper.
==============================
"There are two kinds of people.Those whose guns are loaded and those who
dig."
("The good, the bad and the ugly")
So let us drink for our guns always be loaded.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---