|
| 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 NUnit.Framework; |
| 14 | +using NHibernate.Linq; |
| 15 | + |
| 16 | +namespace NHibernate.Test.NHSpecificTest.NH3972 |
| 17 | +{ |
| 18 | + using System.Threading.Tasks; |
| 19 | + [KnownBug("NH-3972(GH-1189)")] |
| 20 | + [TestFixture] |
| 21 | + public class FixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + private DataChangeState changeState = null; |
| 24 | + private DataRequestForChangeState rfcState = null; |
| 25 | + private DataIncidentState incidentState = null; |
| 26 | + private DataProblemState problemState = null; |
| 27 | + |
| 28 | + protected override void OnSetUp() |
| 29 | + { |
| 30 | + using (var session = OpenSession()) |
| 31 | + using (var transaction = session.BeginTransaction()) |
| 32 | + { |
| 33 | + foreach (ChangeInternalState state in Enum.GetValues(typeof(ChangeInternalState))) |
| 34 | + { |
| 35 | + changeState = new DataChangeState { State = state, Description = Enum.GetName(typeof(ChangeInternalState), state) }; |
| 36 | + session.Save(changeState); |
| 37 | + } |
| 38 | + |
| 39 | + foreach (RequestForChangeInternalState state in Enum.GetValues(typeof(RequestForChangeInternalState))) |
| 40 | + { |
| 41 | + rfcState = new DataRequestForChangeState { State = state, Description = Enum.GetName(typeof(RequestForChangeInternalState), state) }; |
| 42 | + session.Save(rfcState); |
| 43 | + } |
| 44 | + |
| 45 | + foreach (IncidentInternalState state in Enum.GetValues(typeof(IncidentInternalState))) |
| 46 | + { |
| 47 | + incidentState = new DataIncidentState { State = state, Description = Enum.GetName(typeof(IncidentInternalState), state) }; |
| 48 | + session.Save(incidentState); |
| 49 | + } |
| 50 | + |
| 51 | + foreach (ProblemInternalState state in Enum.GetValues(typeof(ProblemInternalState))) |
| 52 | + { |
| 53 | + problemState = new DataProblemState { State = state, Description = Enum.GetName(typeof(ProblemInternalState), state) }; |
| 54 | + session.Save(problemState); |
| 55 | + } |
| 56 | + |
| 57 | + session.Save(new RequestForChange { Subject = "I have a request", State = rfcState }); |
| 58 | + session.Save(new Change { Subject = "I have changed the following stuff", State = changeState, ExecutedBy = "Me" }); |
| 59 | + session.Save(new Incident { Subject = "Can someone look for this", State = incidentState, ReportedBy = "Someone" }); |
| 60 | + session.Save(new Problem { Subject = "We have a problem", State = problemState }); |
| 61 | + |
| 62 | + session.Flush(); |
| 63 | + transaction.Commit(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + protected override void OnTearDown() |
| 68 | + { |
| 69 | + using (var session = OpenSession()) |
| 70 | + using (var transaction = session.BeginTransaction()) |
| 71 | + { |
| 72 | + session.Delete("from System.Object"); |
| 73 | + |
| 74 | + session.Flush(); |
| 75 | + transaction.Commit(); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + [Test] |
| 80 | + public async Task QueryingAllAsync() |
| 81 | + { |
| 82 | + using (var session = OpenSession()) |
| 83 | + { |
| 84 | + var result = await (session.Query<DataRecord>().ToListAsync()); |
| 85 | + Assert.That(result.Count, Is.EqualTo(4)); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + [Test] |
| 90 | + public async Task QueryingSubPropertiesWithDifferentNamesAsync() |
| 91 | + { |
| 92 | + using (var session = OpenSession()) |
| 93 | + { |
| 94 | + var result = await (session.Query<DataRecord>().Select(x => new |
| 95 | + { |
| 96 | + x.Subject, |
| 97 | + ((Incident) x).ReportedBy, |
| 98 | + ((Change) x).ExecutedBy |
| 99 | + }).ToListAsync()); |
| 100 | + Assert.That(result.Count, Is.EqualTo(4)); |
| 101 | + Assert.That(result.Count(x => x.ReportedBy == "Someone") == 1, Is.True); // there is one entity with a set ReportedBy column, i.e. the entity of type "Incident" |
| 102 | + Assert.That(result.Count(x => x.ExecutedBy == "Me") == 1, Is.True); // there is one entity with a set ExecutedBy column, i.e. the entity of type "Change" |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + [Test] |
| 107 | + public async Task QueryingSubPropertyWithTheSameNameAsync() |
| 108 | + { |
| 109 | + using (var session = OpenSession()) |
| 110 | + { |
| 111 | + var result = await (session.Query<DataRecord>().Select(x => new |
| 112 | + { |
| 113 | + x.Subject, |
| 114 | + IncidentState = ((Incident) x).State.Description |
| 115 | + }).ToListAsync()); |
| 116 | + Assert.That(result.Count, Is.EqualTo(4)); |
| 117 | + Assert.That(result.Count(x => x.IncidentState == incidentState.Description) == 1, Is.True); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + [Test] |
| 122 | + public async Task QueryingSubPropertiesWithTheSameNamesAsync() |
| 123 | + { |
| 124 | + using (var session = OpenSession()) |
| 125 | + { |
| 126 | + var result = await (session.Query<DataRecord>().Select(x => new |
| 127 | + { |
| 128 | + x.Subject, |
| 129 | + IncidentState = ((Incident) x).State.Description, |
| 130 | + ChangeState = ((Change) x).State.Description |
| 131 | + }).ToListAsync()); |
| 132 | + Assert.That(result.Count, Is.EqualTo(4)); |
| 133 | + Assert.That(result.Count(x => x.IncidentState == incidentState.Description) == 1, Is.True); // there is only one "Incident" entity |
| 134 | + Assert.That(result.Count(x => x.ChangeState == changeState.Description) == 1, Is.True); // there is only one "Change" entity |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments