Skip to content

Commit

Permalink
Merge pull request #240 from Vonage/DLR_status_ignore
Browse files Browse the repository at this point in the history
Ignoring status for Vonage.Messaging.DeliveryReceipt.
  • Loading branch information
slorello89 authored Jan 19, 2021
2 parents 515ae01 + 54f1bcf commit d0a1fe1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Nexmo.Api.Test.Unit/MessagingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Nexmo.Api.Messaging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -326,6 +327,43 @@ public void TestValidateSignature()
inboundSmsShell.Sig = Cryptography.SmsSignatureGenerator.GenerateSignature(Messaging.InboundSms.ConstructSignatureStringFromDictionary(dict),TestSigningSecret,Cryptography.SmsSignatureGenerator.Method.md5);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, Cryptography.SmsSignatureGenerator.Method.md5));
}

[Fact]
public void TestDlrStructCamelCaseIgnore()
{
var jsonFromNDP = @"{
""msisdn"": ""447700900000"",
""to"": ""AcmeInc"",
""network-code"": ""12345"",
""messageId"": ""0A0000001234567B"",
""price"": ""0.03330000"",
""status"": ""delivered"",
""scts"": ""2001011400"",
""err-code"": ""0"",
""api-key"": ""abcd1234"",
""message-timestamp"": ""2020-01-01T12:00:00.000+00:00"",
""timestamp"": 1582650446,
""nonce"": ""ec11dd3e-1e7f-4db5-9467-82b02cd223b9"",
""sig"": ""1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C"",
""client-ref"": ""steve""
}";
var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var dlr = JsonConvert.DeserializeObject<Messaging.DeliveryReceipt>(jsonFromNDP, settings);
Assert.Equal("447700900000", dlr.Msisdn);
Assert.Equal("AcmeInc", dlr.To);
Assert.Equal("12345", dlr.NetworkCode);
Assert.Equal("0A0000001234567B", dlr.MessageId);
Assert.Equal("0.03330000", dlr.Price);
Assert.Equal(Messaging.DlrStatus.delivered, dlr.Status);
Assert.Equal("2001011400", dlr.Scts);
Assert.Equal("0", dlr.ErrorCode);
Assert.Equal("abcd1234", dlr.ApiKey);
Assert.Equal("2020-01-01T12:00:00.000+00:00", dlr.MessageTimestamp);
Assert.True(1582650446 == dlr.Timestamp);
Assert.Equal("ec11dd3e-1e7f-4db5-9467-82b02cd223b9", dlr.Nonce);
Assert.Equal("1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C", dlr.Sig);
Assert.Equal("steve", dlr.ClientRef);
}
}
}

38 changes: 38 additions & 0 deletions Vonage.Test.Unit/MessagingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Web;
using Xunit;
using Newtonsoft.Json.Serialization;

namespace Vonage.Test.Unit
{
Expand Down Expand Up @@ -358,6 +359,43 @@ public void TestValidateSignature()
inboundSmsShell.Sig = Cryptography.SmsSignatureGenerator.GenerateSignature(Messaging.InboundSms.ConstructSignatureStringFromDictionary(dict),TestSigningSecret,Cryptography.SmsSignatureGenerator.Method.md5);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, Cryptography.SmsSignatureGenerator.Method.md5));
}

[Fact]
public void TestDlrStructCamelCaseIgnore()
{
var jsonFromNDP = @"{
""msisdn"": ""447700900000"",
""to"": ""AcmeInc"",
""network-code"": ""12345"",
""messageId"": ""0A0000001234567B"",
""price"": ""0.03330000"",
""status"": ""delivered"",
""scts"": ""2001011400"",
""err-code"": ""0"",
""api-key"": ""abcd1234"",
""message-timestamp"": ""2020-01-01T12:00:00.000+00:00"",
""timestamp"": 1582650446,
""nonce"": ""ec11dd3e-1e7f-4db5-9467-82b02cd223b9"",
""sig"": ""1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C"",
""client-ref"": ""steve""
}";
var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var dlr = JsonConvert.DeserializeObject<Messaging.DeliveryReceipt>(jsonFromNDP, settings);
Assert.Equal("447700900000", dlr.Msisdn);
Assert.Equal("AcmeInc", dlr.To);
Assert.Equal("12345", dlr.NetworkCode);
Assert.Equal("0A0000001234567B", dlr.MessageId);
Assert.Equal("0.03330000", dlr.Price);
Assert.Equal(Messaging.DlrStatus.delivered, dlr.Status);
Assert.Equal("2001011400", dlr.Scts);
Assert.Equal("0", dlr.ErrorCode);
Assert.Equal("abcd1234", dlr.ApiKey);
Assert.Equal("2020-01-01T12:00:00.000+00:00", dlr.MessageTimestamp);
Assert.True(1582650446 == dlr.Timestamp);
Assert.Equal("ec11dd3e-1e7f-4db5-9467-82b02cd223b9", dlr.Nonce);
Assert.Equal("1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C", dlr.Sig);
Assert.Equal("steve", dlr.ClientRef);
}
}
}

1 change: 1 addition & 0 deletions Vonage/Messaging/DeliveryReceipt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DeliveryReceipt
/// <summary>
/// A code that explains where the message is in the delivery process.
/// </summary>
[JsonIgnore]
public DlrStatus Status
{
get
Expand Down

0 comments on commit d0a1fe1

Please # to comment.