Mercurial > pub > bltoolkit
comparison UnitTests/Linq/ProviderSpecific/PostgreSQL.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Linq; | |
3 | |
4 using BLToolkit.Data.Linq; | |
5 using BLToolkit.Data.DataProvider; | |
6 using BLToolkit.DataAccess; | |
7 using BLToolkit.Mapping; | |
8 | |
9 using NUnit.Framework; | |
10 | |
11 using UnitTests.Linq.Interface.Model; | |
12 | |
13 namespace Data.Linq.ProviderSpecific | |
14 { | |
15 [TestFixture, Category("PostgreSQL")] | |
16 public class PostgreSQL : TestBase | |
17 { | |
18 [TableName(Owner="public", Name="entity")] | |
19 public class Entity | |
20 { | |
21 [MapField("the_name") ] public string TheName { get; set; } | |
22 } | |
23 | |
24 [Test] | |
25 public void SqlTest1([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
26 { | |
27 using (var db = new TestDbManager(context)) | |
28 { | |
29 db.BeginTransaction(); | |
30 | |
31 db | |
32 .SetSpCommand("add_if_not_exists", db.Parameter("p_name", "one")) | |
33 .ExecuteNonQuery(); | |
34 | |
35 db.Insert(new Entity { TheName = "two" }); | |
36 } | |
37 } | |
38 | |
39 [Test] | |
40 public void SequenceInsert1([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
41 { | |
42 using (var db = new TestDbManager(context)) | |
43 { | |
44 db.GetTable<PostgreSQLSpecific.SequenceTest1>().Where(_ => _.Value == "SeqValue").Delete(); | |
45 db.Insert(new PostgreSQLSpecific.SequenceTest1 { Value = "SeqValue" }); | |
46 | |
47 var id = db.GetTable<PostgreSQLSpecific.SequenceTest1>().Single(_ => _.Value == "SeqValue").ID; | |
48 | |
49 db.GetTable<PostgreSQLSpecific.SequenceTest1>().Where(_ => _.ID == id).Delete(); | |
50 | |
51 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest1>().Count(_ => _.Value == "SeqValue")); | |
52 } | |
53 } | |
54 | |
55 [Test] | |
56 public void SequenceInsert2([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
57 { | |
58 using (var db = new TestDbManager(context)) | |
59 { | |
60 db.GetTable<PostgreSQLSpecific.SequenceTest2>().Where(_ => _.Value == "SeqValue").Delete(); | |
61 db.Insert(new PostgreSQLSpecific.SequenceTest2 { Value = "SeqValue" }); | |
62 | |
63 var id = db.GetTable<PostgreSQLSpecific.SequenceTest2>().Single(_ => _.Value == "SeqValue").ID; | |
64 | |
65 db.GetTable<PostgreSQLSpecific.SequenceTest2>().Where(_ => _.ID == id).Delete(); | |
66 | |
67 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest2>().Count(_ => _.Value == "SeqValue")); | |
68 } | |
69 } | |
70 | |
71 [Test] | |
72 public void SequenceInsert3([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
73 { | |
74 using (var db = new TestDbManager(context)) | |
75 { | |
76 db.GetTable<PostgreSQLSpecific.SequenceTest3>().Where(_ => _.Value == "SeqValue").Delete(); | |
77 db.Insert(new PostgreSQLSpecific.SequenceTest3 { Value = "SeqValue" }); | |
78 | |
79 var id = db.GetTable<PostgreSQLSpecific.SequenceTest3>().Single(_ => _.Value == "SeqValue").ID; | |
80 | |
81 db.GetTable<PostgreSQLSpecific.SequenceTest3>().Where(_ => _.ID == id).Delete(); | |
82 | |
83 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest3>().Count(_ => _.Value == "SeqValue")); | |
84 } | |
85 } | |
86 | |
87 [Test] | |
88 public void SequenceInsertWithIdentity1([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
89 { | |
90 using (var db = new TestDbManager(context)) | |
91 { | |
92 db.GetTable<PostgreSQLSpecific.SequenceTest1>().Where(_ => _.Value == "SeqValue").Delete(); | |
93 | |
94 var id1 = Convert.ToInt32(db.InsertWithIdentity(new PostgreSQLSpecific.SequenceTest1 { Value = "SeqValue" })); | |
95 var id2 = db.GetTable<PostgreSQLSpecific.SequenceTest1>().Single(_ => _.Value == "SeqValue").ID; | |
96 | |
97 Assert.AreEqual(id1, id2); | |
98 | |
99 db.GetTable<PostgreSQLSpecific.SequenceTest1>().Where(_ => _.ID == id1).Delete(); | |
100 | |
101 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest1>().Count(_ => _.Value == "SeqValue")); | |
102 } | |
103 } | |
104 | |
105 [Test] | |
106 public void SequenceInsertWithIdentity2([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
107 { | |
108 using (var db = new TestDbManager(context)) | |
109 { | |
110 db.GetTable<PostgreSQLSpecific.SequenceTest2>().Where(_ => _.Value == "SeqValue").Delete(); | |
111 | |
112 var id1 = Convert.ToInt32(db.InsertWithIdentity(new PostgreSQLSpecific.SequenceTest2 { Value = "SeqValue" })); | |
113 var id2 = db.GetTable<PostgreSQLSpecific.SequenceTest2>().Single(_ => _.Value == "SeqValue").ID; | |
114 | |
115 Assert.AreEqual(id1, id2); | |
116 | |
117 db.GetTable<PostgreSQLSpecific.SequenceTest2>().Where(_ => _.ID == id1).Delete(); | |
118 | |
119 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest2>().Count(_ => _.Value == "SeqValue")); | |
120 } | |
121 } | |
122 | |
123 [Test] | |
124 public void SequenceInsertWithIdentity3([IncludeDataContexts(ProviderName.PostgreSQL)] string context) | |
125 { | |
126 using (var db = new TestDbManager(context)) | |
127 { | |
128 db.GetTable<PostgreSQLSpecific.SequenceTest3>().Where(_ => _.Value == "SeqValue").Delete(); | |
129 | |
130 var id1 = Convert.ToInt32(db.InsertWithIdentity(new PostgreSQLSpecific.SequenceTest3 { Value = "SeqValue" })); | |
131 var id2 = db.GetTable<PostgreSQLSpecific.SequenceTest3>().Single(_ => _.Value == "SeqValue").ID; | |
132 | |
133 Assert.AreEqual(id1, id2); | |
134 | |
135 db.GetTable<PostgreSQLSpecific.SequenceTest3>().Where(_ => _.ID == id1).Delete(); | |
136 | |
137 Assert.AreEqual(0, db.GetTable<PostgreSQLSpecific.SequenceTest3>().Count(_ => _.Value == "SeqValue")); | |
138 } | |
139 } | |
140 } | |
141 } |