If I have the following domain object:
public class Customer
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual ISet<Order> Orders { get; set; }
public Customer()
{
Orders = new HashedSet<Order>();
}
public virtual void AddOrder(Order order)
{
order.Customer = this;
Orders.Add(order);
}
}
with the following NHibernate mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Examples" assembly="Examples">
<class name="Customer">
<id name="Id">
<generator class="guid.comb" />
</id>
<property name="Name" length="50"/>
<set name="Orders" table="CustomerOrder" cascade="all-delete-orphan" lazy="true">
<key column="CustomerId"/>
<many-to-many class="Order" column="OrderId"/>
</set>
</class>
</hibernate-mapping>
Is there any value in this test?
[Test]
public Save_NameWritten_SameNameIsReadback()
{
var expected = new Customer { Name = "Fred Quimby" };
_repo.Save(c);
var actual = _repo.Find(expected.Id);
Assert.AreEqual(expected.Name, actual.Name);
}
Do folks commonly test their persistence layer like this? Making sure that each field is persisted individually? I'm honestly not sure what best practice is for something like this. I can see testing something with long strings and parent/child relationships - but what about integers and dates? Is this overkill?
I'm just talking about the persistence layer here, not the business logic in the domain layer. For that, I would mock the repository, whereas here I'm verifying that the repository actually saved the thing that I told it to save. What if someone forgets to map a field, or they have a bogus string length in the mapping?
Are there any tools to automatically generate these kinds of tests in .NET? Or is that "bad"?