Skip to content

NH-3905 - Missings async tests #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Tools/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" />
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net461" />
<package id="NUnit.Extension.VSProjectLoader" version="3.6.0" targetFramework="net461" />
<package id="CSharpAsyncGenerator.CommandLine" version="0.3.6" targetFramework="net461" />
<package id="CSharpAsyncGenerator.CommandLine" version="0.4.0" targetFramework="net461" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for newly generated tests, due to #41, #43, #44 & #45.

</packages>
7 changes: 5 additions & 2 deletions src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@
applyChanges: true
analyzation:
methodConversion:
- conversion: Ignore
hasAttributeName: IgnoreAttribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review.

Copy link
Member Author

@fredericDelaporte fredericDelaporte Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule was causing tests from a base class overridden for marking them as NUnit [Ignored] to have their override ignored by async generator, thus having their async counterpart NUnit executed instead of being ignored.

Example of such a case in this fixture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

- conversion: Smart
hasAttributeName: TestAttribute
- conversion: Smart
Expand All @@ -180,6 +178,8 @@
hasAttributeName: IgnoreAttribute
- conversion: NewType
hasAttributeName: TestFixtureAttribute
- conversion: NewType
anyBaseTypeRule: HasTestFixtureAttribute
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for generating child classes of a base fixture if they are not themselves marked with the [Fixture] attribute.

- conversion: Ignore
rule: IsTestCase
- conversion: Ignore
Expand Down Expand Up @@ -246,3 +246,6 @@ typeRules:
- filters:
- name: TestCase
name: IsTestCase
- filters:
- hasAttributeName: TestFixtureAttribute
name: HasTestFixtureAttribute
38 changes: 38 additions & 0 deletions src/NHibernate.Test/Async/Ado/BatcherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,44 @@ public async Task OneRoundTripUpdateAsync()
await (CleanupAsync());
}

[Test, Ignore("Not fixed yet.")]
[Description("SqlClient: The batcher should run all different INSERT queries in only one roundtrip.")]
public async Task SqlClientOneRoundTripForUpdateAndInsertAsync()
{
if (Sfi.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false)
Assert.Ignore("This test is for SqlClientBatchingBatcher only");

await (FillDbAsync());

using(var sqlLog = new SqlLogSpy())
using (ISession s = Sfi.OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
await (s.SaveAsync(new VerySimple
{
Name = "test441",
Weight = 894
}));

await (s.SaveAsync(new AlmostSimple
{
Name = "test441",
Weight = 894
}));

await (tx.CommitAsync());

var log = sqlLog.GetWholeLog();
//log should only contain NHibernate.SQL once, because that means
//that we ony generated a single batch (NHibernate.SQL log will output
//once per batch)
Assert.AreEqual(0, log.IndexOf("NHibernate.SQL"), "log should start with NHibernate.SQL");
Assert.AreEqual(-1, log.IndexOf("NHibernate.SQL", "NHibernate.SQL".Length), "NHibernate.SQL should only appear once in the log");
}

await (CleanupAsync());
}

[Test]
[Description("SqlClient: The batcher log output should be formatted")]
public async Task BatchedoutputShouldBeFormattedAsync()
Expand Down
72 changes: 72 additions & 0 deletions src/NHibernate.Test/Async/Component/Basic/ComponentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,78 @@ public async Task TestComponentStateChangeAndDirtinessAsync()
}
}

