-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTestsWithPostOperation.cs
57 lines (46 loc) · 1.85 KB
/
TestsWithPostOperation.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
using System;
using NUnit.Framework;
using NUnit.Framework.Internal;
using RestSharp;
using RestSharpDemo.Model;
using RestSharpDemo.Utilities;
namespace RestSharpDemo.Tests
{
[TestFixture]
public class TestsWithPostOperation
{
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 with Anonymous Body
[Test]
public void TestWithPostCall()
{
//Arrange
_restRequest = new RestRequest("api/users" , Method.POST);
_restRequest.AddJsonBody(new {name = "Tester", job = "Director" });
//Act
_restResponse = _restClient.Execute(_restRequest);
Console.WriteLine("Printing results for fun : "+_restResponse.Content);
//Assert
var result = _restResponse.DeserializeResponse();
Assert.That(result["name"], Is.EqualTo("Tester"));
}
//Test POST operation with Type class
[Test]
public void TestPostWithTypeClass_Generics()
{
_restRequest = new RestRequest("api/register", Method.POST);
_restRequest.AddJsonBody(new Users() {email = "[email protected]", password = "pistol"});
var response = _restClient.Execute<Users>(_restRequest);
Console.WriteLine("*** Response is *** " + response.Content);
Assert.That(response.Data.token, Is.EqualTo("QpwL5tke4Pnpja7X4").IgnoreCase);
}
}
}