public async Task NegativeBootstrapInitTestsAsync() { var ucl = new UserCodeLoader("NonExistentAssembly::HandlerTest.CustomerType::ZeroInZeroOut", _internalLogger); var ex = Assert.Throws <LambdaValidationException>(() => ucl.Init(NoOpLoggingAction)); Assert.Contains("Could not find the specified handler", ex.Message); await TestHandlerFailAsync($"HandlerTest2::Type::Method", "Could not find the specified handler assembly with the file name"); await TestHandlerFailAsync("HandlerTest::HandlerTest.FakeCustomerType::PocoInPocoOut", "Unable to load type"); await TestHandlerFailAsync("HandlerTest::HandlerTest.GenericCustomerType`1::PocoInPocoOut", "Handler methods cannot be located in generic types."); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::FakeMethod", "Found no methods matching method name 'FakeMethod'"); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::HandlerTest.CustomerPoco FakeMethod(HandlerTest.CustomerPoco)", "Found no methods matching method name '"); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::OverloadedMethod", "appears to have a number of overloads. To call this method please specify a complete method signature."); await TestHandlerFailAsync("HandlerTest::HandlerTest.AbstractCustomerType::AbstractMethod", "Please specify a non-abstract handler method."); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::GenericMethod", "Handler methods cannot be generic."); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::TwoInputsNoContextMethod", "is not supported: the method has 2 parameters, but the second parameter is not of type"); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::TooManyInputsMethod", "is not supported: the method has more than 2 parameters."); await TestHandlerFailAsync("HandlerTestNoSerializer::HandlerTestNoSerializer.CustomerType::PocoInPocoOut", "To use types other than System.IO.Stream as input/output parameters, the assembly or Lambda function should be annotated with Amazon.Lambda.LambdaSerializerAttribute."); await TestHandlerFailAsync("HandlerTestNoSerializer::HandlerTestNoSerializer.CustomerType::PocoInPocoOut", "To use types other than System.IO.Stream as input/output parameters, the assembly or Lambda function should be annotated with Amazon.Lambda.LambdaSerializerAttribute."); var noZeroParamTypeEx = await TestHandlerFailAsync("HandlerTest::HandlerTest.NoZeroParamConstructorCustomerType::SimpleMethod", "No parameterless constructor defined for this object."); Assert.IsAssignableFrom <MissingMethodException>(noZeroParamTypeEx); var customerConstructorEx = TestHandlerFailAsync("HandlerTest::HandlerTest.ConstructorExceptionCustomerType::SimpleMethod", "An exception was thrown when the constructor for type"); Assert.NotNull(customerConstructorEx); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::NoZeroParameterConstructorCustomerTypeSerializerMethod", "does not define a public zero-parameter constructor"); await TestHandlerFailAsync("HandlerTest::HandlerTest.CustomerType::NoInterfaceCustomerTypeSerializerMethod", "it does not implement the 'ILambdaSerializer' interface."); await TestHandlerFailAsync("HandlerTest::HandlerTest.StaticCustomerTypeThrows::StaticCustomerMethodZeroOut", "StaticCustomerTypeThrows static constructor has thrown an exception."); }
/// Program entry point static void Main(string[] args) { AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; var handler = GetFunctionHandler(args); var body = GetEventBody(args); var lambdaContext = new MockLambdaContext(handler, body); var userCodeLoader = new UserCodeLoader(handler, InternalLogger.NO_OP_LOGGER); userCodeLoader.Init(Console.Error.WriteLine); var lambdaContextInternal = new LambdaContextInternal(lambdaContext.RemainingTime, LogAction, new Lazy <CognitoClientContextInternal>(), lambdaContext.RequestId, new Lazy <string>(lambdaContext.Arn), new Lazy <string>(string.Empty), new Lazy <string>(string.Empty), Environment.GetEnvironmentVariables()); Exception lambdaException = null; LogRequestStart(lambdaContext); try { userCodeLoader.Invoke(lambdaContext.InputStream, lambdaContext.OutputStream, lambdaContextInternal); } catch (Exception ex) { lambdaException = ex; } LogRequestEnd(lambdaContext); if (lambdaException == null) { Console.WriteLine(lambdaContext.OutputText); } else { Console.Error.WriteLine(lambdaException); } }
/// Program entry point static void Main(string[] args) { AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaContext = new MockLambdaContext(handler, body); var userCodeLoader = new UserCodeLoader(handler, InternalLogger.NO_OP_LOGGER); userCodeLoader.Init(Console.Error.WriteLine); var lambdaContextInternal = new LambdaContextInternal(lambdaContext.RemainingTime, LogAction, new Lazy <CognitoClientContextInternal>(), lambdaContext.RequestId, new Lazy <string>(lambdaContext.Arn), new Lazy <string>(string.Empty), new Lazy <string>(string.Empty), Environment.GetEnvironmentVariables()); Exception lambdaException = null; LogRequestStart(lambdaContext); try { userCodeLoader.Invoke(lambdaContext.InputStream, lambdaContext.OutputStream, lambdaContextInternal); } catch (Exception ex) { lambdaException = ex; } LogRequestEnd(lambdaContext); if (lambdaException == null) { Console.WriteLine(lambdaContext.OutputText); } else { Console.Error.WriteLine(lambdaException); } } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } }