Skip to content

Commit 5d8219b

Browse files
Merge pull request #683 from fredericDelaporte/NH-3905
NH-3905 - Missings async tests
2 parents 4d99b2b + 66fedce commit 5d8219b

File tree

468 files changed

+20572
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

468 files changed

+20572
-250
lines changed

Tools/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" />
88
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net461" />
99
<package id="NUnit.Extension.VSProjectLoader" version="3.6.0" targetFramework="net461" />
10-
<package id="CSharpAsyncGenerator.CommandLine" version="0.3.6" targetFramework="net461" />
10+
<package id="CSharpAsyncGenerator.CommandLine" version="0.4.0" targetFramework="net461" />
1111
</packages>

src/AsyncGenerator.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@
156156
applyChanges: true
157157
analyzation:
158158
methodConversion:
159-
- conversion: Ignore
160-
hasAttributeName: IgnoreAttribute
161159
- conversion: Smart
162160
hasAttributeName: TestAttribute
163161
- conversion: Smart
@@ -180,6 +178,8 @@
180178
hasAttributeName: IgnoreAttribute
181179
- conversion: NewType
182180
hasAttributeName: TestFixtureAttribute
181+
- conversion: NewType
182+
anyBaseTypeRule: HasTestFixtureAttribute
183183
- conversion: Ignore
184184
rule: IsTestCase
185185
- conversion: Ignore
@@ -246,3 +246,6 @@ typeRules:
246246
- filters:
247247
- name: TestCase
248248
name: IsTestCase
249+
- filters:
250+
- hasAttributeName: TestFixtureAttribute
251+
name: HasTestFixtureAttribute

src/NHibernate.Test/Async/Ado/BatcherFixture.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,44 @@ public async Task OneRoundTripUpdateAsync()
9898
await (CleanupAsync());
9999
}
100100

101+
[Test, Ignore("Not fixed yet.")]
102+
[Description("SqlClient: The batcher should run all different INSERT queries in only one roundtrip.")]
103+
public async Task SqlClientOneRoundTripForUpdateAndInsertAsync()
104+
{
105+
if (Sfi.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false)
106+
Assert.Ignore("This test is for SqlClientBatchingBatcher only");
107+
108+
await (FillDbAsync());
109+
110+
using(var sqlLog = new SqlLogSpy())
111+
using (ISession s = Sfi.OpenSession())
112+
using (ITransaction tx = s.BeginTransaction())
113+
{
114+
await (s.SaveAsync(new VerySimple
115+
{
116+
Name = "test441",
117+
Weight = 894
118+
}));
119+
120+
await (s.SaveAsync(new AlmostSimple
121+
{
122+
Name = "test441",
123+
Weight = 894
124+
}));
125+
126+
await (tx.CommitAsync());
127+
128+
var log = sqlLog.GetWholeLog();
129+
//log should only contain NHibernate.SQL once, because that means
130+
//that we ony generated a single batch (NHibernate.SQL log will output
131+
//once per batch)
132+
Assert.AreEqual(0, log.IndexOf("NHibernate.SQL"), "log should start with NHibernate.SQL");
133+
Assert.AreEqual(-1, log.IndexOf("NHibernate.SQL", "NHibernate.SQL".Length), "NHibernate.SQL should only appear once in the log");
134+
}
135+
136+
await (CleanupAsync());
137+
}
138+
101139
[Test]
102140
[Description("SqlClient: The batcher log output should be formatted")]
103141
public async Task BatchedoutputShouldBeFormattedAsync()

src/NHibernate.Test/Async/Component/Basic/ComponentTest.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,78 @@ public async Task TestComponentStateChangeAndDirtinessAsync()
167167
}
168168
}
169169

