|
| 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.Collections.Generic; |
| 13 | +using System.Linq; |
| 14 | +using NUnit.Framework; |
| 15 | +using NHibernate.Linq; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.GH1760 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class MapKeyFormulasFixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + protected override void OnSetUp() |
| 24 | + { |
| 25 | + using (var session = OpenSession()) |
| 26 | + using (var transaction = session.BeginTransaction()) |
| 27 | + { |
| 28 | + var bob = |
| 29 | + new User |
| 30 | + { |
| 31 | + Name = "Bob" |
| 32 | + }; |
| 33 | + session.Save(bob); |
| 34 | + |
| 35 | + var sally = |
| 36 | + new User |
| 37 | + { |
| 38 | + Name = "Sally" |
| 39 | + }; |
| 40 | + session.Save(sally); |
| 41 | + |
| 42 | + var g1 = new Group { Name = "Salesperson" }; |
| 43 | + session.Save(g1); |
| 44 | + |
| 45 | + g1.UsersByName.Add(bob.Name, bob); |
| 46 | + g1.UsersByName.Add(sally.Name, sally); |
| 47 | + |
| 48 | + transaction.Commit(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + protected override void OnTearDown() |
| 53 | + { |
| 54 | + using (var session = OpenSession()) |
| 55 | + using (var transaction = session.BeginTransaction()) |
| 56 | + { |
| 57 | + // HQL "delete from" does not handle foreign key order. |
| 58 | + session.Delete("from User"); |
| 59 | + session.CreateQuery("delete System.Object").ExecuteUpdate(); |
| 60 | + |
| 61 | + transaction.Commit(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + [Test] |
| 66 | + public async Task CheckMapKeyAsync() |
| 67 | + { |
| 68 | + using (var session = OpenSession()) |
| 69 | + using (var tx = session.BeginTransaction()) |
| 70 | + { |
| 71 | + var salesperson = await (session.Query<Group>().SingleAsync(u => u.Name == "Salesperson")); |
| 72 | + |
| 73 | + Assert.That( |
| 74 | + salesperson.UsersByName, |
| 75 | + Has.Count.EqualTo(2) |
| 76 | + .And.One.Property(nameof(KeyValuePair<string, User>.Key)).EqualTo("Bob") |
| 77 | + .And.One.Property(nameof(KeyValuePair<string, User>.Key)).EqualTo("Sally")); |
| 78 | + |
| 79 | + await (tx.CommitAsync()); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments