예제 #1
0
        /// <summary>
        /// Prepares the save call by checking the session caches for a pre-existing
        /// entity and performing any lifecycle callbacks.
        /// </summary>
        /// <param name="entity">The entity to be saved.</param>
        /// <param name="id">The id by which to save the entity.</param>
        /// <param name="persister">The entity's persister instance.</param>
        /// <param name="useIdentityColumn">Is an identity column being used?</param>
        /// <param name="anything">Generally cascade-specific information.</param>
        /// <param name="source">The session from which the event originated.</param>
        /// <param name="requiresImmediateIdAccess">does the event context require
        /// access to the identifier immediately after execution of this method (if
        /// not, post-insert style id generators may be postponed if we are outside
        /// a transaction).</param>
        /// <returns>
        /// The id used to save the entity; may be null depending on the
        /// type of id generator used and the requiresImmediateIdAccess value
        /// </returns>
        protected override object PerformSave(object entity, object id, NHibernate.Persister.Entity.IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess)
        {
            if (entity is IEntity)
            {
                Events.CoreEvents.Instance.OnEntitySaving((IEntity)entity, null);
            }

            eventListenerHelper.OnCreate(entity);

            return(base.PerformSave(entity, id, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess));
        }
        public void Should_Update_Creation_Fields_Correctly()
        {
            var principalProvider = new Mock<IPrincipalProvider>();
            principalProvider.Setup(p => p.CurrentPrincipalName).Returns("TestPrincipal");
            var helper = new EventListenerHelper(principalProvider.Object);

            var entity = CreateEntity();
            helper.OnCreate(entity);

            EnsureDeletionPropertiesUntouched(entity);

            Assert.IsTrue(entity.CreatedOn != DateTime.MinValue);
            Assert.IsTrue(entity.ModifiedOn != DateTime.MinValue);
            Assert.AreEqual(entity.CreatedByUser, "TestPrincipal");
            Assert.AreEqual(entity.ModifiedByUser, "TestPrincipal");
        }