Skip to content

Commit

Permalink
Merge branch 'evgeni-nabokov-all-contributors/add-PlayBehavior-to-Ssm…
Browse files Browse the repository at this point in the history
…lOutputSpeech'
  • Loading branch information
timheuer committed Sep 3, 2019
2 parents d62765e + fa6c490 commit 2e87131
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Alexa.NET.Tests/Alexa.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<None Update="Examples\PlainTextOutputSpeech.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\PlainTextOutputSpeechWithPlayBehavior.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\PrintImageConnection.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -110,6 +113,9 @@
<None Update="Examples\SsmlOutputSpeech.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\SsmlOutputSpeechWithPlayBehavior.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\StandardCard.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "PlainText",
"text": "text content",
"playBehavior": "REPLACE_ALL"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "SSML",
"ssml": "ssml content",
"playBehavior": "REPLACE_ENQUEUED"
}
71 changes: 59 additions & 12 deletions Alexa.NET.Tests/ResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,7 @@ public void Should_create_same_json_response_as_example()
}
};

var json = JsonConvert.SerializeObject(skillResponse, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});

const string example = "Response.json";
var workingJson = File.ReadAllText(Path.Combine(ExamplesPath, example));

workingJson = Regex.Replace(workingJson, @"\s", "");
json = Regex.Replace(json, @"\s", "");

Assert.Equal(workingJson, json);
Assert.True(Utility.CompareJson(skillResponse, "Response.json"));
}

[Fact]
Expand Down Expand Up @@ -248,6 +237,13 @@ public void DeserializesExampleAskForPermissionsConsentJson()
Assert.Equal("read::alexa:household:list", card.Permissions.First());
}

[Fact]
public void SerializesPlainTextOutputSpeechToJson()
{
var plainTextOutputSpeech = new PlainTextOutputSpeech { Text = "text content" };
Assert.True(Utility.CompareJson(plainTextOutputSpeech, "PlainTextOutputSpeech.json"));
}

[Fact]
public void DeserializesExamplePlainTextOutputSpeechJson()
{
Expand All @@ -259,6 +255,35 @@ public void DeserializesExamplePlainTextOutputSpeechJson()

Assert.Equal("PlainText", outputSpeech.Type);
Assert.Equal("text content", outputSpeech.Text);
Assert.Equal(null, outputSpeech.PlayBehavior);
}

[Fact]
public void SerializesPlainTextOutputSpeechWithPlayBehaviorToJson()
{
var plainTextOutputSpeech = new PlainTextOutputSpeech { Text = "text content", PlayBehavior = PlayBehavior.ReplaceAll };
Assert.True(Utility.CompareJson(plainTextOutputSpeech, "PlainTextOutputSpeechWithPlayBehavior.json"));
}

[Fact]
public void DeserializesExamplePlainTextOutputSpeechWithPlayBehaviorJson()
{
var deserialized = Utility.ExampleFileContent<IOutputSpeech>("PlainTextOutputSpeechWithPlayBehavior.json");

Assert.Equal(typeof(PlainTextOutputSpeech), deserialized.GetType());

var outputSpeech = (PlainTextOutputSpeech)deserialized;

Assert.Equal("PlainText", outputSpeech.Type);
Assert.Equal("text content", outputSpeech.Text);
Assert.Equal(PlayBehavior.ReplaceAll, outputSpeech.PlayBehavior);
}

[Fact]
public void SerializesSsmlOutputSpeechToJson()
{
var ssmlOutputSpeech = new SsmlOutputSpeech { Ssml = "ssml content" };
Assert.True(Utility.CompareJson(ssmlOutputSpeech, "SsmlOutputSpeech.json"));
}

[Fact]
Expand All @@ -272,6 +297,28 @@ public void DeserializesExampleSsmlOutputSpeechJson()

Assert.Equal("SSML", outputSpeech.Type);
Assert.Equal("ssml content", outputSpeech.Ssml);
Assert.Equal(null, outputSpeech.PlayBehavior);
}

[Fact]
public void SerializesSsmlOutputSpeechWithPlayBehaviorToJson()
{
var ssmlOutputSpeech = new SsmlOutputSpeech { Ssml = "ssml content", PlayBehavior = PlayBehavior.ReplaceEnqueued };
Assert.True(Utility.CompareJson(ssmlOutputSpeech, "SsmlOutputSpeechWithPlayBehavior.json"));
}

[Fact]
public void DeserializesExampleSsmlOutputSpeechWithPlayBehaviorJson()
{
var deserialized = Utility.ExampleFileContent<IOutputSpeech>("SsmlOutputSpeechWithPlayBehavior.json");

Assert.Equal(typeof(SsmlOutputSpeech), deserialized.GetType());

var outputSpeech = (SsmlOutputSpeech)deserialized;

Assert.Equal("SSML", outputSpeech.Type);
Assert.Equal("ssml content", outputSpeech.Ssml);
Assert.Equal(PlayBehavior.ReplaceEnqueued, outputSpeech.PlayBehavior);
}

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions Alexa.NET/Response/IOutputSpeech.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Alexa.NET.Response.Converters;
using Alexa.NET.Response.Directive;
using Newtonsoft.Json;

namespace Alexa.NET.Response
{
[JsonConverter(typeof(OutputSpeechConverter))]
public interface IOutputSpeech : IResponse
{
PlayBehavior? PlayBehavior { get; set; }
}
}
6 changes: 6 additions & 0 deletions Alexa.NET/Response/PlainTextOutputSpeech.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Alexa.NET.Response.Directive;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Alexa.NET.Response
{
Expand All @@ -14,5 +16,9 @@ public string Type
[JsonRequired]
[JsonProperty("text")]
public string Text { get; set; }

[JsonProperty("playBehavior", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public PlayBehavior? PlayBehavior { get; set; }
}
}
6 changes: 6 additions & 0 deletions Alexa.NET/Response/SsmlOutputSpeech.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Alexa.NET.Response.Directive;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Alexa.NET.Response
{
Expand All @@ -14,5 +16,9 @@ public string Type
[JsonRequired]
[JsonProperty("ssml")]
public string Ssml { get; set; }

[JsonProperty("playBehavior", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public PlayBehavior? PlayBehavior { get; set; }
}
}

0 comments on commit 2e87131

Please sign in to comment.