-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EmptyArrayAsDefaultConverter: treat empty object {} as default (null) (…
…#309) * Treat empty object {} as default (null) * Add tests * Fix test
- Loading branch information
1 parent
97247dd
commit ee43f14
Showing
2 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Source/EasyNetQ.Management.Client.Tests/Serialization/EmptyArrayAsDefaultConverterTests.cs
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,47 @@ | ||
using System.Text.Json; | ||
using EasyNetQ.Management.Client.Model; | ||
|
||
namespace EasyNetQ.Management.Client.Tests.Serialization; | ||
|
||
public class EmptyArrayAsDefaultConverterTests | ||
{ | ||
private const string consumerDetailFormat = | ||
"""{{"arguments":{0},"channel_details":{0},"ack_required":true,"active":true,"activity_status":"up","consumer_tag":"CT","consumer_timeout":"undefined","exclusive":false,"prefetch_count":0,"queue":{{"name":"Q","vhost":"V"}}}}"""; | ||
|
||
private static readonly ConsumerDetail expectedConsumerDetail = new ConsumerDetail(new QueueName("Q", "V"), "CT", false, true, null, null); | ||
|
||
[Fact] | ||
public void Should_deserialize_empty_array() | ||
{ | ||
var deserializedObject = JsonSerializer.Deserialize<ConsumerDetail>(string.Format(consumerDetailFormat, "[]"), ManagementClient.SerializerOptions); | ||
deserializedObject.Should().BeEquivalentTo(expectedConsumerDetail); | ||
} | ||
|
||
[Fact] | ||
public void Should_deserialize_empty_object() | ||
{ | ||
var deserializedObject = JsonSerializer.Deserialize<ConsumerDetail>(string.Format(consumerDetailFormat, "{}"), ManagementClient.SerializerOptions); | ||
deserializedObject.Should().BeEquivalentTo(expectedConsumerDetail); | ||
} | ||
|
||
[Fact] | ||
public void Should_deserialize_null() | ||
{ | ||
var deserializedObject = JsonSerializer.Deserialize<ConsumerDetail>(string.Format(consumerDetailFormat, "null"), ManagementClient.SerializerOptions); | ||
deserializedObject.Should().BeEquivalentTo(expectedConsumerDetail); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_deserialize_non_empty_array() | ||
{ | ||
var action = () => JsonSerializer.Deserialize<ConsumerDetail>(string.Format(consumerDetailFormat, "[1]"), ManagementClient.SerializerOptions); | ||
action.Should().ThrowExactly<JsonException>(); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_deserialize_string() | ||
{ | ||
var action = () => JsonSerializer.Deserialize<ConsumerDetail>(string.Format(consumerDetailFormat, "\"consumer_detail\""), ManagementClient.SerializerOptions); | ||
action.Should().ThrowExactly<JsonException>(); | ||
} | ||
} |
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