Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to use PersistenceSpecification and CheckList for unit testing an Inverse HasMany relationship?
    primarykey
    data
    text
    <p>This is actually my very first question on Stackoverflow. I hope its not the last and hopefully I will contribute with some answers myself.</p> <p>My question is simple. I'm stuck with a NUnit test where I'm testing a inversed HasMany relationship. Everytime I debug it, the output is "Actual count does not equal expected count...". I've done some extensive research on the net about this issue and some people claim that it's impossible to do such a unittest. </p> <p>Here is my example. Code for EmployeeMapping:</p> <pre><code> Id(x =&gt; x.ID).GeneratedBy.Identity(); HasMany(x =&gt; x.PositionHistory).KeyColumn("Employee_id").Inverse().Cascade.All(); </code></pre> <p>Here is code for EmployeePositionMapping:</p> <pre><code> Id(x =&gt; x.ID).GeneratedBy.Identity(); References(x =&gt; x.EmployeeAtPosition).Cascade.All().Nullable(); </code></pre> <p>The Unit test is like this:</p> <pre><code> var position2 = new EmployeePosition(); position2.ExtraBenefit = 353.00; position2.Salary = 23300.00; position2.Region = region; position2.Department = department; position2.Year = "2010"; position2.Comment = "kommentar igen..."; position2.History = true; var positionList = new List&lt;EmployeePosition&gt;(); positionList.Add(position2); new PersistenceSpecification&lt;Employee&gt;(Session, new CustomEqualityComparer&lt;Employee, long&gt;()) .CheckProperty(p =&gt; p.ID, Int64.Parse("1")) .CheckList(p =&gt; p.PositionHistory, positionList, (emp, empPosition) =&gt; emp.AddEmployeePosition(empPosition)) .VerifyTheMappings(); </code></pre> <p>I would like to replace the Nullable() attribute to Not.Nullable() for References EmployeeAtPosition property.</p> <p>I have a Entity base class that take cares of comparing entities and even Transients. The AddEmployeePosition() takes care of maintaining the relationship both ways for Employee.PositionHistory and EmployeePosition.EmployeeAtPosition.</p> <p>When I look at the Nhibernate SQL in output It seems ok. But for some reason it's not equal the list I've prepared (positionList)</p> <p>Other useful facts: I'm running Nhibernate 3.0 and the matching fluent Nhibernate binaries. Downloded them for three days ago. Using SQLite InMemory for conducting Mapping Tests.</p> <p>I really appreciate all good new angles that your hints may give me... </p> <p>/Best Regards BacceSR- from a very snowy Stockholm.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload