public T ExecuteRequest <T>(string eventFilePath) { var requestFilePath = Path.Combine(Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location), eventFilePath); var responseFilePath = Path.GetTempFileName(); var comamndArgument = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"/c" : $"-c"; ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = GetSystemShell(); processStartInfo.Arguments = $"{comamndArgument} dotnet run \"{requestFilePath}\" \"{responseFilePath}\""; processStartInfo.WorkingDirectory = GetTestAppDirectory(); lock (lock_process) { using var process = Process.Start(processStartInfo); process.WaitForExit(15000); if (!File.Exists(responseFilePath)) { throw new Exception("No response file found"); } using var responseFileStream = File.OpenRead(responseFilePath); var serializer = new DefaultLambdaJsonSerializer(); var response = serializer.Deserialize <T>(responseFileStream); return(response); } }
public void TestDefaultSerializer() { var serializer = new DefaultLambdaJsonSerializer(); var response = new DummyResponse { BingBong = "Joy" }; MemoryStream ms = new MemoryStream(); StreamReader streamReader = new StreamReader(ms); serializer.Serialize(response, ms); ms.Seek(0, SeekOrigin.Begin); var utf8Payload = streamReader.ReadToEnd(); var albResponse = new Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerResponse { Body = utf8Payload }; serializer.Serialize(albResponse, ms); ms.Seek(0, SeekOrigin.Begin); var json = streamReader.ReadToEnd(); Assert.Equal(106, json.Length); }
public void TestDefaultSerializerWithUnsafeEncoder() { var serializer = new DefaultLambdaJsonSerializer(x => x.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping); var response = new DummyResponse { BingBong = "Joy" }; MemoryStream ms = new MemoryStream(); StreamReader streamReader = new StreamReader(ms); serializer.Serialize(response, ms); ms.Seek(0, SeekOrigin.Begin); var utf8Payload = streamReader.ReadToEnd(); var albResponse = new Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerResponse { Body = utf8Payload }; serializer.Serialize(albResponse, ms); ms.Seek(0, SeekOrigin.Begin); var json = streamReader.ReadToEnd(); Assert.Equal(90, json.Length); }
public void TestPascalCase() { var serializer = new DefaultLambdaJsonSerializer(); var response = new DummyResponse { BingBong = "Joy" }; MemoryStream ms = new MemoryStream(); serializer.Serialize(response, ms); ms.Position = 0; var json = new StreamReader(ms).ReadToEnd(); var serialized = JObject.Parse(json); Assert.Equal("Joy", serialized["BingBong"]?.ToString()); }