Пример #1
0
    public static async Task EnqueueAsync_Validates_Parameters()
    {
        // Arrange
        LambdaTestResponse response = null !;

        // Act
        await Assert.ThrowsAsync <ArgumentNullException>("response", () => response.ReadAsStringAsync());
    }
Пример #2
0
    /// <summary>
    /// Reads the content of the specified response as a string as an asynchronous operation.
    /// </summary>
    /// <param name="response">The response to read as a string.</param>
    /// <returns>
    /// A <see cref="Task{TResult}"/> representing the asynchronous operation to
    /// read the content of the specified response as a <see langword="string"/>.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="response"/> is <see langword="null"/>.
    /// </exception>
    public static async Task <string> ReadAsStringAsync(this LambdaTestResponse response)
    {
        if (response == null)
        {
            throw new ArgumentNullException(nameof(response));
        }

        using var stream = new MemoryStream(response.Content);
        using var reader = new StreamReader(stream);

        return(await reader.ReadToEndAsync().ConfigureAwait(false));
    }
Пример #3
0
    /// <summary>
    /// Completes the request channel for the specified request.
    /// </summary>
    /// <param name="awsRequestId">The AWS request Id to complete the response for.</param>
    /// <param name="content">The raw content associated with the request's response.</param>
    /// <param name="isSuccessful">Whether the response indicates the request was successfully handled.</param>
    /// <param name="cancellationToken">The cancellation token to use.</param>
    /// <returns>
    /// A <see cref="Task"/> representing the asynchronous operation.
    /// </returns>
    private async Task CompleteRequestChannelAsync(
        string awsRequestId,
        byte[] content,
        bool isSuccessful,
        CancellationToken cancellationToken)
    {
        var context = _responses[awsRequestId];

        context.DurationTimer !.Stop();

        Logger?.LogInformation(
            "Completed processing AWS request Id {AwsRequestId} for Lambda function with ARN {FunctionArn} in {FunctionDuration} milliseconds.",
            awsRequestId,
            _options.FunctionArn,
            context.DurationTimer.ElapsedMilliseconds);

        // Make the response available to read by the enqueuer
        var response = new LambdaTestResponse(content, isSuccessful, context.DurationTimer.Elapsed);
        await context.Channel.Writer.WriteAsync(response, cancellationToken).ConfigureAwait(false);

        // Mark the channel as complete as there will be no more responses written
        context.Channel.Writer.Complete();
    }
Пример #4
0
 internal static T ReadAs <T>(this LambdaTestResponse response)
     where T : class
 {
     return(JsonSerializer.Deserialize <T>(response.Content) !);
 }