diff --git a/src/LondonTravel.Skill/AlexaFunction.cs b/src/LondonTravel.Skill/AlexaFunction.cs
index 31ccda54..b495a8f1 100644
--- a/src/LondonTravel.Skill/AlexaFunction.cs
+++ b/src/LondonTravel.Skill/AlexaFunction.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
using MartinCostello.LondonTravel.Skill.Extensions;
using MartinCostello.LondonTravel.Skill.Intents;
using Microsoft.ApplicationInsights;
@@ -72,15 +71,15 @@ public async virtual ValueTask DisposeAsync()
/// Handles a request to the skill as an asynchronous operation.
///
/// The skill request.
- /// The AWS Lambda execution context.
///
/// A representing the asynchronous operation to get the skill's response.
///
- public async Task HandlerAsync(SkillRequest request, ILambdaContext context)
+ public async Task HandlerAsync(SkillRequest request)
{
- context.Logger.LogLine($"Invoking skill request of type {request.Request.GetType().Name}.");
-
var handler = _serviceProvider.GetRequiredService();
+ var logger = _serviceProvider.GetRequiredService>();
+
+ Log.InvokingSkillRequest(logger, request.Request.Type);
return await handler.HandleAsync(request);
}
diff --git a/src/LondonTravel.Skill/AlexaFunctionHandler.cs b/src/LondonTravel.Skill/AlexaFunctionHandler.cs
index 22930761..cad8b657 100644
--- a/src/LondonTravel.Skill/AlexaFunctionHandler.cs
+++ b/src/LondonTravel.Skill/AlexaFunctionHandler.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -19,14 +18,13 @@ public static class AlexaFunctionHandler
/// Handles a request to the skill as an asynchronous operation.
///
/// The skill request.
- /// The current Lambda context.
///
/// A representing the asynchronous operation to get the skill's response.
///
- public static async Task HandleAsync(SkillRequest request, ILambdaContext context)
+ public static async Task HandleAsync(SkillRequest request)
{
await EnsureInitialized();
- return await _function.HandlerAsync(request, context);
+ return await _function.HandlerAsync(request);
}
private static async Task EnsureInitialized()
diff --git a/src/LondonTravel.Skill/Log.cs b/src/LondonTravel.Skill/Log.cs
index 6651f502..ac879f2b 100644
--- a/src/LondonTravel.Skill/Log.cs
+++ b/src/LondonTravel.Skill/Log.cs
@@ -51,4 +51,10 @@ public static partial void SystemError(
Level = LogLevel.Warning,
Message = "Unknown intent {IntentName} cannot be handled for session Id {SessionId}.")]
public static partial void UnknownIntent(ILogger logger, string intentName, string sessionId);
+
+ [LoggerMessage(
+ EventId = 7,
+ Level = LogLevel.Information,
+ Message = "Invoking skill request of type {RequestType}.")]
+ public static partial void InvokingSkillRequest(ILogger logger, string requestType);
}
diff --git a/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs b/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs
index e6cd27d2..cb341704 100644
--- a/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs
+++ b/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -14,10 +13,9 @@ public async Task Can_Invoke_Static_Function()
{
// Arrange
SkillRequest request = CreateIntentRequest("AMAZON.HelpIntent");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await AlexaFunctionHandler.HandleAsync(request, context);
+ SkillResponse actual = await AlexaFunctionHandler.HandleAsync(request);
// Assert
ResponseBody response = AssertResponse(actual, shouldEndSession: false);
@@ -26,7 +24,7 @@ public async Task Can_Invoke_Static_Function()
response.OutputSpeech.Type.ShouldBe("SSML");
// Act
- actual = await AlexaFunctionHandler.HandleAsync(request, context);
+ actual = await AlexaFunctionHandler.HandleAsync(request);
// Assert
response = AssertResponse(actual, shouldEndSession: false);
diff --git a/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs b/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs
index 2a497289..8b27499f 100644
--- a/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs
+++ b/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs
@@ -4,7 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -19,11 +18,9 @@ public async Task Cannot_Invoke_Function_If_Application_Id_Incorrect()
SkillRequest request = CreateIntentRequest("AMAZON.HelpIntent");
request.Session.Application.ApplicationId = "not-my-skill-id";
- ILambdaContext context = CreateContext();
-
// Act
InvalidOperationException exception = await Assert.ThrowsAsync(
- () => function.HandlerAsync(request, context));
+ () => function.HandlerAsync(request));
// Assert
exception.Message.ShouldBe("Request application Id 'not-my-skill-id' and configured skill Id 'my-skill-id' mismatch.");
@@ -43,10 +40,8 @@ public async Task Can_Invoke_Function_If_Locale_Is_Invalid(string locale)
SkillRequest request = CreateIntentRequest("AMAZON.HelpIntent");
request.Request.Locale = locale;
- ILambdaContext context = CreateContext();
-
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual, shouldEndSession: false);
@@ -60,7 +55,6 @@ public async Task Cannot_Invoke_Function_With_System_Failure()
{
// Arrange
AlexaFunction function = await CreateFunctionAsync();
- ILambdaContext context = CreateContext();
var error = new SystemExceptionRequest()
{
@@ -78,7 +72,7 @@ public async Task Cannot_Invoke_Function_With_System_Failure()
var request = CreateRequest(error);
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/CancelTests.cs b/test/LondonTravel.Skill.Tests/CancelTests.cs
index 671cfa4f..7350f9d4 100644
--- a/test/LondonTravel.Skill.Tests/CancelTests.cs
+++ b/test/LondonTravel.Skill.Tests/CancelTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -16,10 +15,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest("AMAZON.CancelIntent");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/CommuteTests.cs b/test/LondonTravel.Skill.Tests/CommuteTests.cs
index 1c79c773..ef034b79 100644
--- a/test/LondonTravel.Skill.Tests/CommuteTests.cs
+++ b/test/LondonTravel.Skill.Tests/CommuteTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
using JustEat.HttpClientInterception;
namespace MartinCostello.LondonTravel.Skill;
@@ -16,10 +15,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Is_Not_Linked()
// Arrange
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: null);
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
@@ -44,10 +42,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Token_Is_Invalid()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: "invalid-access-token");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
@@ -70,10 +67,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Api_Fails()
// Arrange
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: "random-access-token");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
@@ -97,10 +93,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Is_Linked_And_Has_No_Favori
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: "token-for-no-favorites");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
@@ -118,10 +113,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Is_Linked_And_Has_One_Favor
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: "token-for-one-favorite");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
@@ -139,10 +133,9 @@ public async Task Can_Invoke_Function_When_The_Skill_Is_Linked_And_Has_Two_Favor
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequestWithToken(accessToken: "token-for-two-favorites");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
diff --git a/test/LondonTravel.Skill.Tests/DisruptionTests.cs b/test/LondonTravel.Skill.Tests/DisruptionTests.cs
index 6288af9a..3966886d 100644
--- a/test/LondonTravel.Skill.Tests/DisruptionTests.cs
+++ b/test/LondonTravel.Skill.Tests/DisruptionTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
using JustEat.HttpClientInterception;
namespace MartinCostello.LondonTravel.Skill;
@@ -18,10 +17,9 @@ public async Task Can_Invoke_Function_When_There_Are_No_Disruptions()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
@@ -38,10 +36,9 @@ public async Task Can_Invoke_Function_When_There_Is_One_Disruption()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
@@ -58,10 +55,9 @@ public async Task Can_Invoke_Function_When_There_Are_Multiple_Disruptions()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(
@@ -76,10 +72,9 @@ public async Task Can_Invoke_Function_When_The_Api_Fails()
// Arrange
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/FunctionTests.cs b/test/LondonTravel.Skill.Tests/FunctionTests.cs
index caba4e75..97b4be30 100644
--- a/test/LondonTravel.Skill.Tests/FunctionTests.cs
+++ b/test/LondonTravel.Skill.Tests/FunctionTests.cs
@@ -4,8 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
-using Amazon.Lambda.TestUtilities;
using JustEat.HttpClientInterception;
using MartinCostello.Logging.XUnit;
using Microsoft.Extensions.DependencyInjection;
@@ -50,14 +48,6 @@ protected virtual SkillConfiguration CreateConfiguration()
return config;
}
- protected virtual ILambdaContext CreateContext()
- {
- return new TestLambdaContext()
- {
- Logger = new XunitLambdaLogger(OutputHelper),
- };
- }
-
protected virtual async Task CreateFunctionAsync()
{
SkillConfiguration config = CreateConfiguration();
diff --git a/test/LondonTravel.Skill.Tests/HelpTests.cs b/test/LondonTravel.Skill.Tests/HelpTests.cs
index dc6c5b26..354cfd20 100644
--- a/test/LondonTravel.Skill.Tests/HelpTests.cs
+++ b/test/LondonTravel.Skill.Tests/HelpTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -16,10 +15,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest("AMAZON.HelpIntent");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual, shouldEndSession: false);
diff --git a/test/LondonTravel.Skill.Tests/LaunchTests.cs b/test/LondonTravel.Skill.Tests/LaunchTests.cs
index bf703236..3f51b034 100644
--- a/test/LondonTravel.Skill.Tests/LaunchTests.cs
+++ b/test/LondonTravel.Skill.Tests/LaunchTests.cs
@@ -4,7 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -17,10 +16,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual, shouldEndSession: false);
diff --git a/test/LondonTravel.Skill.Tests/SessionEndedTests.cs b/test/LondonTravel.Skill.Tests/SessionEndedTests.cs
index f60e2189..0686d547 100644
--- a/test/LondonTravel.Skill.Tests/SessionEndedTests.cs
+++ b/test/LondonTravel.Skill.Tests/SessionEndedTests.cs
@@ -4,7 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -17,10 +16,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/StatusTests.cs b/test/LondonTravel.Skill.Tests/StatusTests.cs
index ebf0144e..8fc86489 100644
--- a/test/LondonTravel.Skill.Tests/StatusTests.cs
+++ b/test/LondonTravel.Skill.Tests/StatusTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
using JustEat.HttpClientInterception;
namespace MartinCostello.LondonTravel.Skill;
@@ -50,10 +49,9 @@ public async Task Can_Invoke_Function_For_Valid_Line(string id)
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentForLine(id);
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertLineResponse(actual);
@@ -69,10 +67,9 @@ public async Task Can_Invoke_Function_For_Invalid_Line(string id)
// Arrange
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentForLine(id);
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
@@ -102,10 +99,9 @@ public async Task Can_Invoke_Function_When_The_Api_Fails()
// Arrange
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentForLine("district");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
@@ -145,10 +141,9 @@ public async Task Can_Invoke_Function_For_Different_Severities(
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentForLine(id);
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertLineResponse(actual, expectedSsml: "" + expected + "");
diff --git a/test/LondonTravel.Skill.Tests/StopTests.cs b/test/LondonTravel.Skill.Tests/StopTests.cs
index 79e8dd06..e3e9ac86 100644
--- a/test/LondonTravel.Skill.Tests/StopTests.cs
+++ b/test/LondonTravel.Skill.Tests/StopTests.cs
@@ -3,7 +3,6 @@
using Alexa.NET.Request;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -16,10 +15,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateIntentRequest("AMAZON.StopIntent");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs b/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs
index b5d7da27..26a0abd9 100644
--- a/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs
+++ b/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs
@@ -4,7 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -18,10 +17,9 @@ public async Task Can_Invoke_Function()
await function.InitializeAsync();
SkillRequest request = CreateIntentRequest("FooIntent");
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
ResponseBody response = AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs b/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs
index 8ed5335f..6075b35b 100644
--- a/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs
+++ b/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs
@@ -4,7 +4,6 @@
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
-using Amazon.Lambda.Core;
namespace MartinCostello.LondonTravel.Skill;
@@ -17,10 +16,9 @@ public async Task Can_Invoke_Function()
AlexaFunction function = await CreateFunctionAsync();
SkillRequest request = CreateRequest();
- ILambdaContext context = CreateContext();
// Act
- SkillResponse actual = await function.HandlerAsync(request, context);
+ SkillResponse actual = await function.HandlerAsync(request);
// Assert
AssertResponse(actual);
diff --git a/test/LondonTravel.Skill.Tests/XunitLambdaLogger.cs b/test/LondonTravel.Skill.Tests/XunitLambdaLogger.cs
deleted file mode 100644
index de40b291..00000000
--- a/test/LondonTravel.Skill.Tests/XunitLambdaLogger.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) Martin Costello, 2017. All rights reserved.
-// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
-
-using Amazon.Lambda.Core;
-
-namespace MartinCostello.LondonTravel.Skill;
-
-internal sealed class XunitLambdaLogger(ITestOutputHelper outputHelper) : ILambdaLogger
-{
- public void Log(string message)
- {
- outputHelper.WriteLine(message);
- }
-
- public void LogLine(string message)
- {
- outputHelper.WriteLine(message);
- }
-}