|
| 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 System.Linq; |
| 13 | +using NHibernate.Cfg; |
| 14 | +using NHibernate.Cfg.MappingSchema; |
| 15 | +using NHibernate.Mapping.ByCode; |
| 16 | +using NUnit.Framework; |
| 17 | +using NHibernate.Linq; |
| 18 | + |
| 19 | +namespace NHibernate.Test.NHSpecificTest.IlogsProxyTest |
| 20 | +{ |
| 21 | + using System.Threading.Tasks; |
| 22 | + [TestFixture] |
| 23 | + public class FixtureAsync : TestCaseMappingByCode |
| 24 | + { |
| 25 | + private Guid _entityWithClassProxy1Id; |
| 26 | + private Guid _entityWithClassProxy2Id; |
| 27 | + private Guid _entityWithInterfaceProxy1Id; |
| 28 | + private Guid _entityWithInterfaceProxy2Id; |
| 29 | + private Guid _entityWithClassLookupId; |
| 30 | + private Guid _entityWithInterfaceLookupId; |
| 31 | + |
| 32 | + protected override HbmMapping GetMappings() |
| 33 | + { |
| 34 | + var mapper = new ModelMapper(); |
| 35 | + mapper.Class<EntityWithClassProxyDefinition>(rc => |
| 36 | + { |
| 37 | + rc.Proxy(typeof(EntityWithClassProxyDefinition)); |
| 38 | + |
| 39 | + rc.Id(x => x.Id); |
| 40 | + rc.Property(x => x.Name); |
| 41 | + }); |
| 42 | + |
| 43 | + mapper.Class<EntityWithInterfaceProxyDefinition>(rc => |
| 44 | + { |
| 45 | + rc.Proxy(typeof(IEntityProxy)); |
| 46 | + |
| 47 | + rc.Id(x => x.Id); |
| 48 | + rc.Property(x => x.Name); |
| 49 | + }); |
| 50 | + |
| 51 | + mapper.Class<EntityWithClassLookup>(rc => |
| 52 | + { |
| 53 | + rc.Id(x => x.Id); |
| 54 | + rc.Property(x => x.Name); |
| 55 | + rc.ManyToOne(x => x.EntityLookup, x => x.Class(typeof(EntityWithClassProxyDefinition))); |
| 56 | + }); |
| 57 | + |
| 58 | + mapper.Class<EntityWithInterfaceLookup>(rc => |
| 59 | + { |
| 60 | + rc.Id(x => x.Id); |
| 61 | + rc.Property(x => x.Name); |
| 62 | + rc.ManyToOne(x => x.EntityLookup, x => x.Class(typeof(EntityWithInterfaceProxyDefinition))); |
| 63 | + }); |
| 64 | + |
| 65 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + protected override void OnSetUp() |
| 70 | + { |
| 71 | + using(var session = OpenSession()) |
| 72 | + { |
| 73 | + var entityCP1 = new EntityWithClassProxyDefinition |
| 74 | + { |
| 75 | + Id = Guid.NewGuid(), |
| 76 | + Name = "Name 1" |
| 77 | + }; |
| 78 | + _entityWithClassProxy1Id = entityCP1.Id; |
| 79 | + |
| 80 | + var entityCP2 = new EntityWithClassProxyDefinition |
| 81 | + { |
| 82 | + Id = Guid.NewGuid(), |
| 83 | + Name = "Name 2" |
| 84 | + }; |
| 85 | + _entityWithClassProxy2Id = entityCP2.Id; |
| 86 | + |
| 87 | + var entityIP1 = new EntityWithInterfaceProxyDefinition |
| 88 | + { |
| 89 | + Id = Guid.NewGuid(), |
| 90 | + Name = "Name 1" |
| 91 | + }; |
| 92 | + _entityWithInterfaceProxy1Id = entityIP1.Id; |
| 93 | + |
| 94 | + var entityIP2 = new EntityWithInterfaceProxyDefinition |
| 95 | + { |
| 96 | + Id = Guid.NewGuid(), |
| 97 | + Name = "Name 2" |
| 98 | + }; |
| 99 | + _entityWithInterfaceProxy2Id = entityIP2.Id; |
| 100 | + |
| 101 | + session.Save(entityCP1); |
| 102 | + session.Save(entityCP2); |
| 103 | + session.Save(entityIP1); |
| 104 | + session.Save(entityIP2); |
| 105 | + |
| 106 | + var entityCL = new EntityWithClassLookup |
| 107 | + { |
| 108 | + Id = Guid.NewGuid(), |
| 109 | + Name = "Name 1", |
| 110 | + EntityLookup = (EntityWithClassProxyDefinition)session.Load(typeof(EntityWithClassProxyDefinition), entityCP1.Id) |
| 111 | + }; |
| 112 | + _entityWithClassLookupId = entityCL.Id; |
| 113 | + |
| 114 | + var entityIL = new EntityWithInterfaceLookup |
| 115 | + { |
| 116 | + Id = Guid.NewGuid(), |
| 117 | + Name = "Name 1", |
| 118 | + EntityLookup = (IEntityProxy)session.Load(typeof(EntityWithInterfaceProxyDefinition), entityIP1.Id) |
| 119 | + }; |
| 120 | + _entityWithInterfaceLookupId = entityIL.Id; |
| 121 | + |
| 122 | + session.Save(entityCL); |
| 123 | + session.Save(entityIL); |
| 124 | + |
| 125 | + session.Flush(); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + |
| 130 | + protected override void OnTearDown() |
| 131 | + { |
| 132 | + using (var session = OpenSession()) |
| 133 | + { |
| 134 | + using (var transaction = session.BeginTransaction()) |
| 135 | + { |
| 136 | + session.Delete("from System.Object"); |
| 137 | + |
| 138 | + session.Flush(); |
| 139 | + transaction.Commit(); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + [Test] |
| 146 | + public async Task UpdateEntityWithClassLookupAsync() |
| 147 | + { |
| 148 | + using (var session = OpenSession()) |
| 149 | + { |
| 150 | + using(var transaction = session.BeginTransaction()) |
| 151 | + { |
| 152 | + var entityToUpdate = await (session.Query<EntityWithClassLookup>() |
| 153 | + .FirstAsync(e => e.Id == _entityWithClassLookupId)); |
| 154 | + |
| 155 | + entityToUpdate.EntityLookup = (EntityWithClassProxyDefinition)await (session.LoadAsync(typeof(EntityWithClassProxyDefinition), _entityWithClassProxy2Id)); |
| 156 | + |
| 157 | + await (session.UpdateAsync(entityToUpdate)); |
| 158 | + await (session.FlushAsync()); |
| 159 | + await (transaction.RollbackAsync()); |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + |
| 165 | + [Test] |
| 166 | + public async Task UpdateEntityWithInterfaceLookupAsync() |
| 167 | + { |
| 168 | + using(var session = OpenSession()) |
| 169 | + { |
| 170 | + using(var transaction = session.BeginTransaction()) |
| 171 | + { |
| 172 | + var entityToUpdate = await (session.Query<EntityWithInterfaceLookup>() |
| 173 | + .FirstAsync(e => e.Id == _entityWithInterfaceLookupId)); |
| 174 | + |
| 175 | + entityToUpdate.EntityLookup = (IEntityProxy)await (session.LoadAsync(typeof(EntityWithInterfaceProxyDefinition), _entityWithInterfaceProxy2Id)); |
| 176 | + entityToUpdate.EntityLookup.Id = Guid.Empty; |
| 177 | + |
| 178 | + await (session.UpdateAsync(entityToUpdate)); |
| 179 | + await (session.FlushAsync()); |
| 180 | + await (transaction.RollbackAsync()); |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | +} |
0 commit comments