Skip to content

A simple library to make response treatment clean and fluent

Notifications You must be signed in to change notification settings

nikolasmagno/WhenResponse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhenResponse

A simple library to make response treatment clean and fluent

Usage

response.When((r)=> r.StatusCode == HttpStatusCode.Ok,(r)=> System.Console.WriteLine("Ok"))
        .When((r)=> r.StatusCode == HttpStatusCode.Accepted,(r)=> System.Console.WriteLine("Accepted"))
        .When((r)=> r.StatusCode != HttpStatusCode.Accepted,(r)=> Assert.Fail("Waiting status code Accepted"));

Using it with RestSharp

var client = new RestClient("https://httpstat.us/");
var request = new RestRequest("202?sleep=2000", Method.GET);
          
// execute the request
IRestResponse response = client.Execute(request);
response.When((r)=> r.StatusCode == HttpStatusCode.Ok,(r)=> System.Console.WriteLine("Ok"))
        .When((r)=> r.StatusCode == HttpStatusCode.Accepted,(r)=> System.Console.WriteLine("Accepted"))
        .When((r)=> r.StatusCode == HttpStatusCode.NotFound,(r)=> Assert.Fail("No Found"));

Using it with Response Verifier

var client = new RestClient("https://httpstat.us/");
var request = new RestRequest("202?sleep=2000", Method.GET);
          
// execute the request
IRestResponse response = client.Execute(request);
response.When((r)=> r.StatusCode.StatusCode.IsFromSuccessfulResponse(),(r)=> System.Console.WriteLine("Ok"))        
        .When((r)=> !r.StatusCode.StatusCode.IsFromSuccessfulResponse(),(r)=> Assert.Fail("Fail"));

About

A simple library to make response treatment clean and fluent

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages