|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System.Linq; |
| 12 | +using NUnit.Framework; |
| 13 | +using NHibernate.Cfg; |
| 14 | +using NHibernate.Type; |
| 15 | + |
| 16 | +namespace NHibernate.Test.NHSpecificTest.GH1486 |
| 17 | +{ |
| 18 | + using System.Threading.Tasks; |
| 19 | + using System.Threading; |
| 20 | + [TestFixture] |
| 21 | + public class FixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + private readonly OnFlushDirtyInterceptor _interceptor = new OnFlushDirtyInterceptor(); |
| 24 | + |
| 25 | + protected override void Configure(Configuration configuration) |
| 26 | + { |
| 27 | + base.Configure(configuration); |
| 28 | + configuration.SetInterceptor(_interceptor); |
| 29 | + } |
| 30 | + |
| 31 | + protected override void OnSetUp() |
| 32 | + { |
| 33 | + using (var session = OpenSession()) |
| 34 | + { |
| 35 | + using (var transaction = session.BeginTransaction()) |
| 36 | + { |
| 37 | + var john = new Person(1, "John", new Address()); |
| 38 | + session.Save(john); |
| 39 | + |
| 40 | + var mary = new Person(2, "Mary", null); |
| 41 | + session.Save(mary); |
| 42 | + |
| 43 | + var bob = new Person(3, "Bob", new Address("1", "A", "B")); |
| 44 | + session.Save(bob); |
| 45 | + |
| 46 | + session.Flush(); |
| 47 | + transaction.Commit(); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + protected override void OnTearDown() |
| 53 | + { |
| 54 | + using (var session = OpenSession()) |
| 55 | + using (var transaction = session.BeginTransaction()) |
| 56 | + { |
| 57 | + session.Delete("from System.Object"); |
| 58 | + session.Flush(); |
| 59 | + transaction.Commit(); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// The test case was imported from Hibernate HHH-11237 and adjusted for NHibernate. |
| 65 | + /// </summary> |
| 66 | + [Test] |
| 67 | + public async Task TestSelectBeforeUpdateAsync() |
| 68 | + { |
| 69 | + using (var session = OpenSession()) |
| 70 | + { |
| 71 | + using (var transaction = session.BeginTransaction()) |
| 72 | + { |
| 73 | + var john = await (session.GetAsync<Person>(1)); |
| 74 | + _interceptor.Reset(); |
| 75 | + john.Address = null; |
| 76 | + await (session.FlushAsync()); |
| 77 | + Assert.That(_interceptor.CallCount, Is.EqualTo(0), "unexpected flush dirty count for John"); |
| 78 | + |
| 79 | + _interceptor.Reset(); |
| 80 | + var mary = await (session.GetAsync<Person>(2)); |
| 81 | + mary.Address = new Address(); |
| 82 | + await (session.FlushAsync()); |
| 83 | + Assert.That(_interceptor.CallCount, Is.EqualTo(0), "unexpected flush dirty count for Mary"); |
| 84 | + await (transaction.CommitAsync()); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + Person johnObj; |
| 89 | + Person maryObj; |
| 90 | + using (var session = OpenSession()) |
| 91 | + { |
| 92 | + using (var transaction = session.BeginTransaction()) |
| 93 | + { |
| 94 | + johnObj = await (session.GetAsync<Person>(1)); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + using (var session = OpenSession()) |
| 99 | + { |
| 100 | + using (var transaction = session.BeginTransaction()) |
| 101 | + { |
| 102 | + maryObj = await (session.GetAsync<Person>(2)); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + using (var session = OpenSession()) |
| 107 | + { |
| 108 | + using (var transaction = session.BeginTransaction()) |
| 109 | + { |
| 110 | + _interceptor.Reset(); |
| 111 | + johnObj.Address = null; |
| 112 | + await (session.UpdateAsync(johnObj)); |
| 113 | + await (session.FlushAsync()); |
| 114 | + Assert.That(_interceptor.CallCount, Is.EqualTo(0), "unexpected flush dirty count for John update"); |
| 115 | + |
| 116 | + _interceptor.Reset(); |
| 117 | + maryObj.Address = new Address(); |
| 118 | + await (session.UpdateAsync(maryObj)); |
| 119 | + await (session.FlushAsync()); |
| 120 | + Assert.That(_interceptor.CallCount, Is.EqualTo(0), "unexpected flush dirty count for Mary update"); |
| 121 | + await (transaction.CommitAsync()); |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + [Test] |
| 127 | + public async Task TestDirectCallToIsModifiedAsync() |
| 128 | + { |
| 129 | + using (var session = OpenSession()) |
| 130 | + using (var transaction = session.BeginTransaction()) |
| 131 | + { |
| 132 | + var person = await (session.LoadAsync<Person>(3)); |
| 133 | + Assert.That(person, Is.Not.Null, "Bob is not found."); |
| 134 | + Assert.That(person.Address, Is.Not.Null, "Bob's address is missing."); |
| 135 | + var sessionImplementor = session.GetSessionImplementation(); |
| 136 | + |
| 137 | + var metaData = session.SessionFactory.GetClassMetadata(typeof(Person)); |
| 138 | + foreach (var propertyType in metaData.PropertyTypes) |
| 139 | + { |
| 140 | + if (!(propertyType is ComponentType componentType) || componentType.ReturnedClass.Name != "Address") |
| 141 | + continue; |
| 142 | + |
| 143 | + var checkable = new [] { true, true, true }; |
| 144 | + Assert.That( |
| 145 | + () => componentType.IsModifiedAsync(new object[] { "", "", "" }, person.Address, checkable, sessionImplementor, CancellationToken.None), |
| 146 | + Throws.Nothing, |
| 147 | + "Checking component against an array snapshot failed"); |
| 148 | + var isModified = await (componentType.IsModifiedAsync(person.Address, person.Address, checkable, sessionImplementor, CancellationToken.None)); |
| 149 | + Assert.That(isModified, Is.False, "Checking same component failed"); |
| 150 | + isModified = await (componentType.IsModifiedAsync(new Address("1", "A", "B"), person.Address, checkable, sessionImplementor, CancellationToken.None)); |
| 151 | + Assert.That(isModified, Is.False, "Checking equal component failed"); |
| 152 | + } |
| 153 | + await (transaction.RollbackAsync()); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | +} |
0 commit comments