I am creating a two test case one of them validates the OK message in response with valid Authentication token and the other validates Unauthorized message with the invalid/missing token.

In first test case the valid Authentication token is provided (as header) which passes the test case. But when I created second test case with missing token it still got passed even though I did not provide any token there. How it is getting passed without the token.

I have already tried request.AddorUpdateParameter, it did not work.

Test Case I

RestClient client = new RestClient(clientName);
RestRequest request = new RestRequest("Products", Method.GET);

request.AddParameter(Common.AuthenticationKey, Common.AuthenticationValue);
IRestResponse response = client.Execute(request);  

Test Case II

RestClient client = new RestClient(clientName);            
RestRequest request = new RestRequest("Products", Method.GET);

IRestResponse response = client.Execute(request);

It still gives me OK status. It is taking reference of the first test case request?

The second test case should fail since authentication token is not provided.

1 Answers

0
Sunil Dhappadhule On

Adding your own header should overwrite any existing headers, so adding "Accept","*" or something similar should do the trick