forked from ericgu/DesignForTestability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallDatabase.cs
52 lines (47 loc) · 1.66 KB
/
CallDatabase.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
using designIssueExample.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace designIssueExample
{
class CallDatabase
{
private const int EmployeeIdColumnIndex = 0;
private const int EmployeeNameColumnIndex = 1;
private const int EmployeeAgeColumnIndex = 2;
private const int EmployeeIsSalariedColumnIndex = 3;
public static List<Employee> GetAllEmployees(string query)
{
List<Employee> employees = new List<Employee>();
FakeSqlConnection connection = new FakeSqlConnection();
using (FakeSqlCommand sqlCommand = new FakeSqlCommand(query, connection))
{
FakeSqlDataReader reader;
int retryCount = 5;
while (true)
{
try
{
reader = sqlCommand.ExecuteReader();
break;
}
catch (Exception)
{
if (retryCount-- == 0) throw;
}
}
while (reader.Read())
{
int id = reader.GetInt32(EmployeeIdColumnIndex);
string name = reader.GetString(EmployeeNameColumnIndex);
int age = reader.GetInt32(EmployeeAgeColumnIndex);
bool isSalaried = reader.GetBoolean(EmployeeIsSalariedColumnIndex);
employees.Add(new Employee(id, name, age, isSalaried));
}
}
return employees;
}
}
}