PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/dotnetchris/fluent-nhibernate
C# | 47 lines | 40 code | 7 blank | 0 comment | 0 complexity | b09c943e977b7332f6ec2baf0a72d5bf 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. public class When_a_reference_list_is_registered_on_the_persistence_specification : Specification
  12. {
  13. private ReferenceList<PropertyEntity, OtherEntity> sut;
  14. private PersistenceSpecification<PropertyEntity> specification;
  15. private ISession session;
  16. private List<OtherEntity> referencedEntities;
  17. public override void establish_context()
  18. {
  19. var property = ReflectionHelper.GetProperty((Expression<Func<ReferenceEntity, object>>)(x => x.ReferenceList));
  20. referencedEntities = new List<OtherEntity> {new OtherEntity(), new OtherEntity()};
  21. session = MockRepository.GenerateStub<ISession>();
  22. session.Stub(x => x.BeginTransaction()).Return(MockRepository.GenerateStub<ITransaction>());
  23. specification = new PersistenceSpecification<PropertyEntity>(session);
  24. sut = new ReferenceList<PropertyEntity, OtherEntity>(property, referencedEntities);
  25. }
  26. public override void because()
  27. {
  28. sut.HasRegistered(specification);
  29. }
  30. [Test]
  31. public void should_save_the_referenced_list_items()
  32. {
  33. foreach (var reference in referencedEntities)
  34. {
  35. OtherEntity entity = reference;
  36. session.AssertWasCalled(x => x.Save(entity));
  37. }
  38. }
  39. }
  40. }