PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FluentNHibernate.Testing/Testing/Values/ReferenceListSpecs.cs

https://github.com/signoredems/fluent-nhibernate
C# | 48 lines | 41 code | 7 blank | 0 comment | 0 complexity | 6b078d5a0e1b69c3247ac2550cc715ad MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using FluentNHibernate.Testing.Values;
  5. using FluentNHibernate.Utils;
  6. using NHibernate;
  7. using NUnit.Framework;
  8. using Rhino.Mocks;
  9. namespace FluentNHibernate.Testing.Testing.Values
  10. {
  11. [TestFixture]
  12. public class When_a_reference_list_is_registered_on_the_persistence_specification : Specification
  13. {
  14. private ReferenceList<PropertyEntity, OtherEntity> sut;
  15. private PersistenceSpecification<PropertyEntity> specification;
  16. private ISession session;
  17. private List<OtherEntity> referencedEntities;
  18. public override void establish_context()
  19. {
  20. var property = ReflectionHelper.GetAccessor((Expression<Func<ReferenceEntity, object>>)(x => x.ReferenceList));
  21. referencedEntities = new List<OtherEntity> {new OtherEntity(), new OtherEntity()};
  22. session = MockRepository.GenerateStub<ISession>();
  23. session.Stub(x => x.BeginTransaction()).Return(MockRepository.GenerateStub<ITransaction>());
  24. specification = new PersistenceSpecification<PropertyEntity>(session);
  25. sut = new ReferenceList<PropertyEntity, OtherEntity>(property, referencedEntities);
  26. }
  27. public override void because()
  28. {
  29. sut.HasRegistered(specification);
  30. }
  31. [Test]
  32. public void should_save_the_referenced_list_items()
  33. {
  34. foreach (var reference in referencedEntities)
  35. {
  36. OtherEntity entity = reference;
  37. session.AssertWasCalled(x => x.Save(entity));
  38. }
  39. }
  40. }
  41. }