AfterInsert() public method

Invoked after the SqlQuery to insert the record for the instance has been executed.
Thrown if instance is null or IdentifierStrategy is DbGenerated /// and executeScalarResult is null.
public AfterInsert ( object instance, object executeScalarResult ) : void
instance object The instance which has been inserted.
executeScalarResult object The execute scalar result (the identifier value returned by the database /// or null if the identifier is .Assigned.
return void
        public void AfterInsertDoesNotThrowArgumentNullExceptionForNullExecuteScalarResultIfIdentifierStrategyAssigned()
        {
            ObjectInfo.MappingConvention = new ConventionMappingConvention(
                UnitTest.GetConventionMappingSettings(IdentifierStrategy.Assigned));

            var listener = new IdentifierStrategyListener();

            Assert.DoesNotThrow(() => listener.AfterInsert(new Customer(), null));
        }
        public void AfterInsertDoesNotSetIdentifierIfExecuteScalarResultIsNullAndIdentifierStrategySequence()
        {
            ObjectInfo.MappingConvention = new ConventionMappingConvention(
                UnitTest.GetConventionMappingSettings(IdentifierStrategy.Sequence));

            var listener = new IdentifierStrategyListener();
            var customer = new Customer();

            Assert.DoesNotThrow(() => listener.AfterInsert(customer, null));

            Assert.Equal(0, customer.Id);
        }
        public void AfterInsertSetsIdentifierValueForIdentifierStrategyDbGenerated()
        {
            ObjectInfo.MappingConvention = new ConventionMappingConvention(
                UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));

            var customer = new Customer();
            int scalarResult = 4354;

            var listener = new IdentifierStrategyListener();
            listener.AfterInsert(customer, scalarResult);

            Assert.Equal(scalarResult, customer.Id);
        }
        public void AfterInsertSetsIdentifierValueConvertingItToThePropertyType()
        {
            ObjectInfo.MappingConvention = new ConventionMappingConvention(
                UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));

            var customer = new Customer();
            decimal scalarResult = 4354;

            var listener = new IdentifierStrategyListener();
            listener.AfterInsert(customer, scalarResult);

            Assert.Equal(Convert.ToInt32(scalarResult), customer.Id);
        }
        public void AfterInsertThrowsArgumentNullExceptionForNullInstance()
        {
            var listener = new IdentifierStrategyListener();

            var exception = Assert.Throws<ArgumentNullException>(() => listener.AfterInsert(null, 1));

            Assert.Equal("instance", exception.ParamName);
        }