Skip to content

Commit

Permalink
Merge pull request #190 from Nexmo/bugfix/loop_param_ignored_when_zero
Browse files Browse the repository at this point in the history
Fixing default serialization of zero's in loop
  • Loading branch information
slorello89 authored Feb 11, 2020
2 parents 211055b + be8c4fd commit a51d9ec
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Nexmo.Api.Test.Unit/NumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class NumberTest : MockedWebTest
[TestMethod]
public void should_search_numbers()
{
SetExpect($"{RestUrl}/number/search/?country=US&has_application=False&api_key={ApiKey}&api_secret={ApiSecret}&",
SetExpect($"{RestUrl}/number/search/?country=US&api_key={ApiKey}&api_secret={ApiSecret}&",
"{\"count\":177,\"numbers\":[{\"country\":\"US\",\"msisdn\":\"15102694548\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568490\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568491\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568492\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568973\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"}]}");

var results = Number.Search(new Number.SearchRequest
Expand Down
41 changes: 41 additions & 0 deletions Nexmo.Api.Test.Unit/VoiceStreamTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nexmo.Api.Voice;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Nexmo.Api.Test.Unit
{
[TestClass]
public class VoiceStreamTest
{
[TestMethod]
public void TestStreamLoopZero()
{
//Arrange
var expected = "{\"stream_url\":[\"https://example.com/waiting.mp3\"],\"loop\":0}";
var request = new Call.StreamCommand() { loop = 0, stream_url = new[] { "https://example.com/waiting.mp3" } };
//Act
var serialized = JsonConvert.SerializeObject(request,
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
//Assert
Assert.AreEqual(expected, serialized);
}

[TestMethod]
public void TestStreamLoopEmpty()
{
//Arrange
var expected = "{\"stream_url\":[\"https://example.com/waiting.mp3\"]}";
var request = new Call.StreamCommand() {stream_url = new[] { "https://example.com/waiting.mp3" } };
//Act
var serialized = JsonConvert.SerializeObject(request,
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
//Assert
Assert.AreEqual(expected, serialized);
}
}
}
36 changes: 36 additions & 0 deletions Nexmo.Api.Test.Unit/VoiceTalkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Nexmo.Api.Voice;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Nexmo.Api.Test.Unit
{
[TestClass]
public class VoiceTalkTest
{
[TestMethod]
public void TestTalkLoopZero()
{
//Arrange
var expected = "{\"text\":\"hello world\",\"loop\":0}";
var request = new Call.TalkCommand() { loop = 0, text = "hello world" };
//Act
var serialized = JsonConvert.SerializeObject(request,
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
//Assert
Assert.AreEqual(expected, serialized);
}

[TestMethod]
public void TestTalkLoopEmpty()
{
//Arrange
var expected = "{\"text\":\"hello world\"}";
var request = new Call.TalkCommand() {text = "hello world" };
//Act
var serialized = JsonConvert.SerializeObject(request,
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
//Assert
Assert.AreEqual(expected, serialized);
}
}
}
3 changes: 2 additions & 1 deletion Nexmo.Api/Voice/Call.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class StreamCommand
/// <summary>
/// Set to 0 to replay the audio file at stream_url when the stream ends.
/// </summary>
public int loop { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Ignore)]
public int? loop { get; set; }
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion Nexmo.Api/Voice/Call.Talk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class TalkCommand
/// <summary>
/// Set to 0 to replay the audio file at stream_url when the stream ends. The default value is 1.
/// </summary>
public int loop { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Ignore)]
public int? loop { get; set; }
}

public class DtmfCommand
Expand Down

0 comments on commit a51d9ec

Please sign in to comment.