public async Task ShouldReturnOnePost() { try { IRestionClient restionClient = new RestionClient() .SetBaseAddress("http://jsonplaceholder.typicode.com"); IRestionRequest restionRequest = new RestionRequest("/posts/1"); IRestionResponse<Post> response = await restionClient.ExecuteRequestAsync<Post>(restionRequest); if (response != null) { if (response.Exception != null) { Assert.Fail(response.Exception.Message); } else { response.Content.Should().NotBeNull(); } } } catch (Exception) { throw; } }
public async Task ShouldReturnAllPosts() { try { IRestionClient restionClient = new RestionClient().SetBaseAddress("http://jsonplaceholder.typicode.com"); IRestionRequest restionRequest = new RestionRequest("/posts/"); IRestionResponse<List<Post>> response = await restionClient.ExecuteRequestAsync<List<Post>>(restionRequest); if (response != null) { if (response.Exception != null) { Assert.Fail(response.Exception.Message); } else { response.Content.Should().NotBeNull().And.HaveCount(100); } } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public async Task ShouldPostAPost() { try { IRestionClient restionClient = new RestionClient() .SetBaseAddress("http://jsonplaceholder.typicode.com"); IRestionRequest restionRequest = new RestionRequest("/posts/") .WithHttpMethod(HttpMethod.Post) .WithContent(new Post() { Body = "Teste", Title = "Teste", UserId = 1 }) .WithContentMediaType(MediaTypes.ApplicationJson) .WithContentEnconding(Encoding.UTF8); IRestionResponse<Post> response = await restionClient.ExecuteRequestAsync<Post>(restionRequest); if (response != null) { if (response.Exception != null) { Assert.Fail(response.Exception.Message); } else { response.Content.Should().NotBeNull(); } } } catch (Exception ex) { Assert.Fail(ex.Message); } }