-
Notifications
You must be signed in to change notification settings - Fork 934
NH-3727 - Unit tests showing bug and bugfix proposition #364
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78096e6
NH3727 unittest showing bug
itmagination d181f6c
NH3727 bugfix proposition
itmagination 8c9686b
NH3727 bugfix proposition - missing csproj update
itmagination 76832ca
Formatting fix: indentations by tabs instead of spaces.
itmagination 84adfa4
Formatting fix (FixtureByCode.cs): indentations by tabs instead of sp…
itmagination 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
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,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3727 | ||
{ | ||
class Entity | ||
{ | ||
public virtual int Id { get; set; } | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.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,93 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Criterion; | ||
using NHibernate.Impl; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Transform; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3727 | ||
{ | ||
public class ByCodeFixture : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(rc => | ||
{ | ||
rc.Id(x => x.Id); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
[Test] | ||
public void QueryOverWithSubqueryProjectionCanBeExecutedMoreThanOnce() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
const int parameter1 = 111; | ||
|
||
var countSubquery = QueryOver.Of<Entity>() | ||
.Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter | ||
.Select(Projections.RowCount()) | ||
; | ||
|
||
var originalQueryOver = session.QueryOver<Entity>() | ||
.SelectList(l => l | ||
.Select(x => x.Id) | ||
.SelectSubQuery(countSubquery) | ||
) | ||
.TransformUsing(Transformers.ToList); | ||
|
||
originalQueryOver.List<object>(); | ||
|
||
Assert.DoesNotThrow(() => originalQueryOver.List<object>(), "Second try to execute QueryOver thrown exception."); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ClonedQueryOverExecutionMakesOriginalQueryOverNotWorking() | ||
{ | ||
// Projections are copied by clone operation. | ||
// SubqueryProjection use SubqueryExpression which holds CriteriaQueryTranslator (class SubqueryExpression { private CriteriaQueryTranslator innerQuery; }) | ||
// So given CriteriaQueryTranslator is used twice. | ||
// Since CriteriaQueryTranslator has CollectedParameters collection, second execution of the Criteria does not fit SqlCommand parameters. | ||
|
||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
const int parameter1 = 111; | ||
|
||
var countSubquery = QueryOver.Of<Entity>() | ||
.Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter | ||
.Select(Projections.RowCount()) | ||
; | ||
|
||
var originalQueryOver = session.QueryOver<Entity>() | ||
//.Where(x => x.Id == parameter2) | ||
.SelectList(l => l | ||
.Select(x => x.Id) | ||
.SelectSubQuery(countSubquery) | ||
) | ||
.TransformUsing(Transformers.ToList); | ||
|
||
var clonedQueryOver = originalQueryOver.Clone(); | ||
clonedQueryOver.List<object>(); | ||
|
||
Assert.DoesNotThrow(() => originalQueryOver.List<object>(), "Cloned QueryOver execution caused source QueryOver throw exception when executed."); | ||
} | ||
} | ||
|
||
private static IEnumerable<IProjection> GetProjectionList(IQueryOver<Entity, Entity> clonedQueryOver) | ||
{ | ||
var projectionList = (((CriteriaImpl)clonedQueryOver.RootCriteria).Projection as ProjectionList); | ||
for (int i = 0; i < projectionList.Length; i++) | ||
{ | ||
yield return projectionList[i]; | ||
} | ||
} | ||
} | ||
} |
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
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
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.
Can you please make usual method overload?