public async Task ShouldCallLambdaWithEachMessage( SnsRecord <TestLambdaMessage> record, ServiceCollection serviceCollection, JsonSerializer serializer, ILogger logger, [Substitute] TestSnsLambda lambda ) { var request = new SnsEvent <TestLambdaMessage>(new[] { record }); serviceCollection.AddSingleton <ISerializer>(serializer); var serviceProvider = serviceCollection.BuildServiceProvider(); var cancellationToken = new CancellationToken(false); var host = new TestSnsLambdaHost(lambdaHost => { lambdaHost.Lambda = lambda; lambdaHost.Scope = serviceProvider.CreateScope(); lambdaHost.Serializer = serializer; lambdaHost.Logger = logger; }); using var inputStream = await StreamUtils.CreateJsonStream(request); await host.InvokeLambda(inputStream, cancellationToken); await lambda.Received().Handle(Matches(record.Sns), Is(cancellationToken)); }
public async Task ShouldThrowIfEventDeserializesToNull( ServiceCollection serviceCollection, JsonSerializer serializer, ILogger logger, [Substitute] TestSnsLambda lambda ) { serviceCollection.AddSingleton <ISerializer>(serializer); var serviceProvider = serviceCollection.BuildServiceProvider(); var cancellationToken = new CancellationToken(false); var host = new TestSnsLambdaHost(lambdaHost => { lambdaHost.Lambda = lambda; lambdaHost.Scope = serviceProvider.CreateScope(); lambdaHost.Serializer = serializer; lambdaHost.Logger = logger; }); using var inputStream = await StreamUtils.CreateJsonStream <object?>(null); Func <Task> func = () => host.InvokeLambda(inputStream, cancellationToken); await func.Should().ThrowAsync <InvalidLambdaParameterException>(); }