-
Notifications
You must be signed in to change notification settings - Fork 599
/
Copy pathOracleStoredProcTests.cs
212 lines (185 loc) · 7.61 KB
/
OracleStoredProcTests.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;
using PetaPoco.Tests.Integration.Models;
using PetaPoco.Tests.Integration.Providers;
using Shouldly;
using Xunit;
namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleStoredProcTests : StoredProcTests
{
protected override Type DataParameterType => typeof(OracleParameter);
public OracleStoredProcTests()
: base(new OracleTestProvider())
{
}
private IDataParameter GetOutputParameter() => new OracleParameter("p_out_cursor", OracleDbType.RefCursor, ParameterDirection.Output);
[Fact]
public override void QueryProc_NoParam_ShouldReturnAll()
{
var results = DB.QueryProc<Person>("SelectPeople", GetOutputParameter()).ToArray();
results.Length.ShouldBe(6);
}
[Fact]
public override void QueryProc_WithParam_ShouldReturnSome()
{
var results = DB.QueryProc<Person>("SelectPeopleWithParam", new { age = 20 }, GetOutputParameter()).ToArray();
results.Length.ShouldBe(3);
}
[Fact]
public override void QueryProc_WithDbParam_ShouldReturnSome()
{
var results = DB.QueryProc<Person>("SelectPeopleWithParam", GetDataParameter(), GetOutputParameter()).ToArray();
results.Length.ShouldBe(3);
}
[Fact]
public override void FetchProc_NoParam_ShouldReturnAll()
{
var results = DB.FetchProc<Person>("SelectPeople", GetOutputParameter());
results.Count.ShouldBe(6);
}
[Fact]
public override void FetchProc_WithParam_ShouldReturnSome()
{
var results = DB.FetchProc<Person>("SelectPeopleWithParam", new { age = 20 }, GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override void FetchProc_WithDbParam_ShouldReturnSome()
{
var results = DB.FetchProc<Person>("SelectPeopleWithParam", GetDataParameter(), GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override void ScalarProc_NoParam_ShouldReturnAll()
{
var count = DB.ExecuteScalarProc<int>("CountPeople", GetOutputParameter());
count.ShouldBe(6);
}
[Fact]
public override void ScalarProc_WithParam_ShouldReturnSome()
{
var count = DB.ExecuteScalarProc<int>("CountPeopleWithParam", new { age = 20 }, GetOutputParameter());
count.ShouldBe(3);
}
[Fact]
public override void ScalarProc_WithDbParam_ShouldReturnSome()
{
var count = DB.ExecuteScalarProc<int>("CountPeopleWithParam", GetDataParameter(), GetOutputParameter());
count.ShouldBe(3);
}
[Fact]
public override void NonQueryProc_NoParam_ShouldUpdateAll()
{
DB.ExecuteNonQueryProc("UpdatePeople");
DB.Query<Person>($"WHERE {DB.Provider.EscapeSqlIdentifier("FullName")}='Updated'").Count().ShouldBe(6);
}
[Fact]
public override void NonQueryProc_WithParam_ShouldUpdateSome()
{
DB.ExecuteNonQueryProc("UpdatePeopleWithParam", new { age = 20 });
DB.Query<Person>($"WHERE {DB.Provider.EscapeSqlIdentifier("FullName")}='Updated'").Count().ShouldBe(3);
}
[Fact]
public override void NonQueryProc_WithDbParam_ShouldUpdateSome()
{
DB.ExecuteNonQueryProc("UpdatePeopleWithParam", GetDataParameter());
DB.Query<Person>($"WHERE {DB.Provider.EscapeSqlIdentifier("FullName")}='Updated'").Count().ShouldBe(3);
}
[Fact]
public override async Task QueryProcAsync_NoParam_ShouldReturnAll()
{
var results = new List<Person>();
await DB.QueryProcAsync<Person>(p => results.Add(p), "SelectPeople", GetOutputParameter());
results.Count.ShouldBe(6);
}
[Fact]
public override async Task QueryProcAsync_WithParam_ShouldReturnSome()
{
var results = new List<Person>();
await DB.QueryProcAsync<Person>(p => results.Add(p), "SelectPeopleWithParam", new { age = 20 }, GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override async Task QueryProcAsync_WithDbParam_ShouldReturnSome()
{
var results = new List<Person>();
await DB.QueryProcAsync<Person>(p => results.Add(p), "SelectPeopleWithParam", GetDataParameter(), GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override async Task QueryProcAsyncReader_NoParam_ShouldReturnAll()
{
var results = new List<Person>();
using (var reader = await DB.QueryProcAsync<Person>("SelectPeople", GetOutputParameter()))
{
while (await reader.ReadAsync())
results.Add(reader.Poco);
}
results.Count.ShouldBe(6);
}
[Fact]
public override async Task QueryProcAsyncReader_WithParam_ShouldReturnSome()
{
var results = new List<Person>();
using (var reader = await DB.QueryProcAsync<Person>("SelectPeopleWithParam", new { age = 20 }, GetOutputParameter()))
{
while (await reader.ReadAsync())
results.Add(reader.Poco);
}
results.Count.ShouldBe(3);
}
[Fact]
public override async Task QueryProcAsyncReader_WithDbParam_ShouldReturnSome()
{
var results = new List<Person>();
using (var reader = await DB.QueryProcAsync<Person>("SelectPeopleWithParam", GetDataParameter(), GetOutputParameter()))
{
while (await reader.ReadAsync())
results.Add(reader.Poco);
}
results.Count.ShouldBe(3);
}
[Fact]
public override async Task FetchProcAsync_NoParam_ShouldReturnAll()
{
var results = await DB.FetchProcAsync<Person>("SelectPeople", GetOutputParameter());
results.Count.ShouldBe(6);
}
[Fact]
public override async Task FetchProcAsync_WithParam_ShouldReturnSome()
{
var results = await DB.FetchProcAsync<Person>("SelectPeopleWithParam", new { age = 20 }, GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override async Task FetchProcAsync_WithDbParam_ShouldReturnSome()
{
var results = await DB.FetchProcAsync<Person>("SelectPeopleWithParam", GetDataParameter(), GetOutputParameter());
results.Count.ShouldBe(3);
}
[Fact]
public override async Task ScalarProcAsync_NoParam_ShouldReturnAll()
{
var count = await DB.ExecuteScalarProcAsync<int>("CountPeople", GetOutputParameter());
count.ShouldBe(6);
}
[Fact]
public override async Task ScalarProcAsync_WithParam_ShouldReturnSome()
{
var count = await DB.ExecuteScalarProcAsync<int>("CountPeopleWithParam", new { age = 20 }, GetOutputParameter());
count.ShouldBe(3);
}
[Fact]
public override async Task ScalarProcAsync_WithDbParam_ShouldReturnSome()
{
var count = await DB.ExecuteScalarProcAsync<int>("CountPeopleWithParam", GetDataParameter(), GetOutputParameter());
count.ShouldBe(3);
}
}
}