Miika
I usually have a Country persistent entity (with mapping etc).
For unit tests that need it, I use an ObjectMother to create some
samples
[Test]
public void Foreign_Customers_Dont_Get_VAT()
{
ObjectMother.CreateEnglandAndNorway();
var owner = new Company("My Company");
owner.Country = DAO<Country>.GetByISO639("gb")
var c = new Company("Some Customer");
c.Country = DAO<Country>.GetByISO639("no")
}
CreateEnglandAndNorway() is just some code....
public void CreateEnglandAndNorway()
{
UnitOfWork.BeginTransaction();
var no = new Country("Norway", "no");
var gb = new Country("United Kingdom", "gb");
DAO<Country>.Save(no);
DAO<Country>.Save(gb);
UnitOfWork.CommitTransaction();
}
It doesn't look like you're using tests, so you just want to have the
application start up fully loaded with reference data?
I have this need too, usually because I want a nice demo version of
the application created from scratch at the click of a button.
For this I often use a [Test] as my build task, but this could easily
be handled by a custom NAnt task or some other build script (anyone
got a suggestion for easy code-centric build tasks, btw?)
[Test, Explicit]
public void CreateDemoApplication()
{
DoSchemaExport();
ObjectMother.SetupAllCountries();
ObjectMother.SetupSampleCompanies();
ObjectMother.SetupSampleProducts();
}
The ObjectMother.SetupAllCountries() could just be a load of hard-
coded stuff. But, it's often better to have the object mother import
the data from an external source such as an Excel sheet, a CSV file,
other database, web page etc. This means that reference data can be
supplied and maintained by clients, which is handy. Obviously clients
supply bad data from time to time, so your domain logic should barf if
you try to import and persist bad data that's been supplied to you!
As an aside, I've never needed to cache this kind of immutable
reference data. But, I imagine that it's a great candidate?
Tobin
On Sep 16, 9:41 am, "Miika Makinen" <[EMAIL PROTECTED]> wrote:
> Hi guys,
> What do you do with default data like languages, countries etc when using
> schema export to create the db? Import from somewhere? SQL scripts? C# code
> to insert using NH?
>
> Cheers,
> Miika
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---