-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from EnessenE/feature/system.text
Convert Newtsonsoft.Json into System.Text.Json
- Loading branch information
Showing
54 changed files
with
680 additions
and
372 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CM.Text.BusinessMessaging; | ||
using CM.Text.BusinessMessaging.Model; | ||
using CM.Text.BusinessMessaging.Model.MultiChannel; | ||
using FluentAssertions; | ||
|
||
namespace CM.Text.NET6.Tests | ||
{ | ||
[TestClass] | ||
public class BuilderTests | ||
{ | ||
[TestMethod] | ||
public void BuildTest() | ||
{ | ||
var builder = new MessageBuilder("Message Text", "Sender_name", "Recipient_PhoneNumber"); | ||
|
||
var mediaName = "cm.com"; | ||
var mediaUri = "https://avatars3.githubusercontent.com/u/8234794?s=200&v=4"; | ||
var mediaType = "image/png"; | ||
|
||
builder | ||
.WithAllowedChannels(Channel.WhatsApp) | ||
.WithRichMessage( | ||
new MediaMessage( | ||
mediaName, | ||
mediaUri, | ||
mediaType | ||
) | ||
); | ||
var message = builder.Build(); | ||
|
||
message.Should().NotBeNull(); | ||
message.RichContent.Conversation.Should().NotBeNull(); | ||
message.RichContent.Conversation.Length.Should().Be(1); | ||
var media = (MediaMessage) message.RichContent.Conversation.First(); | ||
media.Media.MediaName.Should().Be(mediaName); | ||
media.Media.MediaUri.Should().Be(mediaUri); | ||
media.Media.MimeType.Should().Be(mediaType); | ||
} | ||
} | ||
} |
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,97 @@ | ||
using CM.Text.BusinessMessaging; | ||
using CM.Text.BusinessMessaging.Model; | ||
using CM.Text.BusinessMessaging.Model.MultiChannel; | ||
using FluentAssertions; | ||
|
||
namespace CM.Text.NET6.Tests | ||
{ | ||
[TestClass] | ||
public class BusinessMessagingApiTests | ||
{ | ||
[TestMethod] | ||
public void TestPostBody() | ||
{ | ||
var guid = Guid.NewGuid(); | ||
var message = "This is a unit test"; | ||
var sender = "CM.com"; | ||
var reference = "ReferenceForMeToFind"; | ||
var number1 = "0031612345678"; | ||
var number2 = "0031612345679"; | ||
|
||
var data = BusinessMessagingApi.GetHttpPostBody(guid, message, sender, | ||
new[] {number1, number2}, reference); | ||
|
||
data.Should().NotBeNull(); | ||
//Simple to check if all values survived our logic | ||
data.Should().Contain(guid.ToString()); | ||
data.Should().Contain(message); | ||
data.Should().Contain(sender); | ||
data.Should().Contain(reference); | ||
data.Should().Contain(number1); | ||
data.Should().Contain(number2); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRichPostBody() | ||
{ | ||
var builder = new MessageBuilder("Message Text", "Sender_name", "Recipient_PhoneNumber"); | ||
|
||
var mediaName = "cm.com icon"; | ||
var mediaUri = "https://avatars3.githubusercontent.com/u/8234794"; | ||
var mediaType = "image/png"; | ||
|
||
builder | ||
.WithAllowedChannels(Channel.WhatsApp) | ||
.WithRichMessage( | ||
new MediaMessage( | ||
mediaName, | ||
mediaUri, | ||
mediaType | ||
) | ||
); | ||
var message = builder.Build(); | ||
|
||
Guid fakeApiKey = Guid.NewGuid(); | ||
var data = BusinessMessagingApi.GetHttpPostBody(fakeApiKey, message); | ||
|
||
data.Should().NotBeNull(); | ||
//Simple to check if all values survived our logic | ||
data.Should().Contain(fakeApiKey.ToString(), "the api key should be present in the body"); | ||
data.Should().Contain(mediaName, "the media name needs to be sent"); | ||
data.Should().Contain(mediaType, "the media type has to be sent"); | ||
data.Should().Contain(mediaUri, "the media url has to be sent"); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestResponseBody() | ||
{ | ||
var guid = Guid.NewGuid(); | ||
// Arrange | ||
string message = @"{ | ||
""messages"": [{ | ||
""to"": ""0031612345678"", | ||
""parts"": 1, | ||
""status"": ""Accepted"", | ||
""reference"": ""test-reference-1"", | ||
""messageErrorCode"": 0, | ||
""messageDetails"": null | ||
}], | ||
""details"": ""Created 1 message(s)"", | ||
""errorCode"": 0 | ||
}"; | ||
|
||
|
||
var data = BusinessMessagingApi.GetTextApiResult(message); | ||
|
||
data.Should().NotBeNull(); | ||
//Simple to check if all values survived our logic | ||
data.details.Should().NotBeNull(); | ||
data.details.First().reference.Should().Be("test-reference-1"); | ||
data.details.First().status.Should().Be("Accepted"); | ||
data.details.First().to.Should().Be("0031612345678"); | ||
data.details.First().parts.Should().Be(1); | ||
data.details.First().details.Should().BeNull(); | ||
} | ||
} | ||
} |
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.7.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CM.Text\CM.Text.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace CM.Text.BusinessMessaging.Model | ||
{ | ||
|
||
/// <summary> | ||
/// CM Messaging API response body containing API related info | ||
/// </summary> | ||
public class HttpResponseBody | ||
{ | ||
/// <summary> | ||
/// API Request details | ||
/// </summary> | ||
[JsonInclude] | ||
public string details { get; private set; } | ||
|
||
/// <summary> | ||
/// JSON POST Error codes. Full description of each code available in the development documentation | ||
/// </summary> | ||
[JsonInclude] | ||
public int errorCode { get; private set; } | ||
|
||
/// <summary> | ||
/// Each message that was sent in the original request | ||
/// </summary> | ||
[JsonInclude] | ||
public ResponseMessageDetail[] messages { get; private set; } | ||
} | ||
} |
Oops, something went wrong.