|
| 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; |
| 12 | +using NHibernate.Cfg.MappingSchema; |
| 13 | +using NHibernate.Mapping.ByCode; |
| 14 | +using NUnit.Framework; |
| 15 | + |
| 16 | +namespace NHibernate.Test.NHSpecificTest.GH1738 |
| 17 | +{ |
| 18 | + using System.Threading.Tasks; |
| 19 | + [TestFixture] |
| 20 | + public class RefreshLocallyRemovedCollectionItemFixtureAsync : TestCaseMappingByCode |
| 21 | + { |
| 22 | + private Guid _id; |
| 23 | + |
| 24 | + protected override HbmMapping GetMappings() |
| 25 | + { |
| 26 | + var mapper = new ModelMapper(); |
| 27 | + mapper.Class<Entity>(rc => |
| 28 | + { |
| 29 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 30 | + rc.Property(x => x.Name); |
| 31 | + rc.Bag( |
| 32 | + x => x.Children, |
| 33 | + m => |
| 34 | + { |
| 35 | + m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans); |
| 36 | + m.Inverse(true); |
| 37 | + m.Key(km => km.Column("Parent")); |
| 38 | + }, |
| 39 | + relation => relation.OneToMany()); |
| 40 | + }); |
| 41 | + |
| 42 | + mapper.Class<Child>(rc => |
| 43 | + { |
| 44 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 45 | + rc.Property(x => x.Name); |
| 46 | + rc.ManyToOne(x => x.Parent); |
| 47 | + }); |
| 48 | + |
| 49 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 50 | + } |
| 51 | + |
| 52 | + protected override void OnSetUp() |
| 53 | + { |
| 54 | + using (var session = OpenSession()) |
| 55 | + using (var transaction = session.BeginTransaction()) |
| 56 | + { |
| 57 | + var e1 = new Entity { Name = "Bob"}; |
| 58 | + e1.Children.Add(new Child() {Name = "Child", Parent = e1}); |
| 59 | + session.Save(e1); |
| 60 | + transaction.Commit(); |
| 61 | + _id = e1.Id; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + protected override void OnTearDown() |
| 66 | + { |
| 67 | + using (var session = OpenSession()) |
| 68 | + using (var transaction = session.BeginTransaction()) |
| 69 | + { |
| 70 | + session.Delete("from System.Object"); |
| 71 | + transaction.Commit(); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + [Test] |
| 76 | + public async Task RefreshLocallyRemovedCollectionItemAsync() |
| 77 | + { |
| 78 | + Entity entity; |
| 79 | + using (var session = OpenSession()) |
| 80 | + { |
| 81 | + entity = await (session.GetAsync<Entity>(_id)); |
| 82 | + entity.Children.RemoveAt(0); |
| 83 | + } |
| 84 | + |
| 85 | + using (var session = OpenSession()) |
| 86 | + { |
| 87 | + await (session.UpdateAsync(entity)); |
| 88 | + await (session.RefreshAsync(entity)); |
| 89 | + foreach (var child in entity.Children) |
| 90 | + { |
| 91 | + await (session.RefreshAsync(child)); |
| 92 | + } |
| 93 | + |
| 94 | + Assert.That(session.GetSessionImplementation().PersistenceContext.IsReadOnly(entity), Is.False); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments