Skip to content

Commit 38f7d59

Browse files
authored
Merge branch 'master' into notMappedLinq
2 parents 589b6dd + 9a5a50e commit 38f7d59

File tree

23 files changed

+338
-250
lines changed

23 files changed

+338
-250
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,22 @@ public async Task SubcriteriaJoinTypesAsync()
24412441
session.Close();
24422442
}
24432443

2444+
public class NotMappedEntity
2445+
{
2446+
public virtual int Id { get; set; }
2447+
public virtual string Name { get; set; }
2448+
}
2449+
2450+
[Test]
2451+
public void CriteriaOnNotMappedEntityAsync()
2452+
{
2453+
using (ISession session = OpenSession())
2454+
{
2455+
Assert.ThrowsAsync<QueryException>(
2456+
() => session.CreateCriteria(typeof(NotMappedEntity)).ListAsync());
2457+
}
2458+
}
2459+
24442460
[Test]
24452461
public void TypeMismatchAsync()
24462462
{

src/NHibernate.Test/Async/Events/Collections/AbstractCollectionEventFixture.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//------------------------------------------------------------------------------
99

1010

11+
using System;
1112
using System.Collections;
1213
using System.Collections.Generic;
1314
using NHibernate.Collection;
@@ -38,30 +39,12 @@ protected override string MappingsAssembly
3839

3940
protected override void OnTearDown()
4041
{
41-
IParentWithCollection dummyParent = CreateParent("dummyParent");
42-
dummyParent.NewChildren(CreateCollection());
43-
IChild dummyChild = dummyParent.AddChild("dummyChild");
44-
45-
using (ISession s = OpenSession())
42+
using (var s = OpenSession())
43+
using (var tx = s.BeginTransaction())
4644
{
47-
using (ITransaction tx = s.BeginTransaction())
48-
{
49-
IList children = s.CreateCriteria(dummyChild.GetType()).List();
50-
IList parents = s.CreateCriteria(dummyParent.GetType()).List();
51-
foreach (IParentWithCollection parent in parents)
52-
{
53-
parent.ClearChildren();
54-
s.Delete(parent);
55-
}
56-
foreach (IChild child in children)
57-
{
58-
s.Delete(child);
59-
}
60-
61-
tx.Commit();
62-
}
45+
s.Delete("from System.Object");
46+
tx.Commit();
6347
}
64-
base.OnTearDown();
6548
}
6649

6750
[Test]

src/NHibernate.Test/Async/Linq/WhereSubqueryTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
using System;
1212
using System.Linq;
1313
using System.Linq.Expressions;
14+
using NHibernate.Dialect;
1415
using NHibernate.DomainModel.Northwind.Entities;
15-
using NUnit.Framework;
1616
using NHibernate.Linq;
17+
using NUnit.Framework;
1718

1819
namespace NHibernate.Test.Linq
1920
{
@@ -465,6 +466,42 @@ where subquery.Any(x => x.OrderId == order.OrderId)
465466
Assert.That(query.Count, Is.EqualTo(61));
466467
}
467468

469+
[Test(Description = "GH2479")]
470+
public async Task OrdersWithSubquery11Async()
471+
{
472+
if (Dialect is MySQLDialect)
473+
Assert.Ignore("MySQL does not support LIMIT in subqueries.");
474+
if (Dialect is MsSqlCeDialect)
475+
Assert.Ignore("MS SQL CE does not support sorting on a subquery.");
476+
477+
var ordersQuery = db.Orders
478+
.OrderByDescending(x => x.OrderLines.Count).ThenBy(x => x.OrderId)
479+
.Take(2);
480+
481+
var orderLineQuery = ordersQuery.SelectMany(x => x.OrderLines);
482+
var productsNotInLargestOrders = await (db.Products
483+
.Where(x => orderLineQuery.All(p => p.Product != x))
484+
.OrderBy(x => x.ProductId)
485+
.ToListAsync());
486+
487+
Assert.That(productsNotInLargestOrders.Count, Is.EqualTo(49), nameof(productsNotInLargestOrders));
488+
}
489+
490+
[Test]
491+
public async Task OrdersWithSubquery11AAsync()
492+
{
493+
var ordersQuery = db.Orders
494+
.OrderByDescending(x => x.OrderLines.Count).ThenBy(x => x.OrderId);
495+
496+
var orderLineQuery = ordersQuery.SelectMany(x => x.OrderLines);
497+
var productsNotInLargestOrders = await (db.Products
498+
.Where(x => orderLineQuery.All(p => p.Product != x))
499+
.OrderBy(x => x.ProductId)
500+
.ToListAsync());
501+
502+
Assert.That(productsNotInLargestOrders.Count, Is.EqualTo(0), nameof(productsNotInLargestOrders));
503+
}
504+
468505
[Test(Description = "NH-2654")]
469506
public async Task CategoriesWithDiscountedProductsAsync()
470507
{

src/NHibernate.Test/Async/NHSpecificTest/NH1159/Fixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public async Task DoesNotFlushWithCriteriaWithCommitAsync()
5959

6060
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(1));
6161

62-
ICriteria query = session.CreateCriteria(typeof(ContactTitle));
62+
ICriteria query = session.CreateCriteria(typeof(Contact));
6363
query.Add(Expression.Eq("Id", (Int64)1));
64-
await (query.UniqueResultAsync<ContactTitle>());
64+
await (query.UniqueResultAsync<Contact>());
6565

6666
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(1));
6767

