Skip to content

Commit

Permalink
Merge branch 'stoiveyp-SkillConnections'
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Jul 8, 2019
2 parents d7648ea + 3736124 commit e866b3d
Show file tree
Hide file tree
Showing 35 changed files with 817 additions and 9 deletions.
24 changes: 24 additions & 0 deletions Alexa.NET.Tests/Alexa.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<None Update="Examples\ClearQueueDirective.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\CompleteTaskDirective.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\DialogConfirmIntent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -50,6 +53,9 @@
<None Update="Examples\GetUtterance.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\LaunchRequestWithTask.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\LinkAccountCard.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -62,15 +68,33 @@
<None Update="Examples\PlainTextOutputSpeech.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\PrintImageConnection.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\PrintPDFConnection.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\PrintWebPageConnection.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\ProgressiveResponseRequest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\Response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\ScheduleFoodEstablishmentReservation.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\ScheduleTaxiReservation.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\SessionEndedRequest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\SessionResumedRequest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Examples\SimpleCard.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
7 changes: 7 additions & 0 deletions Alexa.NET.Tests/Examples/CompleteTaskDirective.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "Tasks.CompleteTask",
"status": {
"code": 200,
"message": "return as desired"
}
}
18 changes: 18 additions & 0 deletions Alexa.NET.Tests/Examples/LaunchRequestWithTask.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "LaunchRequest",
"requestId": "string",
"timestamp": "2019-07-03T00:00:00",
"locale": "string",
"originIpAddress": "string",
"task": {
"name": "AMAZON.PrintPDF",
"version": "1",
"input": {
"@type": "PrintPDFRequest",
"@version": "1",
"title": "Flywheel",
"description": "Flywheel",
"url": "http://www.example.com/flywheel.pdf"
}
}
}
12 changes: 12 additions & 0 deletions Alexa.NET.Tests/Examples/PrintImageConnection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "Connections.StartConnection",
"uri": "connection://AMAZON.PrintImage/1",
"input": {
"@type": "PrintImageRequest",
"@version": "1",
"title": "Flywheel Document",
"description": "Flywheel",
"imageType": "JPEG",
"url": "http://www.example.com/flywheel.jpeg"
}
}
15 changes: 15 additions & 0 deletions Alexa.NET.Tests/Examples/PrintPDFConnection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "Connections.StartConnection",
"uri": "connection://AMAZON.PrintPDF/1",
"input": {
"@type": "PrintPDFRequest",
"@version": "1",
"title": "title",
"description": "description",
"context": {
"providerId": "your-provider-skill-id"
},
"url": "http://www.example.com/flywheel.pdf"
},
"token": "none"
}
11 changes: 11 additions & 0 deletions Alexa.NET.Tests/Examples/PrintWebPageConnection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "Connections.StartConnection",
"uri": "connection://AMAZON.PrintWebPage/1",
"input": {
"@type": "PrintWebPageRequest",
"@version": "1",
"title": "title",
"description": "description",
"url": "http://www.example.com/flywheel.html"
}
}
24 changes: 24 additions & 0 deletions Alexa.NET.Tests/Examples/ScheduleFoodEstablishmentReservation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "Connections.StartConnection",
"uri": "connection://AMAZON.ScheduleFoodEstablishmentReservation/1",
"input": {
"@type": "ScheduleFoodEstablishmentReservationRequest",
"@version": "1",
"startTime": "2018-04-08T01:15:46Z",
"partySize": 2,
"restaurant": {
"@type": "Restaurant",
"@version": "1",
"name": "Amazon Day 1 Restaurant",
"location": {
"@type": "PostalAddress",
"@version": "1",
"streetAddress": "2121 7th Avenue",
"locality": "Seattle",
"region": "WA",
"postalCode": "98121",
"country": "US"
}
}
}
}
27 changes: 27 additions & 0 deletions Alexa.NET.Tests/Examples/ScheduleTaxiReservation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "Connections.StartConnection",
"uri": "connection://AMAZON.ScheduleTaxiReservation/1",
"input": {
"@type": "ScheduleTaxiReservationRequest",
"@version": "1",
"partySize": 4,
"pickupLocation": {
"@type": "PostalAddress",
"@version": "1",
"streetAddress": "415 106th Ave NE",
"locality": "Bellevue",
"region": "WA",
"postalCode": "98004",
"country": "US"
},
"dropoffLocation": {
"@type": "PostalAddress",
"@version": "1",
"streetAddress": "2031 6th Ave.",
"locality": "Seattle",
"region": "WA",
"postalCode": "98121",
"country": "US"
}
}
}
16 changes: 16 additions & 0 deletions Alexa.NET.Tests/Examples/SessionResumedRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "SessionResumedRequest",
"requestId": "string",
"timestamp": "2019-07-03T00:00:00",
"locale": "en-GB",
"originIpAddress": "string",
"cause": {
"type": "ConnectionCompleted",
"token": "1234",
"status": {
"code": 200,
"message": "OK"
},
"result": null
}
}
184 changes: 184 additions & 0 deletions Alexa.NET.Tests/SkillConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using Alexa.NET.ConnectionTasks;
using Alexa.NET.ConnectionTasks.Inputs;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
using Alexa.NET.Response.Directive;
using Xunit;

