Skip to content

Commit

Permalink
Add unit test for by type
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ising committed Jan 1, 2024
1 parent 88288d0 commit 934b64b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
Expand Down
13 changes: 13 additions & 0 deletions src/UnitTests/JsonConverters/MultiTypeClassConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public void ShouldDeserializeGiveaway()
Assert.That(deserializedJson.Source.Source, Is.EqualTo(ChatBoostSourceType.Giveaway));
Assert.That(deserializedJson.Source, Is.TypeOf<ChatBoostSourceGiveaway>());
}

[Test]
public void ShouldDeserializeExternalReplyInfo()
{
const string messageOriginUserJson = "{\"type\":\"user\",\"date\":123,\"sender_user\":" + User + "}";
const string json = "{\"origin\":" + messageOriginUserJson + "}";
var deserializedJson = JsonConvert.DeserializeObject<ExternalReplyInfo>(json, JsonSerializerSettings);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.Origin.Type, Is.EqualTo(MessageOriginType.User));
Assert.That(deserializedJson.Origin, Is.TypeOf<MessageOriginUser>());
var user = (MessageOriginUser)deserializedJson.Origin;
Assert.That(user.SenderUser.Id, Is.EqualTo(123));
}
}

0 comments on commit 934b64b

Please sign in to comment.