-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestsWithMultipleData.cs
69 lines (55 loc) · 2.79 KB
/
TestsWithMultipleData.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
using System;
using System.Collections.Generic;
using System.Net;
using NUnit.Framework;
using NUnit.Framework.Internal;
using RestSharp;
using RestSharp.Serialization.Json;
using RestSharpDemo.Model;
using RestSharpDemo.Utilities;
namespace RestSharpDemo.Tests
{
//Reference: Thanks Bas Dijkstra for introducing http://api.zippopotam.us
[TestFixture]
public class TestsWithMultipleData
{
private IRestClient _restClient;
private IRestRequest _restRequest;
private IRestResponse _restResponse;
private const string BaseUrl = "http://api.zippopotam.us";
[SetUp]
public void Setup()
{
_restClient = new RestClient(BaseUrl);
}
[TestCase("IN", "110001", HttpStatusCode.OK, TestName = "Check status code for IN with pin code 110001")]
[TestCase("AU", "2140", HttpStatusCode.OK, TestName = "Check status code for AU with pin code 2140")]
[TestCase("IN", "909090909090909", HttpStatusCode.NotFound, TestName = "Check Not Found status code for IN with pin code 909090909090909")]
public void TestWithPostCal_withData(string countryCode, string pinCode,
HttpStatusCode expectedHttpStatusCode)
{
//http://api.zippopotam.us/us/90210
_restRequest = new RestRequest($"{countryCode}/{pinCode}", Method.GET);
_restResponse = _restClient.Execute(_restRequest);
// Console.WriteLine("***"+result.Content);
Assert.That(_restResponse.StatusCode, Is.EqualTo(expectedHttpStatusCode));
}
[Test,TestCaseSource(nameof(PlacesTestData))]
public void Test_withTestCaseSourceData(string countryCode, string pinCode, string placeName)
{
_restRequest = new RestRequest($"{countryCode}/{pinCode}", Method.GET);
_restResponse = _restClient.Execute(_restRequest);
var result = new JsonDeserializer().Deserialize<Location>(_restResponse);
// var output = response.DeserializeResponse();
Console.WriteLine("*****" + result.Places[0].PlaceName);
Assert.That(result.Places[0].PlaceName, Is.EqualTo(placeName).IgnoreCase);
}
private static IEnumerable<TestCaseData> PlacesTestData()
{
yield return new TestCaseData("in", "600001", "Flower bazar").SetName(
"Check status code for 600001 that has place name as Flower bazar");
yield return new TestCaseData("au", "2140", "Homebush").SetName(
"Check status code for 2140 that has place name as Homebush");
}
}
}