-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Todd
committed
Dec 5, 2023
1 parent
3ef55a3
commit c4dec2a
Showing
4 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using NUnit.Framework; | ||
using Flurl.Http; | ||
using Flurl.Http.Newtonsoft; | ||
using Flurl.Http.Testing; | ||
using System.Threading.Tasks; | ||
|
||
namespace Flurl.Test.Http | ||
{ | ||
// These inherit from GetTests and PostTests and swap out the JSON serializer | ||
// in play, which gets us a lot of free tests but also a lot of redundant ones. | ||
// Maybe worth refactoring someday, but they're fast so it's tolerable for now. | ||
|
||
[TestFixture, Parallelizable] | ||
public class NewtonsoftGetTests : GetTests | ||
{ | ||
protected override HttpTest CreateHttpTest() => base.CreateHttpTest() | ||
.WithSettings(settings => settings.JsonSerializer = new NewtonsoftJsonSerializer()); | ||
|
||
[Test] | ||
public async Task can_get_dynamic() { | ||
HttpTest.RespondWithJson(new { id = 1, name = "Frank" }); | ||
|
||
var data = await "http://some-api.com".GetJsonAsync(); | ||
|
||
Assert.AreEqual(1, data.id); | ||
Assert.AreEqual("Frank", data.name); | ||
} | ||
|
||
[Test] | ||
public async Task can_get_dynamic_list() { | ||
HttpTest.RespondWithJson(new[] { | ||
new { id = 1, name = "Frank" }, | ||
new { id = 2, name = "Claire" } | ||
}); | ||
|
||
var data = await "http://some-api.com".GetJsonListAsync(); | ||
|
||
Assert.AreEqual(1, data[0].id); | ||
Assert.AreEqual("Frank", data[0].name); | ||
Assert.AreEqual(2, data[1].id); | ||
Assert.AreEqual("Claire", data[1].name); | ||
} | ||
} | ||
|
||
[TestFixture, Parallelizable] | ||
public class NewtonsofPostTests : PostTests | ||
{ | ||
protected override HttpTest CreateHttpTest() => base.CreateHttpTest() | ||
.WithSettings(settings => settings.JsonSerializer = new NewtonsoftJsonSerializer()); | ||
|
||
[Test] | ||
public async Task can_receive_json_dynamic() { | ||
HttpTest.RespondWithJson(new { id = 1, name = "Frank" }); | ||
|
||
var data = await "http://some-api.com".PostJsonAsync(new { a = 1, b = 2 }).ReceiveJson(); | ||
|
||
Assert.AreEqual(1, data.id); | ||
Assert.AreEqual("Frank", data.name); | ||
} | ||
|
||
[Test] | ||
public async Task can_receive_json_dynamic_list() { | ||
HttpTest.RespondWithJson(new[] { | ||
new { id = 1, name = "Frank" }, | ||
new { id = 2, name = "Claire" } | ||
}); | ||
|
||
var data = await "http://some-api.com".PostJsonAsync(new { a = 1, b = 2 }).ReceiveJsonList(); | ||
|
||
Assert.AreEqual(1, data[0].id); | ||
Assert.AreEqual("Frank", data[0].name); | ||
Assert.AreEqual(2, data[1].id); | ||
Assert.AreEqual("Claire", data[1].name); | ||
} | ||
} | ||
} |