Skip to content

Commit

Permalink
adding unicode test cases for sms and voice - changing encoding for j…
Browse files Browse the repository at this point in the history
…son to UTF8
  • Loading branch information
slorello89 committed Jun 17, 2020
2 parents b1b738b + 27ec412 commit f2c43d3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 deletions.
32 changes: 32 additions & 0 deletions Nexmo.Api.Test.Unit/MessagingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ public void SendSmsTypicalUsage()
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}

[Fact]
public void SendSmsUnicode()
{
var expectedResponse = @"{
""message-count"": ""1"",
""messages"": [
{
""to"": ""447700900000"",
""message-id"": ""0A0000000123ABCD1"",
""status"": ""0"",
""remaining-balance"": ""3.14159265"",
""message-price"": ""0.03330000"",
""network"": ""12345"",
""account-ref"": ""customer1234""
}
]
}";
var expectedUri = $"{RestUrl}/sms/json?";
var expectedRequestContent = $"from=AcmeInc&to=447700900000&text={HttpUtility.UrlEncode("こんにちは世界")}&api_key={ApiKey}&api_secret={ApiSecret}&";
Setup(expectedUri, expectedResponse, expectedRequestContent);
var client = new NexmoClient(Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret));
var response = client.SmsClient.SendAnSms(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "こんにちは世界" });
Assert.Equal("1", response.MessageCount);
Assert.Equal("447700900000", response.Messages[0].To);
Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId);
Assert.Equal("0", response.Messages[0].Status);
Assert.Equal(SmsStatusCode.Success, response.Messages[0].StatusCode);
Assert.Equal("3.14159265", response.Messages[0].RemainingBalance);
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}

[Fact]
public void SendSmsBadResponse()
{
Expand Down
48 changes: 48 additions & 0 deletions Nexmo.Api.Test.Unit/VoiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,53 @@ public void TestGetRecordings(bool passCreds)
Assert.Equal(expectedResponse, response.ResultStream);

}

[Fact]
public void CreateCallWithUnicodeCharecters()
{
var expectedUri = "https://api.nexmo.com/v1/calls/";
var expectedResponse = @"{
""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356"",
""status"": ""started"",
""direction"": ""outbound"",
""conversation_uuid"": ""CON-f972836a-550f-45fa-956c-12a2ab5b7d22""
}";
var expectedRequesetContent = @"{""to"":[{""number"":""14155550100"",""dtmfAnswer"":""p*123#"",""type"":""phone""}],""from"":{""number"":""14155550100"",""dtmfAnswer"":""p*123#"",""type"":""phone""},""ncco"":[{""text"":""בדיקה בדיקה בדיקה"",""action"":""talk""}],""answer_url"":[""https://example.com/answer""],""answer_method"":""GET"",""event_url"":[""https://example.com/event""],""event_method"":""POST"",""machine_detection"":""continue"",""length_timer"":1,""ringing_timer"":1}";

Setup(expectedUri, expectedResponse, expectedRequesetContent);

var request = new Voice.CallCommand
{
To = new[]
{
new Voice.Nccos.Endpoints.PhoneEndpoint
{
Number="14155550100",
DtmfAnswer="p*123#"
}
},
From = new Voice.Nccos.Endpoints.PhoneEndpoint
{
Number = "14155550100",
DtmfAnswer = "p*123#"
},
Ncco = new Voice.Nccos.Ncco(new Voice.Nccos.TalkAction { Text = "בדיקה בדיקה בדיקה" }),
AnswerUrl = new[] { "https://example.com/answer" },
AnswerMethod = "GET",
EventUrl = new[] { "https://example.com/event" },
EventMethod = "POST",
MachineDetection = "continue",
LengthTimer = 1,
RingingTimer = 1,
};
var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new NexmoClient(creds);
CallResponse response;
response = client.VoiceClient.CreateCall(request);
Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", response.Uuid);
Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", response.ConversationUuid);
Assert.Equal("outbound", response.Direction);
Assert.Equal("started", response.Status);
}
}
}
2 changes: 1 addition & 1 deletion Nexmo.Api/Nexmo.Api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Official C#/.NET wrapper for the Nexmo API</description>
<releaseNotes>
https://github.com/Nexmo/nexmo-dotnet/releases/tag/v4.4.0
https://github.com/Nexmo/nexmo-dotnet/releases/tag/v5.0.0
</releaseNotes>
<copyright>© Nexmo 2020</copyright>
<tags>SMS voice telephony phone nexmo vonage</tags>
Expand Down
6 changes: 3 additions & 3 deletions Nexmo.Api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nexmo")]
[assembly: AssemblyProduct("Nexmo.Api")]
[assembly: AssemblyCopyright(Nexmo 2019")]
[assembly: AssemblyCopyright(Vonage 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -34,5 +34,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.4.0.0")]
[assembly: AssemblyFileVersion("4.4.0.0")]
[assembly: AssemblyVersion("4.4.1.0")]
[assembly: AssemblyFileVersion("4.4.1.0")]
2 changes: 1 addition & 1 deletion Nexmo.Api/Request/ApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public static T DoRequestWithJsonContent<T>(string method, Uri uri, object paylo
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
logger.LogDebug($"Request URI: {uri}");
logger.LogDebug($"JSON Payload: {json}");
var data = Encoding.ASCII.GetBytes(json);
var data = Encoding.UTF8.GetBytes(json);
req.Content = new ByteArrayContent(data);
req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var json_response = SendHttpRequest(req).JsonResponse;
Expand Down

0 comments on commit f2c43d3

Please # to comment.