-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestsWithGetOperation.cs
88 lines (70 loc) · 2.98 KB
/
TestsWithGetOperation.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
using System;
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using RestSharp;
using RestSharp.Authenticators;
using RestSharp.Serialization.Json;
using RestSharpDemo.Utilities;
namespace RestSharpDemo.Tests
{
[TestFixture]
public class TestsWithGetOperation
{
private IRestClient _restClient;
private IRestRequest _restRequest;
private IRestResponse _restResponse;
private const string BaseUrl = "https://reqres.in/";
[SetUp]
public void Setup()
{
_restClient = new RestClient(BaseUrl);
}
[Test]
public void SimpleGetRequestTest()
{
//Arrange
_restRequest = new RestRequest("api/users/{user}", Method.GET);
_restRequest.AddUrlSegment("user", 2);
//Act
_restResponse = _restClient.Execute(_restRequest);
//Assert
Console.WriteLine("**** This is the response **** "+ _restResponse.Content);
Assert.That(_restResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
[Test]
public void SimpleGetRequestWithHelperMethod()
{
//Arrange
var restRequest = Helper.CreateGetRequest("api/users/2");
//Act
var output = Helper.GetResponse(_restClient, restRequest);
//Assert
Console.WriteLine("**** This is the response **** "+ output.Content);
Assert.That(output.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
[Test]
public void VerifyTotalNumberOfRecords()
{
_restRequest= new RestRequest("/api/users?page=2", Method.GET);
_restResponse = _restClient.Execute(_restRequest);
var result = _restResponse.DeserializeResponse()["total"];
Assert.That(result, Is.EqualTo("12"), "Total Records are mismatch");
}
[Test]
public void GetRequestWithAuthenticationParams()
{
_restRequest = new RestRequest("https://reqres.in/api/login", Method.GET);
_restResponse = _restClient.Execute(_restRequest);
Assert.That(_restResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
[TearDown]
public void Close()
{
Console.WriteLine("Hey! I've done executing all the tests");
}
}
}