Skip to content

Commit 03eb294

Browse files
committed
NHSpecificTest/NH3571/*: Various minor cleanups.
1 parent 1b9d14d commit 03eb294

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/NHibernate.Test/NHSpecificTest/NH3571/Fixture.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@ protected override void OnSetUp()
3838
{
3939
using (var tran = session.BeginTransaction())
4040
{
41-
Product product = new Product();
42-
product.ProductId = "1";
41+
var product = new Product {ProductId = "1"};
4342
product.Details.Properties["Name"] = "First Product";
4443
product.Details.Properties["Description"] = "First Description";
4544

4645
session.Save(product);
4746

48-
product = new Product();
49-
product.ProductId = "2";
47+
product = new Product {ProductId = "2"};
5048
product.Details.Properties["Name"] = "Second Product";
5149
product.Details.Properties["Description"] = "Second Description";
5250

5351
session.Save(product);
5452

55-
product = new Product();
56-
product.ProductId = "3";
53+
product = new Product {ProductId = "3"};
5754
product.Details.Properties["Name"] = "val";
5855
product.Details.Properties["Description"] = "val";
5956

@@ -80,50 +77,52 @@ protected override void OnTearDown()
8077
}
8178

8279
[Test]
83-
public void Query_DynamicComponent_In_Component()
80+
public void CanQueryDynamicComponentInComponent()
8481
{
8582
using (var session = OpenSession())
8683
{
8784
var query = session.CreateQuery("from Product p where p.Details.Properties.Name=:name");
8885
query.SetString("name", "First Product");
8986
//var product = query.List<Product>().FirstOrDefault();
9087
var product =
91-
(from p in session.Query<Product>() where p.Details.Properties["Name"] == "First Product" select p).Single();
88+
(from p in session.Query<Product>() where (string) p.Details.Properties["Name"] == "First Product" select p).Single();
9289

9390
Assert.IsNotNull(product);
9491
Assert.AreEqual("First Product", product.Details.Properties["Name"]);
9592
}
9693
}
9794

98-
9995

10096
[Test]
101-
public void Multiple_Query_Does_Not_Cache()
97+
public void MultipleQueriesShouldNotCache()
10298
{
10399
using (var session = OpenSession())
104100
{
105101
// Query by name
106102
var product1 = (from p in session.Query<Product>()
107-
where p.Details.Properties["Name"] == "First Product"
103+
where (string) p.Details.Properties["Name"] == "First Product"
108104
select p).Single();
109105
Assert.That(product1.ProductId, Is.EqualTo("1"));
110106

111107
// Query by description (this test is to verify that the dictionary
112108
// index isn't cached from the query above.
113109
var product2 = (from p in session.Query<Product>()
114-
where p.Details.Properties["Description"] == "Second Description"
110+
where (string) p.Details.Properties["Description"] == "Second Description"
115111
select p).Single();
116112
Assert.That(product2.ProductId, Is.EqualTo("2"));
117113
}
118114
}
119115

116+
120117
[Test]
121-
public void Different_Key_In_DynamicComponentDictionary_Returns_Different_Keys()
118+
public void DifferentKeyInDynamicComponentDictionaryReturnsDifferentExpressionKeys()
122119
{
123120
using (var session = OpenSession())
124121
{
125-
Expression<Func<IEnumerable>> key1 = () => (from a in session.Query<Product>() where a.Details.Properties["Name"] == "val" select a);
126-
Expression<Func<IEnumerable>> key2 = () => (from a in session.Query<Product>() where a.Details.Properties["Description"] == "val" select a);
122+
// ReSharper disable AccessToDisposedClosure Ok since the expressions aren't actually used after the using block.
123+
Expression<Func<IEnumerable>> key1 = () => (from a in session.Query<Product>() where (string) a.Details.Properties["Name"] == "val" select a);
124+
Expression<Func<IEnumerable>> key2 = () => (from a in session.Query<Product>() where (string) a.Details.Properties["Description"] == "val" select a);
125+
// ReSharper restore AccessToDisposedClosure
127126

128127
var nhKey1 = new NhLinqExpression(key1.Body, sessions);
129128
var nhKey2 = new NhLinqExpression(key2.Body, sessions);
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
33
namespace="NHibernate.Test.NHSpecificTest.NH3571">
4-
<class name="Product" table="Products">
5-
<id name="ProductId" column="ProductId" type="String">
6-
<generator class="assigned" />
4+
<class name="Product" table="Products">
5+
<id name="ProductId" column="ProductId" type="String">
6+
<generator class="assigned" />
77

8-
</id>
9-
<component name="Details" class="ProductDetails">
10-
<dynamic-component name="Properties">
11-
<property name="Description" column="Description" type="String"/>
12-
<property name="Name" column="Name" type="String" />
13-
</dynamic-component>
14-
</component>
15-
</class>
8+
</id>
9+
<component name="Details" class="ProductDetails">
10+
<dynamic-component name="Properties">
11+
<property name="Description" column="Description" type="String"/>
12+
<property name="Name" column="Name" type="String" />
13+
</dynamic-component>
14+
</component>
15+
</class>
1616

1717
</hibernate-mapping>

src/NHibernate.Test/NHSpecificTest/NH3571/Product.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Product
77
{
88
public Product()
99
{
10-
Details=new ProductDetails();
10+
Details = new ProductDetails();
1111
}
1212
public virtual string ProductId { get; set; }
1313

0 commit comments

Comments
 (0)