170+
[Test]
171+
[Ignore("Ported from Hibernate. Read properties not supported in NH yet.")]
172+
public async Task TestCustomColumnReadAndWriteAsync()
173+
{
174+
const double HEIGHT_INCHES = 73;
175+
const double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
176+
177+
using (ISession s = Sfi.OpenSession())
178+
using (ITransaction t = s.BeginTransaction())
179+
{
180+
User u = new User("steve", "hibernater", new Person( "Steve Ebersole", new DateTime(1999, 12, 31), "Main St"));
181+
u.Person.HeightInches = HEIGHT_INCHES;
182+
await (s.PersistAsync(u));
183+
await (s.FlushAsync());
184+
185+
// Test value conversion during insert
186+
double heightViaSql = (double)await (s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResultAsync());
187+
Assert.That(heightViaSql, Is.EqualTo(HEIGHT_CENTIMETERS).Within(0.01d));
188+
189+
// Test projection
190+
double heightViaHql = (double)await (s.CreateQuery("select u.Person.HeightInches from User u where u.Id = 'steve'").UniqueResultAsync());
191+
Assert.That(heightViaHql, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));
192+
193+
// Test restriction and entity load via criteria
194+
u = (User)await (s.CreateCriteria(typeof(User))
195+
.Add(Restrictions.Between("Person.HeightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d))
196+
.UniqueResultAsync());
197+
Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));
198+
199+
// Test predicate and entity load via HQL
200+
u = (User)await (s.CreateQuery("from User u where u.Person.HeightInches between ? and ?")
201+
.SetDouble(0, HEIGHT_INCHES - 0.01d)
202+
.SetDouble(1, HEIGHT_INCHES + 0.01d)
203+
.UniqueResultAsync());
204+
205+
Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));
206+
207+
// Test update
208+
u.Person.HeightInches = 1;
209+
await (s.FlushAsync());
210+
heightViaSql = (double)await (s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResultAsync());
211+
Assert.That(heightViaSql, Is.EqualTo(2.54d).Within(0.01d));
212+
await (s.DeleteAsync(u));
213+
await (t.CommitAsync());
214+
s.Close();
215+
}
216+
}
217+
218+
[Test]
219+
[Ignore("Ported from Hibernate - failing in NH")]
220+
public async Task TestComponentQueriesAsync()
221+
{
222+
using (ISession s = Sfi.OpenSession())
223+
using (ITransaction t = s.BeginTransaction())
224+
{
225+
Employee emp = new Employee();
226+
emp.HireDate = new DateTime(1999, 12, 31);
227+
emp.Person = new Person();
228+
emp.Person.Name = "steve";
229+
emp.Person.Dob = new DateTime(1999, 12, 31);
230+
await (s.SaveAsync(emp));
231+
232+
await (s.CreateQuery("from Employee e where e.Person = :p and 1=1 and 2=2").SetParameter("p", emp.Person).ListAsync());
233+
await (s.CreateQuery("from Employee e where :p = e.Person").SetParameter("p", emp.Person).ListAsync());
234+
await (s.CreateQuery("from Employee e where e.Person = ('steve', current_timestamp)").ListAsync());
235+
236+
await (s.DeleteAsync( emp ));
237+
await (t.CommitAsync());
238+
s.Close();
239+
}
240+
}
241+
170242
[Test]
171243
public async Task TestComponentFormulaQueryAsync()
172244
{
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.Data.Common;
13+
using System.Data.Odbc;
14+
using System.Data.SqlClient;
15+
using System.Linq;
16+
using NHibernate.Cfg.MappingSchema;
17+
using NHibernate.Dialect;
18+
using NHibernate.Exceptions;
19+
using NHibernate.Linq;
20+
using NHibernate.Mapping.ByCode;
21+
using NUnit.Framework;
22+
23+
namespace NHibernate.Test.Component.Basic
24+
{
25+
using System.Threading.Tasks;
26+
[TestFixture]
27+
public class ComponentWithUniqueConstraintTestsAsync : TestCaseMappingByCode
28+
{
29+
protected override HbmMapping GetMappings()
30+
{
31+
var mapper = new ModelMapper();
32+
33+
mapper.Component<Person>(comp =>
34+
{
35+
comp.Property(p => p.Name);
36+
comp.Property(p => p.Dob);
37+
comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
38+
});
39+
40+
mapper.Class<Employee>(cm =>
41+
{
42+
cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow));
43+
cm.Property(employee => employee.HireDate);
44+
cm.Component(person => person.Person);
45+
});
46+
47+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
48+
}
49+
50+
protected override void OnTearDown()
51+
{
52+
using (var session = Sfi.OpenSession())
53+
using (var transaction = session.BeginTransaction())
54+
{
55+
session.Delete("from Employee");
56+
transaction.Commit();
57+
}
58+
}
59+
60+
[Test]
61+
public async Task CanBePersistedWithUniqueValuesAsync()
62+
{
63+
using (var session = OpenSession())
64+
using (var transaction = session.BeginTransaction())
65+
{
66+
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };
67+
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Hillary", Dob = new DateTime(2000, 1, 1) } };
68+
await (session.SaveAsync(e1));
69+
await (session.SaveAsync(e2));
70+
await (transaction.CommitAsync());
71+
}
72+
73+
using (var session = OpenSession())
74+
using (session.BeginTransaction())
75+
{
76+
var employees = await (session.Query<Employee>().ToListAsync());
77+
Assert.That(employees.Count, Is.EqualTo(2));
78+
Assert.That(employees.Select(employee => employee.Person.Name).ToArray(), Is.EquivalentTo(new[] { "Hillary", "Bill" }));
79+
}
80+
}
81+
82+
[Test]
83+
public void CannotBePersistedWithNonUniqueValuesAsync()
84+
{
85+
using (var session = OpenSession())
86+
using (session.BeginTransaction())
87+
{
88+
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };
89+
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };
90+
91+
var exception = Assert.ThrowsAsync<GenericADOException>(async () =>
92+
{
93+
await (session.SaveAsync(e1));
94+
await (session.SaveAsync(e2));
95+
await (session.FlushAsync());
96+
});
97+
Assert.That(exception.InnerException, Is.AssignableTo<DbException>());
98+
Assert.That(exception.InnerException.Message,
99+
Does.Contain("unique").IgnoreCase.And.Contains("constraint").IgnoreCase
100+
.Or.Contains("duplicate entry").IgnoreCase);
101+
}
102+
}
103+
}
104+
}

