public async Task MessageWithTextData() { var data = new MessagePublishedData { Message = new PubsubMessage { TextData = "PubSub user" } }; var cloudEvent = new CloudEvent( MessagePublishedData.MessagePublishedCloudEventType, new Uri("//pubsub.googleapis.com", UriKind.RelativeOrAbsolute), Guid.NewGuid().ToString(), DateTime.UtcNow); // Our function doesn't actually use the CloudEvent data, because that's provided separately. // If we wanted to make the CloudEvent look as realistic as possible, we could use // CloudEventConverters.PopulateCloudEvent. var logger = new MemoryLogger <HelloPubSub.Function>(); var function = new HelloPubSub.Function(logger); await function.HandleAsync(cloudEvent, data, CancellationToken.None); var logEntry = Assert.Single(logger.ListLogEntries()); Assert.Equal("Hello PubSub user", logEntry.Message); Assert.Equal(LogLevel.Information, logEntry.Level); }
public async Task MessageWithoutTextData() { var data = new MessagePublishedData { Message = new PubsubMessage { Attributes = { { "key", "value" } } } }; var cloudEvent = new CloudEvent { Type = MessagePublishedData.MessagePublishedCloudEventType, Source = new Uri("//pubsub.googleapis.com", UriKind.RelativeOrAbsolute), Id = Guid.NewGuid().ToString(), Time = DateTimeOffset.UtcNow }; var logger = new MemoryLogger <HelloPubSub.Function>(); var function = new HelloPubSub.Function(logger); await function.HandleAsync(cloudEvent, data, CancellationToken.None); var logEntry = Assert.Single(logger.ListLogEntries()); Assert.Equal("Hello world", logEntry.Message); Assert.Equal(LogLevel.Information, logEntry.Level); }
public async Task NoRetry(PubsubMessage message) { var data = new MessagePublishedData { Message = message }; await ExecuteCloudEventFunctionAsync(EventType, data); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal(LogLevel.Information, logEntry.Level); Assert.Equal("Not retrying...", logEntry.Message); }
public async Task RetryTrue() { var data = new MessagePublishedData { Message = new PubsubMessage { TextData = "{ \"retry\": true }" } }; // The test server propagates the exception to the caller. The real server would respond // with a status code of 500. await Assert.ThrowsAsync <InvalidOperationException>(() => ExecuteCloudEventFunctionAsync(EventType, data)); Assert.Empty(GetFunctionLogEntries()); }
public async Task MessageWithTextData() { var data = new MessagePublishedData { Message = new PubsubMessage { TextData = "PubSub user" } }; await ExecuteCloudEventRequestAsync(MessagePublishedData.MessagePublishedCloudEventType, data); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal("Hello PubSub user", logEntry.Message); Assert.Equal(LogLevel.Information, logEntry.Level); }
public async Task MessageWithoutTextData() { var data = new MessagePublishedData { Message = new PubsubMessage { Attributes = { { "key", "value" } } } }; await ExecuteCloudEventRequestAsync(MessagePublishedData.MessagePublishedCloudEventType, data); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal("Hello world", logEntry.Message); Assert.Equal(LogLevel.Information, logEntry.Level); }
public async Task NoRetry(PubsubMessage message) { var cloudEvent = new CloudEvent(MessagePublishedData.MessagePublishedCloudEventType, new Uri("//pubsub.googleapis.com")); var data = new MessagePublishedData { Message = message }; CloudEventConverters.PopulateCloudEvent(cloudEvent, data); await ExecuteCloudEventRequestAsync(cloudEvent); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal(LogLevel.Information, logEntry.Level); Assert.Equal("Not retrying...", logEntry.Message); }
public async Task RetryTrue() { var cloudEvent = new CloudEvent(MessagePublishedData.MessagePublishedCloudEventType, new Uri("//pubsub.googleapis.com")); var data = new MessagePublishedData { Message = new PubsubMessage { TextData = "{ \"retry\": true }" } }; CloudEventConverters.PopulateCloudEvent(cloudEvent, data); // The test server propagates the exception to the caller. The real server would respond // with a status code of 500. await Assert.ThrowsAsync <InvalidOperationException>(() => ExecuteCloudEventRequestAsync(cloudEvent)); Assert.Empty(GetFunctionLogEntries()); }
public async Task Processing(string textData, int ageInSeconds, string expectedLog) { var cloudEvent = new CloudEvent(MessagePublishedData.MessagePublishedCloudEventType, new Uri("//pubsub.googleapis.com"), "1234", DateTime.UtcNow.AddSeconds(-ageInSeconds)); var data = new MessagePublishedData { Message = new PubsubMessage { TextData = textData } }; CloudEventConverters.PopulateCloudEvent(cloudEvent, data); await ExecuteCloudEventRequestAsync(cloudEvent); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal(LogLevel.Information, logEntry.Level); Assert.Equal(expectedLog, logEntry.Message); }
public async Task MessageWithoutTextData() { var cloudEvent = new CloudEvent(MessagePublishedData.MessagePublishedCloudEventType, new Uri("//pubsub.googleapis.com")); var data = new MessagePublishedData { Message = new PubsubMessage { Attributes = { { "key", "value" } } } }; CloudEventConverters.PopulateCloudEvent(cloudEvent, data); await ExecuteCloudEventRequestAsync(cloudEvent); var logEntry = Assert.Single(GetFunctionLogEntries()); Assert.Equal("Hello world", logEntry.Message); Assert.Equal(LogLevel.Information, logEntry.Level); }