Skip to content

Commit

Permalink
Serialize streamUrl as array per docs to avoid bad request
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon committed Mar 20, 2020
1 parent b3bd241 commit 0d804c9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
32 changes: 31 additions & 1 deletion Nexmo.Api.Test.Integration/CallTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nexmo.Api.Voice;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Nexmo.Api.Voice.Nccos;

namespace Nexmo.Api.Test.Integration
{
Expand Down Expand Up @@ -34,7 +35,7 @@ public void should_call()
}

[TestMethod]
public void Should_call_with_NCCO()
public void should_call_with_NCCO()
{
dynamic TalkNCCO = new JObject();
TalkNCCO.action = "talk";
Expand Down Expand Up @@ -63,6 +64,35 @@ public void Should_call_with_NCCO()
Assert.AreEqual("started", results.status);
}

[TestMethod]
public void should_call_with_stream_NCCO()
{
var nccoObject = new Ncco(new StreamAction()
{
StreamUrl = new string[] { "https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3" }
});

var results = Call.Do(new Call.CallCommand
{
to = new[]
{
new Call.Endpoint
{
type = "phone",
number = Configuration.Instance.Settings["test_number"]
}
},
from = new Call.Endpoint
{
type = "phone",
number = Configuration.Instance.Settings["nexmo_number"]
},
NccoObj = nccoObject
});

Assert.AreEqual("started", results.status);
}

[TestMethod]
public void should_get_calls()
{
Expand Down
23 changes: 23 additions & 0 deletions Nexmo.Api.Test.Unit/StreamActionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Nexmo.Api.Voice.Nccos;

namespace Nexmo.Api.Test.Unit
{
[TestClass]
public class StreamActionTest
{
[TestMethod]
public void TestStreamUrl()
{
//Arrange
var expected = "{\"streamUrl\":[\"https://www.example.com/waiting.mp3\"],\"action\":\"stream\"}";
var action = new StreamAction() { StreamUrl = new string[] { "https://www.example.com/waiting.mp3" } };
//Act
var serialized = JsonConvert.SerializeObject(action, Formatting.None,
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
//Assert
Assert.AreEqual(expected, serialized);
}
}
}
2 changes: 1 addition & 1 deletion Nexmo.Api/Voice/Nccos/StreamAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nexmo.Api.Voice.Nccos
public class StreamAction : NccoAction
{
[JsonProperty("streamUrl")]
public string StreamUrl { get; set; }
public string[] StreamUrl { get; set; }

[JsonProperty("level")]
public string Level { get; set; }
Expand Down

0 comments on commit 0d804c9

Please sign in to comment.