src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ public async Task EscapeCharacterAsync()
9797
}
9898
}
9999

100+
[Test, Ignore("ScrollableResults not implemented")]
101+
public async Task ScrollCriteriaAsync()
102+
{
103+
ISession session = OpenSession();
104+
ITransaction t = session.BeginTransaction();
105+
106+
Course course = new Course();
107+
course.CourseCode = "HIB";
108+
course.Description = "Hibernate Training";
109+
await (session.SaveAsync(course));
110+
await (session.FlushAsync());
111+
session.Clear();
112+
//IScrollableResults sr = session.CreateCriteria(typeof(Course)).Scroll();
113+
//Assert.IsTrue( sr.Next() );
114+
//course = (Course) sr[0];
115+
Assert.IsNotNull(course);
116+
//sr.Close();
117+
await (session.DeleteAsync(course));
118+
119+
await (t.CommitAsync());
120+
session.Close();
121+
}
122+
100123
[Test]
101124
public async Task AllowToSetLimitOnSubqueriesAsync()
102125
{
@@ -802,6 +825,93 @@ public async Task ProjectionCacheAsync()
802825
s.Close();
803826
}
804827

828+
[Test, Ignore("Not supported.")]
829+
public async Task NH_1155_ShouldNotLoadAllChildrenInPagedSubSelectAsync()
830+
{
831+
if (this.Dialect.GetType().Equals((typeof(MsSql2000Dialect))))
832+
Assert.Ignore("This is not fixed for SQL 2000 Dialect");
833+
834+
using (ISession s = OpenSession())
835+
using (ITransaction tx = s.BeginTransaction())
836+
{
837+
Course course = new Course();
838+
course.CourseCode = "HIB";
839+
course.Description = "Hibernate Training";
840+
await (s.SaveAsync(course));
841+
842+
843+
Student gavin = new Student();
844+
gavin.Name = "Gavin King";
845+
gavin.StudentNumber = 667;
846+
await (s.SaveAsync(gavin));
847+
848+
Student ayende = new Student();
849+
ayende.Name = "Ayende Rahien";
850+
ayende.StudentNumber = 1337;
851+
await (s.SaveAsync(ayende));
852+
853+
854+
Student xam = new Student();
855+
xam.Name = "Max Rydahl Andersen";
856+
xam.StudentNumber = 101;
857+
await (s.SaveAsync(xam));
858+
859+
Enrolment enrolment = new Enrolment();
860+
enrolment.Course = course;
861+
enrolment.CourseCode = course.CourseCode;
862+
enrolment.Semester = 1;
863+
enrolment.Year = 1999;
864+
enrolment.Student = xam;
865+
enrolment.StudentNumber = xam.StudentNumber;
866+
xam.Enrolments.Add(enrolment);
867+
await (s.SaveAsync(enrolment));
868+
869+
enrolment = new Enrolment();
870+
enrolment.Course = course;
871+
enrolment.CourseCode = course.CourseCode;
872+
enrolment.Semester = 3;
873+
enrolment.Year = 1998;
874+
enrolment.Student = ayende;
875+
enrolment.StudentNumber = ayende.StudentNumber;
876+
ayende.Enrolments.Add(enrolment);
877+
await (s.SaveAsync(enrolment));
878+
await (tx.CommitAsync());
879+
}
880+
881+
using (ISession s = OpenSession())
882+
{
883+
IList<Student> list = await (s.CreateCriteria(typeof(Student))
884+
.SetFirstResult(1)
885+
.SetMaxResults(10)
886+
.AddOrder(Order.Asc("StudentNumber"))
887+
.ListAsync<Student>());
888+
foreach (Student student in list)
889+
{
890+
foreach (Enrolment enrolment in student.Enrolments)
891+
{
892+
await (NHibernateUtil.InitializeAsync(enrolment));
893+
}
894+
}
895+
896+
Enrolment key = new Enrolment();
897+
key.CourseCode = "HIB";
898+
key.StudentNumber = 101;// xam
899+
//since we didn't load xam's entrollments before (skipped by orderring)
900+
//it should not be already loaded
901+
Enrolment shouldNotBeLoaded = (Enrolment)await (s.LoadAsync(typeof(Enrolment), key));
902+
Assert.IsFalse(NHibernateUtil.IsInitialized(shouldNotBeLoaded));
903+
}
904+
905+
using (ISession s = OpenSession())
906+
using (ITransaction tx = s.BeginTransaction())
907+
{
908+
await (s.DeleteAsync("from Enrolment"));
909+
await (s.DeleteAsync("from Student"));
910+
await (s.DeleteAsync("from Course"));
911+
await (tx.CommitAsync());
912+
}
913+
}
914+
805915
[Test]
806916
public async Task ProjectionsTestAsync()
807917
{

0 commit comments

Comments
 (0)