Nov 12
Want to learn how test your REST API fluently in a couple of lines of C# code?
Like this:
[Fact]
public async Task Get_UserWithId1_ReturnsDynamicWithUsernameBretAndOkStatusCode()
{
var client = new RestClient("https://jsonplaceholder.typicode.com", new Config()
.SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }));
await client
.Resource("users/1").Get()
.Verify(userIsBret => userIsBret.username == "Bret")
.Verify(httpResponseMessageIsOk => httpResponseMessageIsOk.HttpResponseMessage.StatusCode == HttpStatusCode.OK);
}
View live example
Head over to my post on Code Maze, and your be testing REST API’s using C# in no time at all.
Tagged with: csharp • dotnet • dotnetcore • rest • restclient • RESTFul • testing
Recent Comments