@@ -89,9 +89,9 @@ public async Task DoesNotFlushWithCriteriaWithNeverAsync()
8989

9090
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(1));
9191

92-
ICriteria query = session.CreateCriteria(typeof(ContactTitle));
92+
ICriteria query = session.CreateCriteria(typeof(Contact));
9393
query.Add(Expression.Eq("Id", (Int64)1));
94-
await (query.UniqueResultAsync<ContactTitle>());
94+
await (query.UniqueResultAsync<Contact>());
9595

9696
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(1));
9797

@@ -120,9 +120,9 @@ public async Task DoesNotFlushWithCriteriaWithAutoAsync()
120120

121121
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(1));
122122

123-
ICriteria query = session.CreateCriteria(typeof(ContactTitle));
123+
ICriteria query = session.CreateCriteria(typeof(Contact));
124124
query.Add(Expression.Eq("Id", (Int64)1));
125-
await (query.UniqueResultAsync<ContactTitle>());
125+
await (query.UniqueResultAsync<Contact>());
126126

127127
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(2));
128128

src/NHibernate.Test/Async/NHSpecificTest/NH1688/Fixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected override void OnTearDown()
6868
{
6969
using (ISession session = OpenSession())
7070
{
71-
DetachedCriteria criteria = DetachedCriteria.For<NH1679.DomainClass>("alias");
71+
DetachedCriteria criteria = DetachedCriteria.For<DomainClass>("alias");
7272

7373
action.Invoke(criteria);
7474

@@ -77,4 +77,4 @@ protected override void OnTearDown()
7777
}
7878
}
7979
}
80-
}
80+
}

src/NHibernate.Test/Async/TransactionTest/TransactionNotificationFixture.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System;
1212
using System.Data;
1313
using System.Data.Common;
14+
using NHibernate.Cfg;
15+
using NHibernate.Mapping.ByCode;
1416
using NHibernate.Transaction;
1517
using NUnit.Framework;
1618

@@ -21,7 +23,27 @@ namespace NHibernate.Test.TransactionTest
2123
[TestFixture]
2224
public class TransactionNotificationFixtureAsync : TestCase
2325
{
24-
protected override string[] Mappings => Array.Empty<string>();
26+
public class Entity
27+
{
28+
public virtual int Id { get; set; }
29+
public virtual string Name { get; set; }
30+
}
31+
32+
protected override string[] Mappings => null;
33+
34+
protected override void AddMappings(Configuration configuration)
35+
{
36+
var modelMapper = new ModelMapper();
37+
modelMapper.Class<Entity>(
38+
x =>
39+
{
40+
x.Id(e => e.Id);
41+
x.Property(e => e.Name);
42+
x.Table(nameof(Entity));
43+
});
44+
45+
configuration.AddMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities());
46+
}
2547

2648
[Test]
2749
public async Task CommitAsync()

src/NHibernate.Test/Criteria/CriteriaQueryTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,22 @@ public void SubcriteriaJoinTypes()
25382538
session.Close();
25392539
}
25402540

2541+
public class NotMappedEntity
2542+
{
2543+
public virtual int Id { get; set; }
2544+
public virtual string Name { get; set; }
2545+
}
2546+
2547+
[Test]
2548+
public void CriteriaOnNotMappedEntity()
2549+
{
2550+
using (ISession session = OpenSession())
2551+
{
2552+
Assert.Throws<QueryException>(
2553+
() => session.CreateCriteria(typeof(NotMappedEntity)).List());
2554+
}
2555+
}
2556+
25412557
[Test]
25422558
public void TypeMismatch()
25432559
{

src/NHibernate.Test/Events/Collections/AbstractCollectionEventFixture.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using NHibernate.Collection;
@@ -26,30 +27,12 @@ protected override string MappingsAssembly
2627

2728
protected override void OnTearDown()
2829
{
29-
IParentWithCollection dummyParent = CreateParent("dummyParent");
30-
dummyParent.NewChildren(CreateCollection());
31-
IChild dummyChild = dummyParent.AddChild("dummyChild");
32-
33-
using (ISession s = OpenSession())
30+
using (var s = OpenSession())
31+
using (var tx = s.BeginTransaction())
3432
{
35-
using (ITransaction tx = s.BeginTransaction())
36-
{
37-
IList children = s.CreateCriteria(dummyChild.GetType()).List();
38-
IList parents = s.CreateCriteria(dummyParent.GetType()).List();
39-
foreach (IParentWithCollection parent in parents)
40-
{
41-
parent.ClearChildren();
42-
s.Delete(parent);
43-
}
44-
foreach (IChild child in children)
45-
{
46-
s.Delete(child);
47-
}
48-
49-
tx.Commit();
50-
}
33+
s.Delete("from System.Object");
34+
tx.Commit();
5135
}
52-
base.OnTearDown();
5336
}
5437

5538
[Test]

0 commit comments

Comments
 (0)