-
Notifications
You must be signed in to change notification settings - Fork 933
#750 - AliasToBean failure, test case and fix #1380
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
src/NHibernate.Test/Async/NHSpecificTest/GH0750/Fixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.Collections.Generic; | ||
using NHibernate.Criterion; | ||
using NHibernate.Transform; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH0750 | ||
{ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
|
||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var greenTea = new Product() | ||
{ | ||
ProductId = 1, | ||
Name = "Green Tea", | ||
UnitPrice = 5 | ||
}; | ||
|
||
session.Save(greenTea); | ||
|
||
var blackTea = new Product() | ||
{ | ||
ProductId = 2, | ||
Name = "Black Tea", | ||
UnitPrice = 10 | ||
}; | ||
|
||
session.Save(blackTea); | ||
|
||
var greenTeaOrder = new Order() | ||
{ | ||
OrderId = 1, | ||
OrderDate = System.DateTime.Now | ||
}; | ||
|
||
session.Save(greenTeaOrder); | ||
|
||
greenTeaOrder.OrderLines.Add(new OrderLine() { Order = greenTeaOrder, Product = greenTea, Quantity = 2, UnitPrice = greenTea.UnitPrice ?? 0 }); | ||
|
||
session.Save(greenTeaOrder); | ||
|
||
var blackTeaOrder = new Order() | ||
{ | ||
OrderId = 2, | ||
OrderDate = System.DateTime.Now | ||
}; | ||
|
||
session.Save(blackTeaOrder); | ||
|
||
blackTeaOrder.OrderLines.Add(new OrderLine() { Order = blackTeaOrder, Product = blackTea, Quantity = 5, UnitPrice = blackTea.UnitPrice ?? 0 }); | ||
|
||
session.Save(blackTeaOrder); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete from OrderLine").ExecuteUpdate(); | ||
s.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void MapQueryResultWithAliasToBeanTransformerAsync() | ||
{ | ||
Assert.DoesNotThrowAsync(() => GetSaleSummariesAsync()); | ||
} | ||
|
||
public async Task<IList<ProductSummary>> GetSaleSummariesAsync(CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var criteria = session | ||
.CreateCriteria<Order>("O") | ||
.CreateCriteria("O.OrderLines", "OI", SqlCommand.JoinType.InnerJoin) | ||
.CreateCriteria("OI.Product", "P", SqlCommand.JoinType.InnerJoin); | ||
|
||
var summaeries = await (criteria | ||
.SetProjection(Projections.ProjectionList().Add(Projections.Property("P.ProductId"), "ProductId") | ||
.Add(Projections.Property("P.Name"), "Name") | ||
.Add(Projections.Sum(Projections.Cast(NHibernateUtil.Int32, Projections.Property("OI.Quantity"))), "TotalQuantity") | ||
.Add(Projections.Sum("OI.UnitPrice"), "TotalPrice") | ||
.Add(Projections.GroupProperty("P.ProductId")) | ||
.Add(Projections.GroupProperty("P.Name"))) | ||
.SetResultTransformer(Transformers.AliasToBean(typeof(ProductSummary))) | ||
.ListAsync<ProductSummary>(cancellationToken)); | ||
await (tx.CommitAsync(cancellationToken)); | ||
return summaeries; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System.Collections.Generic; | ||
using NHibernate.Criterion; | ||
using NHibernate.Transform; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH0750 | ||
{ | ||
public class ProductSummary | ||
{ | ||
public int ProductId { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public int TotalQuantity { get; set; } | ||
|
||
public decimal TotalPrice { get; set; } | ||
} | ||
|
||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction tx = session.BeginTransaction()) | ||
{ | ||
var greenTea = new Product() | ||
{ | ||
ProductId = 1, | ||
Name = "Green Tea", | ||
UnitPrice = 5 | ||
}; | ||
|
||
session.Save(greenTea); | ||
|
||
var blackTea = new Product() | ||
{ | ||
ProductId = 2, | ||
Name = "Black Tea", | ||
UnitPrice = 10 | ||
}; | ||
|
||
session.Save(blackTea); | ||
|
||
var greenTeaOrder = new Order() | ||
{ | ||
OrderId = 1, | ||
OrderDate = System.DateTime.Now | ||
}; | ||
|
||
session.Save(greenTeaOrder); | ||
|
||
greenTeaOrder.OrderLines.Add(new OrderLine() { Order = greenTeaOrder, Product = greenTea, Quantity = 2, UnitPrice = greenTea.UnitPrice ?? 0 }); | ||
|
||
session.Save(greenTeaOrder); | ||
|
||
var blackTeaOrder = new Order() | ||
{ | ||
OrderId = 2, | ||
OrderDate = System.DateTime.Now | ||
}; | ||
|
||
session.Save(blackTeaOrder); | ||
|
||
blackTeaOrder.OrderLines.Add(new OrderLine() { Order = blackTeaOrder, Product = blackTea, Quantity = 5, UnitPrice = blackTea.UnitPrice ?? 0 }); | ||
|
||
session.Save(blackTeaOrder); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was missing. Deleting all data is required by our tests, otherwise it is considered as a teardown failure. |
||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete from OrderLine").ExecuteUpdate(); | ||
s.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void MapQueryResultWithAliasToBeanTransformer() | ||
{ | ||
Assert.DoesNotThrow(() => GetSaleSummaries()); | ||
} | ||
|
||
public IList<ProductSummary> GetSaleSummaries() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var criteria = session | ||
.CreateCriteria<Order>("O") | ||
.CreateCriteria("O.OrderLines", "OI", SqlCommand.JoinType.InnerJoin) | ||
.CreateCriteria("OI.Product", "P", SqlCommand.JoinType.InnerJoin); | ||
|
||
var summaeries = criteria | ||
.SetProjection(Projections.ProjectionList().Add(Projections.Property("P.ProductId"), "ProductId") | ||
.Add(Projections.Property("P.Name"), "Name") | ||
.Add(Projections.Sum(Projections.Cast(NHibernateUtil.Int32, Projections.Property("OI.Quantity"))), "TotalQuantity") | ||
.Add(Projections.Sum("OI.UnitPrice"), "TotalPrice") | ||
.Add(Projections.GroupProperty("P.ProductId")) | ||
.Add(Projections.GroupProperty("P.Name"))) | ||
.SetResultTransformer(Transformers.AliasToBean(typeof(ProductSummary))) | ||
.List<ProductSummary>(); | ||
tx.Commit(); | ||
return summaeries; | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/NHibernate.Test/NHSpecificTest/GH0750/Mappings.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH0750"> | ||
|
||
<class name="Order" table="Orders"> | ||
<id name="OrderId" column="OrderId" type="int" unsaved-value="0" | ||
access="field.camelcase-underscore"> | ||
<generator class="assigned"/> | ||
</id> | ||
<property name="OrderDate" column="OrderDate" type="DateTime" | ||
access="field.camelcase-underscore"/> | ||
<set name="OrderLines" lazy="true" access="field.camelcase-underscore" | ||
cascade="all-delete-orphan" inverse="true"> | ||
<key column="OrderId"/> | ||
<one-to-many class="OrderLine"/> | ||
</set> | ||
</class> | ||
|
||
<class name="OrderLine" table="OrderLines"> | ||
<id name="OrderLineId" column="OrderLineId" type="int" unsaved-value="0" | ||
access="field.camelcase-underscore"> | ||
<generator class="native"/> | ||
</id> | ||
<many-to-one name="Order" class="Order" column="OrderId" not-null="true" | ||
access="field.camelcase-underscore" fetch="select"/> | ||
<many-to-one name="Product" class="Product" column="ProductId" not-null="true" | ||
access="field.camelcase-underscore" fetch="select"/> | ||
<property name="UnitPrice" column="UnitPrice" type="Decimal" | ||
not-null="true" access="field.camelcase-underscore"/> | ||
<property name="Quantity" column="Quantity" type="int" | ||
not-null="true" access="field.camelcase-underscore"/> | ||
</class> | ||
|
||
<class name="Product" table="Products"> | ||
<id name="ProductId" column="ProductId" type="int" unsaved-value="0" access="field.camelcase-underscore"> | ||
<generator class="assigned"/> | ||
</id> | ||
<property name="Name" column="ProductName" type="string" length="40" not-null="true" | ||
access="field.camelcase-underscore"/> | ||
<property name="UnitPrice" column="UnitPrice" type="Decimal" access="field.camelcase-underscore"/> | ||
<bag name="OrderLines" lazy="true" access="field.camelcase-underscore" cascade="none"> | ||
<key column="ProductId"/> | ||
<one-to-many class="OrderLine"/> | ||
</bag> | ||
</class> | ||
|
||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH0750 | ||
{ | ||
public class Order | ||
{ | ||
private readonly ISet<OrderLine> _orderLines; | ||
private DateTime? _orderDate; | ||
private int _orderId; | ||
|
||
public Order() | ||
{ | ||
_orderLines = new HashSet<OrderLine>(); | ||
} | ||
|
||
public virtual int OrderId | ||
{ | ||
get { return _orderId; } | ||
set { _orderId = value; } | ||
} | ||
|
||
public virtual DateTime? OrderDate | ||
{ | ||
get { return _orderDate; } | ||
set { _orderDate = value; } | ||
} | ||
|
||
public virtual ISet<OrderLine> OrderLines | ||
{ | ||
get { return _orderLines; } | ||
} | ||
|
||
public virtual void AddOrderLine(OrderLine orderLine) | ||
{ | ||
if (!_orderLines.Contains(orderLine)) | ||
{ | ||
orderLine.Order = this; | ||
_orderLines.Add(orderLine); | ||
} | ||
} | ||
|
||
public virtual void RemoveOrderLine(OrderLine orderLine) | ||
{ | ||
if (_orderLines.Contains(orderLine)) | ||
{ | ||
_orderLines.Remove(orderLine); | ||
orderLine.Order = null; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH0750 | ||
{ | ||
public class OrderLine | ||
{ | ||
private int _orderLineId; | ||
private Order _order; | ||
private Product _product; | ||
private int _quantity; | ||
private decimal _unitPrice; | ||
|
||
public OrderLine() : this(null, null) | ||
{ | ||
} | ||
|
||
public OrderLine(Order order, Product product) | ||
{ | ||
_order = order; | ||
_product = product; | ||
} | ||
|
||
public virtual int OrderLineId | ||
{ | ||
get { return _orderLineId; } | ||
set { _orderLineId = value; } | ||
} | ||
|
||
public virtual Order Order | ||
{ | ||
get { return _order; } | ||
set { _order = value; } | ||
} | ||
|
||
public virtual Product Product | ||
{ | ||
get { return _product; } | ||
set { _product = value; } | ||
} | ||
|
||
public virtual decimal UnitPrice | ||
{ | ||
get { return _unitPrice; } | ||
set { _unitPrice = value; } | ||
} | ||
|
||
public virtual int Quantity | ||
{ | ||
get { return _quantity; } | ||
set { _quantity = value; } | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its generation was forgotten. See this section of contributing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOPS! It was very hectic to work with VS2017 since it keeps throwing itself into NOT RESPONDING state for my install while I add/edit/rename files in test project. Would keep it in mind if needed to write another one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No troubles. Yes VS2017 is currently quite bad at handling large projects migrated to its new csproj format. That is why I had mentioned Rider, which does quite better. But maybe things will start to be better with changes like dotnet/msbuild#2572.
About writing another one, you will need to clean your master branch. But you should do it only after this PR is closed, otherwise you will need to open a new one from a dedicated branch this time.
For cleaning, in case you need instructions, it could be something like:
git branch newBranch
.git reset --hard head~x
, where x is the number of commits to remove (2 currentlygit reset --hard head~2
).git push -f
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed instructions. I will wait for this PR to close.