-
Notifications
You must be signed in to change notification settings - Fork 936
/
Copy pathFixture.cs
106 lines (95 loc) · 2.64 KB
/
Fixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.Collections;
using System.Linq;
using NUnit.Framework;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq.Dynamic.Core;
namespace NHibernate.Test.NHSpecificTest.NH2664Dynamic
{
[TestFixture]
public class Fixture : TestCase
{
protected override string MappingsAssembly => "NHibernate.Test";
protected override string[] Mappings => new[] {"NHSpecificTest.NH2664Dynamic.Mappings.hbm.xml"};
/// <summary>
/// push some data into the database
/// Really functions as a save test also
/// </summary>
protected override void OnSetUp()
{
using (var session = OpenSession())
using (var tran = session.BeginTransaction())
{
var properties1 = new Dictionary<string, object>
{
["Name"] = "First Product",
["Description"] = "First Description"
};
session.Save(
new Product
{
ProductId = "1",
Properties = properties1
});
var properties2 = new
{
Name = "Second Product",
Description = "Second Description"
};
session.Save(
new Product
{
ProductId = "2",
Properties = properties2
});
dynamic properties3 = new ExpandoObject();
properties3.Name = "Third Product";
properties3.Description = "Third Description";
session.Save(
new Product
{
ProductId = "3",
Properties = properties3
});
tran.Commit();
}
}
protected override void OnTearDown()
{
using (var session = OpenSession())
using (var tran = session.BeginTransaction())
{
session.CreateQuery("delete from Product").ExecuteUpdate();
tran.Commit();
}
}
[Test]
public void Query_DynamicComponent()
{
using (var session = OpenSession())
{
var product = session
.Query<Product>()
.Where("Properties.Name == @0", "First Product")
.Single();
Assert.That(product, Is.Not.Null);
Assert.That((object) product.Properties["Name"], Is.EqualTo("First Product"));
Assert.That((object) product.Properties.Name, Is.EqualTo("First Product"));
}
}
[Test]
public void Multiple_Query_Does_Not_Cache()
{
using (var session = OpenSession())
{
// Query by name
var product1 = session.Query<Product>().Where("Properties.Name == @0", "First Product").Single();
Assert.That(product1.ProductId, Is.EqualTo("1"));
// Query by description (this test is to verify that the dictionary
// index isn't cached from the query above.
var product2 = session.Query<Product>().Where("Properties.Description == @0", "Second Description").Single();
Assert.That(product2.ProductId, Is.EqualTo("2"));
}
}
}
}