in src/Google.Cloud.Functions.Testing/FunctionTestBase.cs [109:128]
public async Task ExecuteCloudEventRequestAsync(CloudEvent cloudEvent, CloudEventFormatter? formatter = null)
{
var dataFormatter = cloudEvent.Data is null ? null : CloudEventFormatterAttribute.CreateFormatter(cloudEvent.Data.GetType());
formatter = formatter ?? dataFormatter ?? s_defaultEventFormatter;
var bytes = formatter.EncodeStructuredModeMessage(cloudEvent, out var contentType);
contentType ??= s_applicationJsonContentType;
var mediaContentType = new MediaTypeHeaderValue(contentType.MediaType) { CharSet = contentType.CharSet };
var request = new HttpRequestMessage
{
// Any URI
RequestUri = new Uri("uri", UriKind.Relative),
// CloudEvent headers
Content = new ReadOnlyMemoryContent(bytes) { Headers = { ContentType = mediaContentType } },
Method = HttpMethod.Post
};
using var client = Server.CreateClient();
using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
}