namespace Alexa.NET.Tests
{
public class SkillConnectionTests
{
[Fact]
public void StartConnectionDirectiveSerializesCorrectly()
{
var task = new PrintPdfV1
{
Title = "title",
Description = "description",
Url = "http://www.example.com/flywheel.pdf",
Context = new ConnectionTaskContext { ProviderId = "your-provider-skill-id" }
};
Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json");
}

[Fact]
public void StartConnectionDirectiveDeserializesCorrectly()
{
var raw = Utility.ExampleFileContent<IDirective>("PrintPDFConnection.json");
Assert.NotNull(raw);

var directive = Assert.IsType<StartConnectionDirective>(raw);
Assert.Equal("none", directive.Token);
Assert.Equal(PrintPdfV1.AssociatedUri, directive.Uri);

Assert.IsType<PrintPdfV1>(directive.Input);
}

[Fact]
public void SessionResumedSerializesProperly()
{
var task = new SessionResumedRequest
{
RequestId = "string",
Timestamp = new DateTime(2019, 07, 03),
Locale = "en-GB",
OriginIpAddress = "string",
Cause = new SessionResumedRequestCause
{
Type = "ConnectionCompleted",
Token = "1234",
Status = new TaskStatus(200, "OK")
}
};
Utility.CompareJson(task, "SessionResumedRequest.json");
}

[Fact]
public void SessionResumedDeserializesProperly()
{
var result = Utility.ExampleFileContent<Request.Type.Request>("SessionResumedRequest.json");
var request = Assert.IsType<SessionResumedRequest>(result);

Assert.Equal("1234", request.Cause.Token);
Assert.Equal(200, request.Cause.Status.Code);
Assert.Equal("OK", request.Cause.Status.Message);
}

[Fact]
public void LaunchRequestWithTaskDeserializesCorrectly()
{
var result = Utility.ExampleFileContent<LaunchRequest>("LaunchRequestWithTask.json");
Assert.NotNull(result.Task);
Assert.Equal("AMAZON.PrintPDF", result.Task.Name);
Assert.Equal("1", result.Task.Version);
Assert.IsType<PrintPdfV1>(result.Task.Input);
}

[Fact]
public void TestCompleteTaskDirective()
{
var directive = new CompleteTaskDirective(200, "return as desired");
Assert.True(Utility.CompareJson(directive, "CompleteTaskDirective.json"));
}

[Fact]
public void PrintImageConnectionComparison()
{
var directive = new PrintImageV1
{
Title = "Flywheel Document",
Description = "Flywheel",
ImageV1Type = PrintImageV1Type.JPEG,
Url = "http://www.example.com/flywheel.jpeg"
}.ToConnectionDirective();
Assert.Equal(PrintImageV1.AssociatedUri, directive.Uri);
Assert.True(Utility.CompareJson(directive, "PrintImageConnection.json"));
Assert.IsType<PrintImageV1>(Utility.ExampleFileContent<StartConnectionDirective>("PrintImageConnection.json").Input);
}

[Fact]
public void PrintPDFConnectionComparison()
{
var directive = new PrintPdfV1
{
Title = "title",
Description = "description",
Url = "http://www.example.com/flywheel.pdf",
Context = new ConnectionTaskContext { ProviderId = "your-provider-skill-id" }
}.ToConnectionDirective("none");
Assert.Equal(PrintPdfV1.AssociatedUri, directive.Uri);
Assert.True(Utility.CompareJson(directive, "PrintPDFConnection.json"));
Assert.IsType<PrintPdfV1>(Utility.ExampleFileContent<StartConnectionDirective>("PrintPDFConnection.json").Input);
}

[Fact]
public void PrintWebPageConnectionComparison()
{
var directive = new PrintWebPageV1
{
Title = "title",
Description = "description",
Url = "http://www.example.com/flywheel.html"
}.ToConnectionDirective();
Assert.Equal(PrintWebPageV1.AssociatedUri, directive.Uri);
Assert.True(Utility.CompareJson(directive, "PrintWebPageConnection.json"));
Assert.IsType<PrintPdfV1>(Utility.ExampleFileContent<StartConnectionDirective>("PrintPDFConnection.json").Input);
}

[Fact]
public void ScheduleTaxiReservationConnectionComparison()
{
var directive = new ScheduleTaxiReservation
{
PartySize = 4,
PickupLocation = new PostalAddress
{
StreetAddress = "415 106th Ave NE",
Locality = "Bellevue",
Region = "WA",
PostalCode = "98004",
Country = "US"
},
DropoffLocation = new PostalAddress
{
StreetAddress = "2031 6th Ave.",
Locality = "Seattle",
Region = "WA",
PostalCode = "98121",
Country = "US"
}
}.ToConnectionDirective();
Assert.Equal(ScheduleTaxiReservation.AssociatedUri, directive.Uri);
Assert.True(Utility.CompareJson(directive, "ScheduleTaxiReservation.json"));
Assert.IsType<ScheduleTaxiReservation>(Utility.ExampleFileContent<StartConnectionDirective>("ScheduleTaxiReservation.json").Input);
}

[Fact]
public void ScheduleFoodReservationConnectionComparison()
{
var directive = new ScheduleFoodEstablishmentReservation
{
PartySize = 2,
StartTime = new DateTime(2018,04,08,01,15,46),
Restaurant = new Restaurant
{
Name = "Amazon Day 1 Restaurant",
Location = new PostalAddress
{
StreetAddress = "2121 7th Avenue",
Locality = "Seattle",
Region = "WA",
PostalCode = "98121",
Country = "US"
}
}
}.ToConnectionDirective();
Assert.Equal(ScheduleFoodEstablishmentReservation.AssociatedUri, directive.Uri);
Assert.True(Utility.CompareJson(directive, "ScheduleFoodEstablishmentReservation.json"));
Assert.IsType<ScheduleFoodEstablishmentReservation>(Utility.ExampleFileContent<StartConnectionDirective>("ScheduleFoodEstablishmentReservation.json").Input);
}

}
}
Loading

0 comments on commit e866b3d

Please sign in to comment.