[Test]
[Ignore("Ported from Hibernate. Read properties not supported in NH yet.")]
public async Task TestCustomColumnReadAndWriteAsync()
{
const double HEIGHT_INCHES = 73;
const double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;

using (ISession s = Sfi.OpenSession())
using (ITransaction t = s.BeginTransaction())
{
User u = new User("steve", "hibernater", new Person( "Steve Ebersole", new DateTime(1999, 12, 31), "Main St"));
u.Person.HeightInches = HEIGHT_INCHES;
await (s.PersistAsync(u));
await (s.FlushAsync());

// Test value conversion during insert
double heightViaSql = (double)await (s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResultAsync());
Assert.That(heightViaSql, Is.EqualTo(HEIGHT_CENTIMETERS).Within(0.01d));

// Test projection
double heightViaHql = (double)await (s.CreateQuery("select u.Person.HeightInches from User u where u.Id = 'steve'").UniqueResultAsync());
Assert.That(heightViaHql, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));

// Test restriction and entity load via criteria
u = (User)await (s.CreateCriteria(typeof(User))
.Add(Restrictions.Between("Person.HeightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d))
.UniqueResultAsync());
Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));

// Test predicate and entity load via HQL
u = (User)await (s.CreateQuery("from User u where u.Person.HeightInches between ? and ?")
.SetDouble(0, HEIGHT_INCHES - 0.01d)
.SetDouble(1, HEIGHT_INCHES + 0.01d)
.UniqueResultAsync());

Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d));

// Test update
u.Person.HeightInches = 1;
await (s.FlushAsync());
heightViaSql = (double)await (s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResultAsync());
Assert.That(heightViaSql, Is.EqualTo(2.54d).Within(0.01d));
await (s.DeleteAsync(u));
await (t.CommitAsync());
s.Close();
}
}

[Test]
[Ignore("Ported from Hibernate - failing in NH")]
public async Task TestComponentQueriesAsync()
{
using (ISession s = Sfi.OpenSession())
using (ITransaction t = s.BeginTransaction())
{
Employee emp = new Employee();
emp.HireDate = new DateTime(1999, 12, 31);
emp.Person = new Person();
emp.Person.Name = "steve";
emp.Person.Dob = new DateTime(1999, 12, 31);
await (s.SaveAsync(emp));

await (s.CreateQuery("from Employee e where e.Person = :p and 1=1 and 2=2").SetParameter("p", emp.Person).ListAsync());
await (s.CreateQuery("from Employee e where :p = e.Person").SetParameter("p", emp.Person).ListAsync());
await (s.CreateQuery("from Employee e where e.Person = ('steve', current_timestamp)").ListAsync());

await (s.DeleteAsync( emp ));
await (t.CommitAsync());
s.Close();
}
}

[Test]
public async Task TestComponentFormulaQueryAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Dialect;
using NHibernate.Exceptions;
using NHibernate.Linq;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;

namespace NHibernate.Test.Component.Basic
{
using System.Threading.Tasks;
[TestFixture]
public class ComponentWithUniqueConstraintTestsAsync : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();

mapper.Component<Person>(comp =>
{
comp.Property(p => p.Name);
comp.Property(p => p.Dob);
comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
});

mapper.Class<Employee>(cm =>
{
cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow));
cm.Property(employee => employee.HireDate);
cm.Component(person => person.Person);
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override void OnTearDown()
{
using (var session = Sfi.OpenSession())
using (var transaction = session.BeginTransaction())
{
session.Delete("from Employee");
transaction.Commit();
}
}

[Test]
public async Task CanBePersistedWithUniqueValuesAsync()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Hillary", Dob = new DateTime(2000, 1, 1) } };
await (session.SaveAsync(e1));
await (session.SaveAsync(e2));
await (transaction.CommitAsync());
}

using (var session = OpenSession())
using (session.BeginTransaction())
{
var employees = await (session.Query<Employee>().ToListAsync());
Assert.That(employees.Count, Is.EqualTo(2));
Assert.That(employees.Select(employee => employee.Person.Name).ToArray(), Is.EquivalentTo(new[] { "Hillary", "Bill" }));
}
}

[Test]
public void CannotBePersistedWithNonUniqueValuesAsync()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } };

var exception = Assert.ThrowsAsync<GenericADOException>(async () =>
{
await (session.SaveAsync(e1));
await (session.SaveAsync(e2));
await (session.FlushAsync());
});
Assert.That(exception.InnerException, Is.AssignableTo<DbException>());
Assert.That(exception.InnerException.Message,
Does.Contain("unique").IgnoreCase.And.Contains("constraint").IgnoreCase
.Or.Contains("duplicate entry").IgnoreCase);
}
}
}
}
110 changes: 110 additions & 0 deletions src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ public async Task EscapeCharacterAsync()
}
}

