Monday, 15 September 2014

Fluent NHibernate - unit-testing a one-to-many *inverse* mapping -


I do not understand how Fluent NHibernate PersistenceSpecification & lt; To use T & gt (or if this is possible);

One-to-many mapping

method to check a inversion (...) method . Trying to:

Using a fluent Neighbnernet on the example of a vanilla blog / post, I have blogs from one to several blogs & lt; -> Post Mapping is defined. I want one restriction that a post should always be consistent with the blog, from exactly the same time it is added to the database. (Basically, the blog id column in the postal table is not zero).

For this reason, I defined mapping as:

  Public class blogmap: classplapse  

In the blog class, there is a AddPosts (IELIT & Lt; Post & gt; Position) method that takes care of both sides of the mapping, so when the post Insert instances

So far, it's great.

While using the problem

  new compulsion exclusivity & lt; Blog & gt; (GetSession (), eq). Checklist (C => c.Posts, new [] {new post} {name = "post1"}, new post {name = "post2"}}). Verify mailing (); In the mapping unit-test, I get this exception:  

"System. Exception: Actual calculation is not equal to expected count"

... which is expected, Since the blog id values ​​of the posts are not set anywhere, I am thinking that in some way I can get behind the scenes by blog for example strongly clarity Checking I can call the AddBlogs (...) method manually Is.

If I delete . The mapping () and (to remove the obstacles to tap the databases for blog ID column) exams are passed.

Any thoughts?

I know that it has already been sorted on the mailing list but we are also on stack overflow Can answer.

Intolerance is a checklist method in the display class. Here's an example used:

  _spec.CheckList (x => x.EnumerableOfKittens, kittens, (cat , Kitten) => cat.AddKitten (Kitten));  

This method was only recently added if you have not received it, so get the latest FNH trunk.


No comments:

Post a Comment