Skip to content
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

Modernize the test case example #3484

Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,45 @@ public class FixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity {Name = "Bob"};
session.Save(e1);
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var e2 = new Entity {Name = "Sally"};
session.Save(e2);
var e1 = new Entity { Name = "Bob" };
session.Save(e1);

transaction.Commit();
}
var e2 = new Entity { Name = "Sally" };
session.Save(e2);

transaction.Commit();
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();
using var session = OpenSession();
using var transaction = session.BeginTransaction();

// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
transaction.Commit();
}

[Test]
public async Task YourTestNameAsync()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session
.Query<Entity>()
.Where(e => e.Name == "Bob");
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
}
await (transaction.CommitAsync());
}
}
}
60 changes: 29 additions & 31 deletions src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000
/// Fixture using 'by code' mappings
/// </summary>
/// <remarks>
/// This fixture is identical to <see cref="FixtureAsync" /> except the <see cref="Entity" /> mapping is performed
/// This fixture is identical to <see cref="FixtureAsync" /> except the <see cref="Entity" /> mapping is performed
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
/// if you prefer.
/// </remarks>
[TestFixture]
public class ByCodeFixtureAsync : TestCaseMappingByCode
public class FixtureByCodeAsync : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
Expand All @@ -42,48 +42,46 @@ protected override HbmMapping GetMappings()

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity { Name = "Bob" };
session.Save(e1);
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var e1 = new Entity { Name = "Bob" };
session.Save(e1);

var e2 = new Entity { Name = "Sally" };
session.Save(e2);
var e2 = new Entity { Name = "Sally" };
session.Save(e2);

transaction.Commit();
}
transaction.Commit();
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHbernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();
using var session = OpenSession();
using var transaction = session.BeginTransaction();

// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHbernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
transaction.Commit();
}

[Test]
public async Task YourTestNameAsync()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session
.Query<Entity>()
.Where(e => e.Name == "Bob");

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
await (transaction.CommitAsync());
}
await (transaction.CommitAsync());
}
}
}
58 changes: 28 additions & 30 deletions src/NHibernate.Test/NHSpecificTest/GH0000/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,45 @@ public class Fixture : BugTestCase
{
protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity {Name = "Bob"};
session.Save(e1);
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var e2 = new Entity {Name = "Sally"};
session.Save(e2);
var e1 = new Entity { Name = "Bob" };
session.Save(e1);

transaction.Commit();
}
var e2 = new Entity { Name = "Sally" };
session.Save(e2);

transaction.Commit();
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
using var session = OpenSession();
using var transaction = session.BeginTransaction();

// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}

[Test]
public void YourTestName()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;

Assert.That(result.ToList(), Has.Count.EqualTo(1));
}
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session
.Query<Entity>()
.Where(e => e.Name == "Bob");
Assert.That(result.ToList(), Has.Count.EqualTo(1));

transaction.Commit();
}
}
}
60 changes: 29 additions & 31 deletions src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000
/// Fixture using 'by code' mappings
/// </summary>
/// <remarks>
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
/// if you prefer.
/// </remarks>
[TestFixture]
public class ByCodeFixture : TestCaseMappingByCode
public class FixtureByCode : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
Expand All @@ -30,48 +30,46 @@ protected override HbmMapping GetMappings()

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity { Name = "Bob" };
session.Save(e1);
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var e1 = new Entity { Name = "Bob" };
session.Save(e1);

var e2 = new Entity { Name = "Sally" };
session.Save(e2);
var e2 = new Entity { Name = "Sally" };
session.Save(e2);

transaction.Commit();
}
transaction.Commit();
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHbernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();
using var session = OpenSession();
using var transaction = session.BeginTransaction();

// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHbernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
transaction.Commit();
}

[Test]
public void YourTestName()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session
.Query<Entity>()
.Where(e => e.Name == "Bob");

Assert.That(result.ToList(), Has.Count.EqualTo(1));

Assert.That(result.ToList(), Has.Count.EqualTo(1));
transaction.Commit();
}
transaction.Commit();
}
}
}
Loading