[Test, Ignore("ScrollableResults not implemented")]
public async Task ScrollCriteriaAsync()
{
ISession session = OpenSession();
ITransaction t = session.BeginTransaction();

Course course = new Course();
course.CourseCode = "HIB";
course.Description = "Hibernate Training";
await (session.SaveAsync(course));
await (session.FlushAsync());
session.Clear();
//IScrollableResults sr = session.CreateCriteria(typeof(Course)).Scroll();
//Assert.IsTrue( sr.Next() );
//course = (Course) sr[0];
Assert.IsNotNull(course);
//sr.Close();
await (session.DeleteAsync(course));

await (t.CommitAsync());
session.Close();
}

[Test]
public async Task AllowToSetLimitOnSubqueriesAsync()
{
Expand Down Expand Up @@ -802,6 +825,93 @@ public async Task ProjectionCacheAsync()
s.Close();
}

[Test, Ignore("Not supported.")]
public async Task NH_1155_ShouldNotLoadAllChildrenInPagedSubSelectAsync()
{
if (this.Dialect.GetType().Equals((typeof(MsSql2000Dialect))))
Assert.Ignore("This is not fixed for SQL 2000 Dialect");

using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Course course = new Course();
course.CourseCode = "HIB";
course.Description = "Hibernate Training";
await (s.SaveAsync(course));


Student gavin = new Student();
gavin.Name = "Gavin King";
gavin.StudentNumber = 667;
await (s.SaveAsync(gavin));

Student ayende = new Student();
ayende.Name = "Ayende Rahien";
ayende.StudentNumber = 1337;
await (s.SaveAsync(ayende));


Student xam = new Student();
xam.Name = "Max Rydahl Andersen";
xam.StudentNumber = 101;
await (s.SaveAsync(xam));

Enrolment enrolment = new Enrolment();
enrolment.Course = course;
enrolment.CourseCode = course.CourseCode;
enrolment.Semester = 1;
enrolment.Year = 1999;
enrolment.Student = xam;
enrolment.StudentNumber = xam.StudentNumber;
xam.Enrolments.Add(enrolment);
await (s.SaveAsync(enrolment));

enrolment = new Enrolment();
enrolment.Course = course;
enrolment.CourseCode = course.CourseCode;
enrolment.Semester = 3;
enrolment.Year = 1998;
enrolment.Student = ayende;
enrolment.StudentNumber = ayende.StudentNumber;
ayende.Enrolments.Add(enrolment);
await (s.SaveAsync(enrolment));
await (tx.CommitAsync());
}

using (ISession s = OpenSession())
{
IList<Student> list = await (s.CreateCriteria(typeof(Student))
.SetFirstResult(1)
.SetMaxResults(10)
.AddOrder(Order.Asc("StudentNumber"))
.ListAsync<Student>());
foreach (Student student in list)
{
foreach (Enrolment enrolment in student.Enrolments)
{
await (NHibernateUtil.InitializeAsync(enrolment));
}
}

Enrolment key = new Enrolment();
key.CourseCode = "HIB";
key.StudentNumber = 101;// xam
//since we didn't load xam's entrollments before (skipped by orderring)
//it should not be already loaded
Enrolment shouldNotBeLoaded = (Enrolment)await (s.LoadAsync(typeof(Enrolment), key));
Assert.IsFalse(NHibernateUtil.IsInitialized(shouldNotBeLoaded));
}

using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
await (s.DeleteAsync("from Enrolment"));
await (s.DeleteAsync("from Student"));
await (s.DeleteAsync("from Course"));
await (tx.CommitAsync());
}
}

[Test]
public async Task ProjectionsTestAsync()
{
Expand Down
Loading