Skip to content

Commit

Permalink
Moving test json to json files for maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-lethargic committed Jan 11, 2022
1 parent f7d2199 commit 1734147
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"dtmf": {
"timeOut": 3,
"maxDigits": 1,
"submitOnHash": true
},
"speech": {
"uuid": [
"aaaaaaaa-bbbb-cccc-dddd-0123456789ab"
],
"endOnSilence": 1,
"language": "en-US",
"context": [
"dog",
"cat"
],
"startTimeout": 5,
"maxDuration": 30
},
"action": "input"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"dtmf": {
},
"speech": {
"uuid": [
"aaaaaaaa-bbbb-cccc-dddd-0123456789ab"
]
},
"action": "input"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"speech": {
"timeout_reason": "end_on_silence_timeout",
"results": [
{
"confidence": "0.9405097",
"text": "Sales"
},
{
"confidence": "0.70543784",
"text": "Sails"
},
{
"confidence": "0.5949854",
"text": "Sale"
}
]
},
"dtmf": {
"digits": null,
"timed_out": false
},
"uuid": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"conversation_uuid": "bbbbbbbb-cccc-dddd-eeee-0123456789ab",
"timestamp": "2020-01-01T14:00:00.000Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"speech": {
"error": "Speech overridden by DTMF"
},
"dtmf": {
"digits": "1234",
"timed_out": false
},
"uuid": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"conversation_uuid": "bbbbbbbb-cccc-dddd-eeee-0123456789ab",
"timestamp": "2020-01-01T14:00:00.000Z"
}
31 changes: 31 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/CreateCall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"to": [
{
"number": "14155550100",
"dtmfAnswer": "p*123#",
"type": "phone"
}
],
"from": {
"number": "14155550100",
"dtmfAnswer": "p*123#",
"type": "phone"
},
"ncco": [
{
"text": "Hello World",
"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
}
31 changes: 31 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/CreateCallAsync.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"to": [
{
"number": "14155550100",
"dtmfAnswer": "p*123#",
"type": "phone"
}
],
"from": {
"number": "14155550100",
"dtmfAnswer": "p*123#",
"type": "phone"
},
"ncco": [
{
"text": "Hello World",
"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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"to": [
{
"number": "14155550100",
"dtmfAnswer": "p*123#",
"type": "phone"
}
],
"ncco": [
{
"text": "Hello World",
"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,
"random_from_number": true
}
70 changes: 15 additions & 55 deletions Vonage.Test.Unit/MultiInputTests.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
using Xunit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vonage.Voice.Nccos;
using Newtonsoft.Json;
using Vonage.Voice.EventWebhooks;
using Newtonsoft.Json;
using Vonage.Voice.Nccos;
using Xunit;

namespace Vonage.Test.Unit
{
{
public class MultiInputTests : TestBase
{
[Fact]
public void TestSerializeNccoKitchenSink()
public void TestSerializeNccoAllProperties()
{
// arrage
var expected = @"[{""dtmf"":{""timeOut"":3,""maxDigits"":1,""submitOnHash"":true},""speech"":{""uuid"":[""aaaaaaaa-bbbb-cccc-dddd-0123456789ab""],""endOnSilence"":1,""language"":""en-US"",""context"":[""dog"",""cat""],""startTimeout"":5,""maxDuration"":30},""action"":""input""}]";
var expected = GetExpectedJson();
var settings = new SpeechSettings
{
Uuid = new[] { "aaaaaaaa-bbbb-cccc-dddd-0123456789ab" },
EndOnSilence = 1,
Language = "en-US",
Context = new string[] { "dog", "cat" },
Context = new [] { "dog", "cat" },
StartTimeout = 5,
MaxDuration = 30
};
var dtmfSettings = new DtmfSettings { MaxDigits = 1, TimeOut = 3, SubmitOnHash = true };
var inputAction = new MultiInputAction { Speech = settings, Dtmf=dtmfSettings };
var inputAction = new MultiInputAction { Speech = settings, Dtmf = dtmfSettings };

//act
var ncco = new Ncco(inputAction);
var actual = ncco.ToString();

//assert
Assert.Equal(expected, actual);
Assert.Equal(expected, actual);
}

[Fact]
public void TestSerializeNccoKitchenEmpty()
public void TestSerializeNccoAllPropertiesEmpty()
{
// arrage
var expected = @"[{""dtmf"":{},""speech"":{""uuid"":[""aaaaaaaa-bbbb-cccc-dddd-0123456789ab""]},""action"":""input""}]";
var expected = GetExpectedJson();
var settings = new SpeechSettings
{
Uuid = new[] { "aaaaaaaa-bbbb-cccc-dddd-0123456789ab" }
Expand All @@ -59,36 +55,11 @@ public void TestSerializeNccoKitchenEmpty()
public void TestWebhookSerialization()
{
//ARRANGE
var inboundString = @"{
""speech"": {
""timeout_reason"": ""end_on_silence_timeout"",
""results"": [
{
""confidence"": ""0.9405097"",
""text"": ""Sales""
},
{
""confidence"": ""0.70543784"",
""text"": ""Sails""
},
{
""confidence"": ""0.5949854"",
""text"": ""Sale""
}
]
},
""dtmf"": {
""digits"": null,
""timed_out"": false
},
""uuid"": ""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""conversation_uuid"": ""bbbbbbbb-cccc-dddd-eeee-0123456789ab"",
""timestamp"": ""2020-01-01T14:00:00.000Z""
}";
var inboundString = GetExpectedJson();

var serialized = JsonConvert.DeserializeObject<MultiInput>(inboundString);

Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", serialized.Uuid);
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", serialized.Uuid);
Assert.Equal("end_on_silence_timeout", serialized.Speech.TimeoutReason);
Assert.Equal("0.9405097", serialized.Speech.SpeechResults[0].Confidence);
Assert.Equal("Sales", serialized.Speech.SpeechResults[0].Text);
Expand All @@ -102,18 +73,7 @@ public void TestWebhookSerialization()
public void TestWebhookSerializationSpeechOveridden()
{
//ARRANGE
var inboundString = @"{
""speech"": {
""error"": ""Speech overridden by DTMF""
},
""dtmf"": {
""digits"": ""1234"",
""timed_out"": false
},
""uuid"": ""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""conversation_uuid"": ""bbbbbbbb-cccc-dddd-eeee-0123456789ab"",
""timestamp"": ""2020-01-01T14:00:00.000Z""
}";
var inboundString = GetExpectedJson();

var serialized = JsonConvert.DeserializeObject<MultiInput>(inboundString);

Expand Down
18 changes: 9 additions & 9 deletions Vonage.Test.Unit/NccoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void TestRecord()
EventMethod = "POST"
};

var ncco = new Ncco(recordAction);
var ncco = new Voice.Nccos.Ncco(recordAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -33,7 +33,7 @@ public void TestRecordMinimalist()
{
var expectedJson = @"[{""action"":""record""}]";
var recordAction = new RecordAction();
var ncco = new Ncco(recordAction);
var ncco = new Voice.Nccos.Ncco(recordAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -51,7 +51,7 @@ public void TestConversation()
CanSpeak = new[] { "6a4d6af0-55a6-4667-be90-8614e4c8e83c" },
CanHear = new[] { "6a4d6af0-55a6-4667-be90-8614e4c8e83c" }
};
var ncco = new Ncco(conversationAction);
var ncco = new Voice.Nccos.Ncco(conversationAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public void TestConnect()
RingbackTone = "http://example.com/ringbackTone.wav",
EventMethod = "POST"
};
var ncco = new Ncco(connectAction);
var ncco = new Voice.Nccos.Ncco(connectAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -101,7 +101,7 @@ public void TestTalk()
Language="en-US",
Style = 0
};
var ncco = new Ncco(talkAction);
var ncco = new Voice.Nccos.Ncco(talkAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -113,7 +113,7 @@ public void TestTalkBareBones()
{
Text = "Hello World"
};
var ncco = new Ncco(talkAction);
var ncco = new Voice.Nccos.Ncco(talkAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -128,7 +128,7 @@ public void TestStream()
Loop = "2",
Level = "0",
};
var ncco = new Ncco(talkAction);
var ncco = new Voice.Nccos.Ncco(talkAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -144,7 +144,7 @@ public void TestInput()
EventUrl = new[] { "https://example.com/ivr" },
EventMethod = "POST"
};
var ncco = new Ncco(inputAction);
var ncco = new Voice.Nccos.Ncco(inputAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand All @@ -161,7 +161,7 @@ public void TestNotify()
},
EventUrl = new[] { "https://example.com/webhooks/events" }
};
var ncco = new Ncco(notifyAction);
var ncco = new Voice.Nccos.Ncco(notifyAction);
Assert.Equal(expectedJson, ncco.ToString());
}

Expand Down
Loading

0 comments on commit 1734147

Please # to comment.