private async Task <InvokeRequest> CreateLambdaRequest(LambdaInvocationRequest systemRequest)
        {
            var request = new InvokeRequest();

            request.FunctionName   = systemRequest.FunctionName;
            request.InvocationType = new InvocationTypeConverter().Convert(systemRequest.InvocationType);

            request.Payload = await new FileContentReader().ReadFileAsync(systemRequest.PayloadFilePath);
            request.LogType = LogType.Tail;

            return(request);
        }
        public async Task <LambdaSizeCalculationResultItem> RunTestAsync(LambdaInvocationRequest invocationRequest)
        {
            Console.WriteLine("Starting config fetch prior to test run");

            var settings = await _client.GetFunctionConfigurationAsync(invocationRequest.FunctionName);

            var memory = settings.MemorySize;

            Console.WriteLine("Starting dry run");
            await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest));

            Console.WriteLine("Starting test run # 1");
            var response = await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest));

            Console.WriteLine("Starting test run # 2");
            var response2 = await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest));

            if (response.StatusCode > 299 || response.StatusCode < 200)
            {
                throw new InvalidProgramException($"The Lambda which was invoked with the given payload returned with a status code not in the 200 series. The status code was '{response.StatusCode}'");
            }
            if (response2.StatusCode > 299 || response2.StatusCode < 200)
            {
                throw new InvalidProgramException($"The Lambda which was invoked with the given payload returned with a status code not in the 200 series. The status code was '{response2.StatusCode}'");
            }
            var log1 = response.LogResult;

            var item1 = ParseResultFromLog(log1, memory);

            var log2 = response2.LogResult;

            var item2 = ParseResultFromLog(log2, memory);

            var item = item2.Latency < item1.Latency ? item2 : item1;

            Console.WriteLine($"Selected best out of two test result:{item.ToString()}");

            return(item);
        }