Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote branch 'remotes/origin/nh-2500'
- Loading branch information
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Linq; | ||
using NHibernate.Mapping.ByCode; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH2500 | ||
{ | ||
public class Foo | ||
{ | ||
public virtual Guid Id { get; set; } | ||
|
||
public virtual string Name { get; set; } | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class Fixture : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ConventionModelMapper(); | ||
mapper.BeforeMapClass += (mi, t, x) => x.Id(map => map.Generator(Generators.Guid)); | ||
return mapper.CompileMappingFor(new[] { typeof(Foo) }); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
base.OnSetUp(); | ||
|
||
using (ISession session = Sfi.OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.Persist(new Foo { Name = "Banana" }); | ||
session.Persist(new Foo { Name = "Egg" }); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession session = Sfi.OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from Foo").ExecuteUpdate(); | ||
transaction.Commit(); | ||
} | ||
|
||
base.OnTearDown(); | ||
} | ||
|
||
private int count; | ||
|
||
[Test] | ||
public void TestLinqProjectionExpressionDoesntCacheParameters() | ||
{ | ||
using (ISession session = Sfi.OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
this.count = 1; | ||
|
||
var foos1 = session.Query<Foo>() | ||
.Where(x => x.Name == "Banana") | ||
.Select(x => new | ||
{ | ||
x.Name, | ||
count, | ||
User = "abc" | ||
}).First(); | ||
|
||
this.count = 2; | ||
|
||
var foos2 = session.Query<Foo>() | ||
.Where(x => x.Name == "Egg") | ||
.Select(x => new | ||
{ | ||
x.Name, | ||
count, | ||
User = "def" | ||
}).First(); | ||
|
||
Assert.AreEqual(1, foos1.count); | ||
Assert.AreEqual(2, foos2.count); | ||
Assert.AreEqual("abc", foos1.User); | ||
Assert.AreEqual("def", foos2.User); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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