From f26e5fc2e0f476fe7a8b403483ce2ffd16329a3a Mon Sep 17 00:00:00 2001 From: Rafael Gomez Date: Wed, 1 Jun 2022 14:01:24 +0200 Subject: [PATCH] Fix serialization + version change + nuget update --- Directory.Build.props | 2 +- TeamsHook.NET.Tests/SystemTextJsonTests.cs | 11 ++++++----- TeamsHook.NET.Tests/TeamsHook.NET.Tests.csproj | 8 ++++---- TeamsHook.NET/TeamsHook.NET.csproj | 2 +- TeamsHook.NET/TeamsHookClient.cs | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 0cc7e1d..c20bb51 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 0.2.0-pre3 + 0.2.0-pre4 TeamsHook.NET .NET Client for sending messages to Microsoft Teams via Webhooks Rafael Gómez diff --git a/TeamsHook.NET.Tests/SystemTextJsonTests.cs b/TeamsHook.NET.Tests/SystemTextJsonTests.cs index ad0ae64..cbd6fa8 100644 --- a/TeamsHook.NET.Tests/SystemTextJsonTests.cs +++ b/TeamsHook.NET.Tests/SystemTextJsonTests.cs @@ -98,7 +98,7 @@ public void JsonTestActionsMessageCard() [Fact] public async Task JsonTestMessageCardClient() { - const string UriWebhook = @"https://outlook.office.com/webhook/d3470767-e202-4f22-8251-a42d92916355@4cccefa5-026f-4183-ba9d-ca1ff6e6bb59/IncomingWebhook/ba9e479c10b540a2bdffe7a1493879d3/e2d090c3-7509-4c54-a95f-678a5af6d85b"; + const string UriWebhook = @"https://hengesbachgmbh.webhook.office.com/webhookb2/f4d42301-3481-42e4-8b9f-cc7616ccb768@4cccefa5-026f-4183-ba9d-ca1ff6e6bb59/IncomingWebhook/fe635dbed4b642a4aeb57eb7221a7ca1/e2d090c3-7509-4c54-a95f-678a5af6d85b"; var opt = new JsonSerializerOptions() { @@ -127,10 +127,11 @@ public async Task JsonTestMessageCardClient() } } }; - var json = JsonSerializer.Serialize(card, opt); - using var client = new HttpClient(); - var response = await client.PostAsync(UriWebhook, new StringContent(json, Encoding.UTF8, "application/json")); - var content = await response.Content.ReadAsStringAsync(); + + var client = new TeamsHookClient(); + var response = await client.PostAsync(UriWebhook, card); + var content = await response.Content.ReadAsStringAsync(); + Console.WriteLine(content); } [Fact] diff --git a/TeamsHook.NET.Tests/TeamsHook.NET.Tests.csproj b/TeamsHook.NET.Tests/TeamsHook.NET.Tests.csproj index 5208d17..3f6c5fa 100644 --- a/TeamsHook.NET.Tests/TeamsHook.NET.Tests.csproj +++ b/TeamsHook.NET.Tests/TeamsHook.NET.Tests.csproj @@ -1,15 +1,15 @@ - netcoreapp3.1 + net6.0 false - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TeamsHook.NET/TeamsHook.NET.csproj b/TeamsHook.NET/TeamsHook.NET.csproj index 2137200..b87a3e0 100644 --- a/TeamsHook.NET/TeamsHook.NET.csproj +++ b/TeamsHook.NET/TeamsHook.NET.csproj @@ -10,7 +10,7 @@ - + diff --git a/TeamsHook.NET/TeamsHookClient.cs b/TeamsHook.NET/TeamsHookClient.cs index 7ed52c9..6e56d45 100644 --- a/TeamsHook.NET/TeamsHookClient.cs +++ b/TeamsHook.NET/TeamsHookClient.cs @@ -18,7 +18,7 @@ public TeamsHookClient(HttpClient client = null) public Task PostAsync(string webhookUrl, TeamsCard card) { - var payload = JsonSerializer.Serialize(card, _jsonSettings); + var payload = JsonSerializer.Serialize(card, card.GetType(), _jsonSettings); return _client.PostAsync(webhookUrl, new StringContent(payload, Encoding.UTF8, "application/json")); } }