|
| 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.Collections.Generic; |
| 12 | +using System.Linq; |
| 13 | +using NHibernate.Cfg; |
| 14 | +using NHibernate.Cfg.MappingSchema; |
| 15 | +using NHibernate.Mapping.ByCode; |
| 16 | +using NHibernate.SqlCommand; |
| 17 | +using NUnit.Framework; |
| 18 | +using NHibernate.Linq; |
| 19 | + |
| 20 | +namespace NHibernate.Test.NHSpecificTest.GH3421 |
| 21 | +{ |
| 22 | + using System.Threading.Tasks; |
| 23 | + [TestFixture] |
| 24 | + public class ByCodeFixtureAsync : TestCaseMappingByCode |
| 25 | + { |
| 26 | + private SqlInterceptor _interceptor; |
| 27 | + |
| 28 | + protected override HbmMapping GetMappings() |
| 29 | + { |
| 30 | + var mapper = new ModelMapper(); |
| 31 | + mapper.Class<Entity>(rc => |
| 32 | + { |
| 33 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 34 | + rc.Property(x => x.Name); |
| 35 | + rc.Component(x => x.Attributes, new { |
| 36 | + Sku = (string)null |
| 37 | + }, dc => { |
| 38 | + dc.Property(x => x.Sku); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 43 | + } |
| 44 | + |
| 45 | + protected override void Configure(Configuration configuration) |
| 46 | + { |
| 47 | + base.Configure(configuration); |
| 48 | + |
| 49 | + _interceptor = new SqlInterceptor(); |
| 50 | + |
| 51 | + configuration.SetInterceptor(_interceptor); |
| 52 | + } |
| 53 | + |
| 54 | + protected override void OnSetUp() |
| 55 | + { |
| 56 | + using (var session = OpenSession()) |
| 57 | + using (var transaction = session.BeginTransaction()) |
| 58 | + { |
| 59 | + var e1 = new Entity { Name = "Bob" }; |
| 60 | + session.Save(e1); |
| 61 | + |
| 62 | + var e2 = new Entity { Name = "Sally", Attributes = new Dictionary<string, object>() { |
| 63 | + { "Sku", "AAA" } |
| 64 | + } }; |
| 65 | + session.Save(e2); |
| 66 | + |
| 67 | + transaction.Commit(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + protected override void OnTearDown() |
| 72 | + { |
| 73 | + using (var session = OpenSession()) |
| 74 | + using (var transaction = session.BeginTransaction()) |
| 75 | + { |
| 76 | + session.CreateQuery("delete from Entity").ExecuteUpdate(); |
| 77 | + transaction.Commit(); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + [Test] |
| 82 | + public async Task TestFlushDoesNotTriggerAnUpdateAsync() |
| 83 | + { |
| 84 | + using (var session = OpenSession()) |
| 85 | + using (var transaction = session.BeginTransaction()) |
| 86 | + { |
| 87 | + var foo = await (session.Query<Entity>().ToListAsync()); |
| 88 | + |
| 89 | + await (session.FlushAsync()); |
| 90 | + |
| 91 | + var updateStatements = _interceptor.SqlStatements.Where(s => s.ToString().ToUpper().Contains("UPDATE")).ToList(); |
| 92 | + |
| 93 | + Assert.That(updateStatements, Has.Count.EqualTo(0)); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public class SqlInterceptor : EmptyInterceptor |
| 98 | + { |
| 99 | + public IList<SqlString> SqlStatements = new List<SqlString>(); |
| 100 | + |
| 101 | + public override SqlString OnPrepareStatement(SqlString sql) |
| 102 | + { |
| 103 | + SqlStatements.Add(sql); |
| 104 | + |
| 105 | + return base.OnPrepareStatement(sql); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments