-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataDrivenHelpers.cs
102 lines (77 loc) · 3.03 KB
/
DataDrivenHelpers.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
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using DataDriven_NetCore_NUnit.Helpers;
using NUnit.Framework;
namespace DataDriven_NetCore_NUnit
{
public class DataDrivenHelpers
{
public static List<TestCaseData> ReturnNameTelephone_CSV
{
get
{
var testCases = new List<TestCaseData>();
using (var fs = File.OpenRead(GeneralHelpers.GetProjectPath() + @"\DataDriven\Files\NameTelephone.csv"))
using (var sr = new StreamReader(fs))
{
string headerLine = sr.ReadLine();
string line = string.Empty;
while (line != null)
{
line = sr.ReadLine();
if (line != null)
{
string[] split = line.Split(new char[] { ',' },
StringSplitOptions.None);
string param1 = Convert.ToString(split[0]); //name
string param2 = Convert.ToString(split[1]); //telephone
var testCase = new TestCaseData(param1, param2);
testCases.Add(testCase);
}
}
}
return testCases;
}
}//end method
static object[] PersonData =
{
new object[] { "Irene J. Hunt", "1156736694" }, //TestCase1
new object[] { "Michael D. Young", "8056736694"} //TestCase2
};
public static IEnumerable<TestCaseData> ReturnNameTelephone_XLSX
{
get
{
var testCases = new List<TestCaseData>();
testCases = new ExcelHelpers().ReadExcelData(GeneralHelpers.GetProjectPath() + @"\DataDriven\Files\NameTelephone.xlsx");
if (testCases != null)
foreach (TestCaseData testCaseData in testCases)
yield return testCaseData;
}
}
public static List<TestCaseData> ReturnDataUsingAPI()
{
var testcase = new List<TestCaseData>();
var users = APIHelpers.GetUsersInfoAPI();
Console.WriteLine(users);
foreach (var user in users)
{
testcase.Add(new TestCaseData(user.first_name.ToString(), user.email.ToString()));
}
return testcase;
}
public static List<TestCaseData> ReturnDataUsingDataBase()
{
var testcase = new List<TestCaseData>();
DataTable users = DataBaseHelpers.RetornaDadosDataTableQuery("SELECT * FROM `user`");
Console.WriteLine(users);
foreach(DataRow row in users.Rows)
{
testcase.Add(new TestCaseData(row[1].ToString(), row[2].ToString()));
}
return testcase;
}
}
}