Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r4742, r4743 (fix NH-1990, NH-1992)
SVN: trunk@4744
- Loading branch information
1 parent
886f956
commit 856f350
Showing
7 changed files
with
242 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NHibernate.Criterion; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH1990 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction tx = s.BeginTransaction()) | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var feed = new NewsFeed | ||
{ | ||
Url = string.Format("Feed{0}Uri", i), | ||
Title = string.Format("Feed{0}", i), | ||
Status = (i % 2 == 0 ? 1 : 2) | ||
}; | ||
s.Save(feed); | ||
|
||
for (int j = 0; j < 8; j++) | ||
{ | ||
var item = new NewsItem | ||
{Title = string.Format("Feed{0}Item{1}", i, j), Status = (j % 2 == 0 ? 1 : 2), Feed = feed}; | ||
s.Save(item); | ||
} | ||
} | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction tx = s.BeginTransaction()) | ||
{ | ||
s.Delete(string.Format("from {0}", typeof (NewsItem).Name)); | ||
s.Delete(string.Format("from {0}", typeof (NewsFeed).Name)); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void FetchingBySubqueryFilterParameters() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction tx = s.BeginTransaction()) | ||
{ | ||
IFilter filter = s.EnableFilter("StatusFilter"); | ||
filter.SetParameter("Status", 1); | ||
|
||
ICriteria criteria = s.CreateCriteria(typeof (NewsFeed), "NewsFeed"); | ||
IList<NewsFeed> feeds = criteria.List<NewsFeed>(); | ||
|
||
Assert.That(feeds.Count, Is.EqualTo(5)); | ||
foreach (NewsFeed feed in feeds) | ||
{ | ||
Assert.That(feed.Items.Count, Is.EqualTo(4)); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void FetchingBySubqueryFilterParametersAndPositionalParameters() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction tx = s.BeginTransaction()) | ||
{ | ||
IFilter filter = s.EnableFilter("StatusFilter"); | ||
filter.SetParameter("Status", 1); | ||
|
||
ICriteria criteria = s.CreateCriteria(typeof (NewsFeed), "NewsFeed"); | ||
criteria.Add(Restrictions.In("Url", new[] {"Feed2Uri", "Feed4Uri", "Feed8Uri"})); | ||
|
||
IList<NewsFeed> feeds = criteria.List<NewsFeed>(); | ||
|
||
Assert.That(feeds.Count, Is.EqualTo(3)); | ||
foreach (NewsFeed feed in feeds) | ||
{ | ||
Assert.That(feed.Items.Count, Is.EqualTo(4)); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void FetchingBySubqueryFilterParametersAndPositionalParametersAndNamedParameters() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction tx = s.BeginTransaction()) | ||
{ | ||
IFilter filter = s.EnableFilter("StatusFilter"); | ||
filter.SetParameter("Status", 1); | ||
|
||
var hql = new StringBuilder(); | ||
hql.AppendLine("from NewsFeed"); | ||
hql.AppendLine("where (Url = ? or Url = ?) and Title in (:TitleList)) "); | ||
|
||
IQuery query = s.CreateQuery(hql.ToString()); | ||
query.SetString(0, "Feed4Uri"); | ||
query.SetString(1, "Feed8Uri"); | ||
query.SetParameterList("TitleList", new[] {"Feed2", "Feed4", "Feed8"}); | ||
|
||
IList<NewsFeed> feeds = query.List<NewsFeed>(); | ||
|
||
Assert.That(feeds.Count, Is.EqualTo(2)); | ||
foreach (NewsFeed feed in feeds) | ||
{ | ||
Assert.That(feed.Items.Count, Is.EqualTo(4)); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/NHibernate.Test/NHSpecificTest/NH1990/Mappings.hbm.xml
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,37 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
namespace="NHibernate.Test.NHSpecificTest.NH1990" | ||
assembly="NHibernate.Test"> | ||
|
||
<class name="NewsFeed" table="NWS_Feed" batch-size="100"> | ||
<id name="Id" type="Guid" column="OID"> | ||
<generator class="guid"></generator> | ||
</id> | ||
<property name="Title" type="String" not-null="true"/> | ||
<property name="Url" type="String" not-null="true"/> | ||
<property name="Status" type="Int32" not-null="true"/> | ||
<bag name="Items" cascade="all" fetch="subselect" inverse="true" > | ||
<key column="FK_Feed_OID"/> | ||
<one-to-many class="NewsItem"></one-to-many> | ||
<filter name="StatusFilter" condition=":Status=Status" /> | ||
</bag> | ||
<filter name="StatusFilter" condition=":Status=Status" /> | ||
</class> | ||
|
||
<class name="NewsItem" table="NWS_Item" batch-size="100"> | ||
<id name="Id" type="Guid" column="OID"> | ||
<generator class="guid"></generator> | ||
</id> | ||
<property name="Title" type="String" not-null="true"/> | ||
<property name="Status" type="Int32" not-null="true"/> | ||
<many-to-one name="Feed" class="NewsFeed" column="FK_Feed_OID" not-null="true"/> | ||
|
||
<filter name="StatusFilter" condition=":Status=Status" /> | ||
</class> | ||
|
||
<filter-def name="StatusFilter"> | ||
<filter-param name="Status" type="Int32"/> | ||
</filter-def> | ||
</hibernate-mapping> | ||
|
||
|
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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH1990 | ||
{ | ||
public class NewsFeed | ||
{ | ||
public NewsFeed() | ||
{ | ||
Items = new List<NewsItem>(); | ||
} | ||
|
||
public virtual Guid Id { get; set; } | ||
public virtual string Title { get; set; } | ||
public virtual string Url { get; set; } | ||
public virtual int Status { get; set; } | ||
public virtual IList<NewsItem> Items { get; set; } | ||
} | ||
|
||
public class NewsItem | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Title { get; set; } | ||
public virtual int Status { get; set; } | ||
public virtual NewsFeed Feed { get; set; } | ||
} | ||
} |
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,23 @@ | ||
using NHibernate.AdoNet.Util; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.UtilityTest | ||
{ | ||
[TestFixture] | ||
public class BasicFormatterFixture | ||
{ | ||
[Test] | ||
public void StringWithNestedDelimiters() | ||
{ | ||
string formattedSql = null; | ||
IFormatter formatter = new BasicFormatter(); | ||
string sql = @"INSERT INTO Table (Name, id) VALUES (@p0, @p1); @p0 = 'a'(b', @p1 = 1"; | ||
Assert.DoesNotThrow(() => formattedSql = formatter.Format(sql)); | ||
Assert.That(formattedSql, Text.Contains("'a'(b'")); | ||
|
||
sql = @"UPDATE Table SET Column = @p0;@p0 = '(')'"; | ||
Assert.DoesNotThrow(() => formattedSql = formatter.Format(sql)); | ||
Assert.That(formattedSql, Text.Contains("'(')'")); | ||
} | ||
} | ||
} |
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