public ListScenario(ISessionFactory factory) { this.factory = factory; using (ISession s = factory.OpenSession()) { using (ITransaction t = s.BeginTransaction()) { var entity = new Base(); var child = new Child(); // null members are partially working for lists, can't have one at the end // and can't use the Count property. entity.Children = new List<Child> {null, child}; s.Save(entity); t.Commit(); } } }
public void Map_NullChild() { using (new MapScenario(Sfi)) { using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { var entity = s.CreateQuery("from Base").UniqueResult<Base>(); // null collection members don't seem to work, at least for lazy="extra" collections entity.NamedChildren.Count.Should().Not.Be.EqualTo(0); //entity.NamedChildren.Count.Should().Be.EqualTo(2); NHibernateUtil.IsInitialized(entity.NamedChildren).Should().Be.False(); // null valued child shouldn't cause errors var sigil = new Child(); Child child = sigil; Assert.DoesNotThrow(() => { child = entity.NamedChildren["NullChild"]; }); child.Should().Not.Be.EqualTo(sigil); child.Should().Be.Null(); } } } }
public void List_NullChild() { using (new ListScenario(Sfi)) { using (ISession s = OpenSession()) { using (ITransaction t = s.BeginTransaction()) { // the list should only contain an item at index 0 // accessing an invalid index should throw an exception var entity = s.CreateQuery("from Base").UniqueResult<Base>(); // null collection members don't seem to work, at least for lazy="extra" collections entity.Children.Count.Should().Not.Be.EqualTo(0); //entity.Children.Count.Should().Be.EqualTo(2); NHibernateUtil.IsInitialized(entity.Children).Should().Be.False(); var sigil = new Child(); Child child = sigil; Executing.This(() => { child = entity.Children[0]; }).Should().NotThrow(); child.Should().Not.Be.EqualTo(sigil); child.Should().Be.Null(); } } } }