You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//------------------------------------------------------------------------------// <auto-generated>// This code was generated by AsyncGenerator.//// Changes to this file may cause incorrect behavior and will be lost if// the code is regenerated.// </auto-generated>//------------------------------------------------------------------------------usingSystem;usingSystem.Data.Common;usingNUnit.Framework;usingNHibernate.Dialect;namespaceNHibernate.Test.NHSpecificTest.NH2204{usingSystem.Threading.Tasks;usingSystem.Threading;[TestFixture]publicclassFixtureAsync:BugTestCase{publicoverridestringBugNumber{get{return"NH2204";}}protectedoverrideboolAppliesTo(Dialect.Dialectdialect){returndialectisPostgreSQL81Dialect;}// create the triggerprotectedoverridevoidOnSetUp(){using(ISessions=OpenSession()){varcommand=s.Connection.CreateCommand();command.CommandText="CREATE OR REPLACE FUNCTION audit_parent() RETURNS trigger AS $audit_parent$"+Environment.NewLine+"BEGIN"+Environment.NewLine+"INSERT INTO parent_history SELECT nextval('parent_history_histid_seq'), now(), NEW.*;"+Environment.NewLine+"RETURN NEW;"+Environment.NewLine+"END"+Environment.NewLine+" $audit_parent$ LANGUAGE 'plpgsql';";command.ExecuteNonQuery();command.CommandText="CREATE TRIGGER parent_audit"+Environment.NewLine+"AFTER INSERT OR UPDATE ON parent"+Environment.NewLine+"FOR EACH ROW EXECUTE PROCEDURE audit_parent();";command.ExecuteNonQuery();}}// remove trigger and remove data from tablesprotectedoverridevoidOnTearDown(){using(ISessions=OpenSession()){varcommand=s.Connection.CreateCommand();command.CommandText="DROP FUNCTION audit_parent() CASCADE;";command.ExecuteNonQuery();command.CommandText="DELETE from parent_history;";command.ExecuteNonQuery();command.CommandText="DELETE from parent;";command.ExecuteNonQuery();}}[Test]publicvoidKnownFailure_Correct_Id_Returned_When_Using_TriggerAsync(){Assert.ThrowsAsync<AssertionException>(()=>RunTestAsync(),"We expected this test to fail - if the problem has been fixed, clean-up the test.");}privateasyncTaskRunTestAsync(CancellationTokencancellationToken=default(CancellationToken)){varentity1=newParent{Name="Parent1_0"};// when saved this entity should have the id of 1varentity2=newParent{Name="Parent2_0"};// when saved this entity should have the id of 2varentity3=newParent{Name="Parent3_0"};// when saved this entity should have the id of 3using(ISessions=OpenSession()){// save first entityawait(s.SaveAsync(entity1,cancellationToken));await(s.FlushAsync(cancellationToken));Assert.AreEqual(1,entity1.Id);// save second entityawait(s.SaveAsync(entity2,cancellationToken));await(s.FlushAsync(cancellationToken));Assert.AreEqual(2,entity2.Id);// update this entity 10 times - adds entries to the audit table // causing the sequences for the parent and history table to no longer be alignedfor(inti=1;i<11;i++){entity2.Name=string.Format("Parent2_{0}",i);await(s.UpdateAsync(entity2,cancellationToken));await(s.FlushAsync(cancellationToken));}// save third entityawait(s.SaveAsync(entity3,cancellationToken));await(s.FlushAsync(cancellationToken));Assert.AreEqual(3,entity3.Id,"oh uh - it would appear that lastval() is not our friend when a trigger updates other sequences.");// now would be a good time to look at the data in the tables and see that they have the IDs as expected// which are not the same as those returned by nhibernate}}}}
usingSystem;usingSystem.Data.Common;usingNUnit.Framework;usingNHibernate.Dialect;namespaceNHibernate.Test.NHSpecificTest.NH2204{[TestFixture]publicclassFixture:BugTestCase{publicoverridestringBugNumber{get{return"NH2204";}}protectedoverrideboolAppliesTo(Dialect.Dialectdialect){returndialectisPostgreSQL81Dialect;}// create the triggerprotectedoverridevoidOnSetUp(){using(ISessions=OpenSession()){varcommand=s.Connection.CreateCommand();command.CommandText="CREATE OR REPLACE FUNCTION audit_parent() RETURNS trigger AS $audit_parent$"+Environment.NewLine+"BEGIN"+Environment.NewLine+"INSERT INTO parent_history SELECT nextval('parent_history_histid_seq'), now(), NEW.*;"+Environment.NewLine+"RETURN NEW;"+Environment.NewLine+"END"+Environment.NewLine+" $audit_parent$ LANGUAGE 'plpgsql';";command.ExecuteNonQuery();command.CommandText="CREATE TRIGGER parent_audit"+Environment.NewLine+"AFTER INSERT OR UPDATE ON parent"+Environment.NewLine+"FOR EACH ROW EXECUTE PROCEDURE audit_parent();";command.ExecuteNonQuery();}}// remove trigger and remove data from tablesprotectedoverridevoidOnTearDown(){using(ISessions=OpenSession()){varcommand=s.Connection.CreateCommand();command.CommandText="DROP FUNCTION audit_parent() CASCADE;";command.ExecuteNonQuery();command.CommandText="DELETE from parent_history;";command.ExecuteNonQuery();command.CommandText="DELETE from parent;";command.ExecuteNonQuery();}}[Test]publicvoidKnownFailure_Correct_Id_Returned_When_Using_Trigger(){Assert.Throws<AssertionException>(()=>RunTest(),"We expected this test to fail - if the problem has been fixed, clean-up the test.");}privatevoidRunTest(){varentity1=newParent{Name="Parent1_0"};// when saved this entity should have the id of 1varentity2=newParent{Name="Parent2_0"};// when saved this entity should have the id of 2varentity3=newParent{Name="Parent3_0"};// when saved this entity should have the id of 3using(ISessions=OpenSession()){// save first entitys.Save(entity1);s.Flush();Assert.AreEqual(1,entity1.Id);// save second entitys.Save(entity2);s.Flush();Assert.AreEqual(2,entity2.Id);// update this entity 10 times - adds entries to the audit table // causing the sequences for the parent and history table to no longer be alignedfor(inti=1;i<11;i++){entity2.Name=string.Format("Parent2_{0}",i);s.Update(entity2);s.Flush();}// save third entitys.Save(entity3);s.Flush();Assert.AreEqual(3,entity3.Id,"oh uh - it would appear that lastval() is not our friend when a trigger updates other sequences.");// now would be a good time to look at the data in the tables and see that they have the IDs as expected// which are not the same as those returned by nhibernate}}}}
0 commit comments