diff --git a/src/LondonTravel.Skill/AlexaFunction.cs b/src/LondonTravel.Skill/AlexaFunction.cs index fd9df1d4..2334272a 100644 --- a/src/LondonTravel.Skill/AlexaFunction.cs +++ b/src/LondonTravel.Skill/AlexaFunction.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Extensions; using MartinCostello.LondonTravel.Skill.Intents; using MartinCostello.LondonTravel.Skill.Models; @@ -69,15 +68,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.Type}."); - var handler = _serviceProvider.GetRequiredService(); + var logger = _serviceProvider.GetRequiredService>(); + + Log.InvokingSkillRequest(logger, request.Request.Type); var converted = request.FromModel(); diff --git a/src/LondonTravel.Skill/AlexaFunctionHandler.cs b/src/LondonTravel.Skill/AlexaFunctionHandler.cs index 01fd5d1a..87cb7154 100644 --- a/src/LondonTravel.Skill/AlexaFunctionHandler.cs +++ b/src/LondonTravel.Skill/AlexaFunctionHandler.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -18,14 +17,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 0cbca375..1f58e632 100644 --- a/src/LondonTravel.Skill/Log.cs +++ b/src/LondonTravel.Skill/Log.cs @@ -63,4 +63,10 @@ public static partial void SystemError( Level = LogLevel.Debug, Message = "Ended session for user Id {UserId} and session Id {SessionId}.")] public static partial void SessionEnded(ILogger logger, string userId, string sessionId); + + [LoggerMessage( + EventId = 9, + 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 56fe3137..a3916547 100644 --- a/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs +++ b/test/LondonTravel.Skill.Tests/AlexaFunctionHandlerTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -13,10 +12,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); @@ -25,7 +23,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 22b83cac..0633a459 100644 --- a/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs +++ b/test/LondonTravel.Skill.Tests/AlexaFunctionTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -18,11 +17,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."); @@ -42,10 +39,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); @@ -59,7 +54,6 @@ public async Task Cannot_Invoke_Function_With_System_Failure() { // Arrange AlexaFunction function = await CreateFunctionAsync(); - ILambdaContext context = CreateContext(); var error = new Request() { @@ -77,7 +71,7 @@ public async Task Cannot_Invoke_Function_With_System_Failure() var request = CreateRequest("System.ExceptionEncountered", error); // Act - SkillResponse actual = await function.HandlerAsync(request, context); + SkillResponse actual = await function.HandlerAsync(request); // Assert await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/CancelTests.cs b/test/LondonTravel.Skill.Tests/CancelTests.cs index ca0b2def..be49dc25 100644 --- a/test/LondonTravel.Skill.Tests/CancelTests.cs +++ b/test/LondonTravel.Skill.Tests/CancelTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; 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 await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/CommuteTests.cs b/test/LondonTravel.Skill.Tests/CommuteTests.cs index 51e67c13..d9bbd48c 100644 --- a/test/LondonTravel.Skill.Tests/CommuteTests.cs +++ b/test/LondonTravel.Skill.Tests/CommuteTests.cs @@ -1,7 +1,6 @@ // 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; using JustEat.HttpClientInterception; using MartinCostello.LondonTravel.Skill.Models; @@ -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 await Verify(actual); @@ -46,10 +44,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 await Verify(actual); @@ -74,10 +71,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 await Verify(actual); @@ -103,10 +99,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 await Verify(actual); @@ -126,10 +121,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 await Verify(actual); @@ -149,10 +143,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 await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/DisruptionTests.cs b/test/LondonTravel.Skill.Tests/DisruptionTests.cs index 3c475037..c551f8b8 100644 --- a/test/LondonTravel.Skill.Tests/DisruptionTests.cs +++ b/test/LondonTravel.Skill.Tests/DisruptionTests.cs @@ -1,7 +1,6 @@ // 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; using JustEat.HttpClientInterception; using MartinCostello.LondonTravel.Skill.Models; @@ -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 await Verify(actual); @@ -40,10 +38,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 await Verify(actual); @@ -62,10 +59,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 await Verify(actual); @@ -82,10 +78,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 await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/FunctionTests.cs b/test/LondonTravel.Skill.Tests/FunctionTests.cs index 5b94ed68..bfe1cd43 100644 --- a/test/LondonTravel.Skill.Tests/FunctionTests.cs +++ b/test/LondonTravel.Skill.Tests/FunctionTests.cs @@ -1,8 +1,6 @@ // 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; -using Amazon.Lambda.TestUtilities; using JustEat.HttpClientInterception; using MartinCostello.Logging.XUnit; using MartinCostello.LondonTravel.Skill.Models; @@ -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 e53c4c61..dfd89e6a 100644 --- a/test/LondonTravel.Skill.Tests/HelpTests.cs +++ b/test/LondonTravel.Skill.Tests/HelpTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; 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 await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/LaunchTests.cs b/test/LondonTravel.Skill.Tests/LaunchTests.cs index 40c626f2..6bfc240e 100644 --- a/test/LondonTravel.Skill.Tests/LaunchTests.cs +++ b/test/LondonTravel.Skill.Tests/LaunchTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -16,10 +15,9 @@ public async Task Can_Invoke_Function() AlexaFunction function = await CreateFunctionAsync(); SkillRequest request = CreateRequest("LaunchRequest"); - ILambdaContext context = CreateContext(); // Act - SkillResponse actual = await function.HandlerAsync(request, context); + SkillResponse actual = await function.HandlerAsync(request); // Assert await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/SessionEndedTests.cs b/test/LondonTravel.Skill.Tests/SessionEndedTests.cs index f2f2811b..a192f847 100644 --- a/test/LondonTravel.Skill.Tests/SessionEndedTests.cs +++ b/test/LondonTravel.Skill.Tests/SessionEndedTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -16,10 +15,9 @@ public async Task Can_Invoke_Function() AlexaFunction function = await CreateFunctionAsync(); SkillRequest request = CreateRequest("SessionEndedRequest"); - ILambdaContext context = CreateContext(); // Act - SkillResponse actual = await function.HandlerAsync(request, context); + SkillResponse actual = await function.HandlerAsync(request); // Assert await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/StatusTests.cs b/test/LondonTravel.Skill.Tests/StatusTests.cs index 6e4a7506..f27c9824 100644 --- a/test/LondonTravel.Skill.Tests/StatusTests.cs +++ b/test/LondonTravel.Skill.Tests/StatusTests.cs @@ -1,7 +1,6 @@ // 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; using JustEat.HttpClientInterception; using MartinCostello.LondonTravel.Skill.Models; @@ -18,10 +17,9 @@ public async Task Can_Invoke_Function_For_Valid_Line() AlexaFunction function = await CreateFunctionAsync(); SkillRequest request = CreateIntentForLine("northern"); - ILambdaContext context = CreateContext(); // Act - SkillResponse actual = await function.HandlerAsync(request, context); + SkillResponse actual = await function.HandlerAsync(request); // Assert await Verify(actual); @@ -67,10 +65,9 @@ public async Task Can_Invoke_Function_For_Valid_Lines(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); @@ -86,10 +83,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); @@ -119,10 +115,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 await Verify(actual); @@ -164,10 +159,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 0d5380c4..1830a971 100644 --- a/test/LondonTravel.Skill.Tests/StopTests.cs +++ b/test/LondonTravel.Skill.Tests/StopTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; 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 await Verify(actual); diff --git a/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs b/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs index 65ea37f8..7ce203ee 100644 --- a/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs +++ b/test/LondonTravel.Skill.Tests/UnknownIntentTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -16,10 +15,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 182fc318..4bab1edd 100644 --- a/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs +++ b/test/LondonTravel.Skill.Tests/UnknownRequestTests.cs @@ -1,7 +1,6 @@ // 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; using MartinCostello.LondonTravel.Skill.Models; namespace MartinCostello.LondonTravel.Skill; @@ -16,10 +15,8 @@ public async Task Can_Invoke_Function() SkillRequest request = CreateRequest("Unknown"); - 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); - } -}