fluent-nhibernate /src/FluentNHibernate.Testing/Testing/Values/ReferenceListSpecs.cs

Language C# Lines 47
MD5 Hash b09c943e977b7332f6ec2baf0a72d5bf
Repository https://github.com/dotnetchris/fluent-nhibernate.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FluentNHibernate.Testing.Values;
using FluentNHibernate.Utils;
using NHibernate;
using NUnit.Framework;
using Rhino.Mocks;

namespace FluentNHibernate.Testing.Testing.Values
{
    public class When_a_reference_list_is_registered_on_the_persistence_specification : Specification
    {
        private ReferenceList<PropertyEntity, OtherEntity> sut;
        private PersistenceSpecification<PropertyEntity> specification;
        private ISession session;
        private List<OtherEntity> referencedEntities;

        public override void establish_context()
        {
            var property = ReflectionHelper.GetProperty((Expression<Func<ReferenceEntity, object>>)(x => x.ReferenceList));

            referencedEntities = new List<OtherEntity> {new OtherEntity(), new OtherEntity()};

            session = MockRepository.GenerateStub<ISession>();
            session.Stub(x => x.BeginTransaction()).Return(MockRepository.GenerateStub<ITransaction>());
            specification = new PersistenceSpecification<PropertyEntity>(session);

            sut = new ReferenceList<PropertyEntity, OtherEntity>(property, referencedEntities);
        }

        public override void because()
        {
            sut.HasRegistered(specification);
        }

        [Test]
        public void should_save_the_referenced_list_items()
        {
            foreach (var reference in referencedEntities)
            {
                OtherEntity entity = reference;
                session.AssertWasCalled(x => x.Save(entity));
            }
        }
    }
}
Back to Top