public async Task PublishSingleRawEventWithDetailedInfo_WithBuilder_ValidParameters_Succeeds() { // Arrange const string licensePlate = "1-TOM-337"; const string expectedSubject = "/"; var eventId = Guid.NewGuid().ToString(); var data = new CarEventData(licensePlate); var rawEventBody = JsonConvert.SerializeObject(data); var cloudEvent = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), subject: expectedSubject, id: eventId, DateTime.UtcNow) { Data = data, DataContentType = new ContentType("application/json") }; IEventGridPublisher publisher = EventPublisherFactory.CreateCloudEventPublisher(_config); // Act await publisher.PublishRawCloudEventAsync( cloudEvent.SpecVersion, cloudEvent.Id, cloudEvent.Type, cloudEvent.Source, rawEventBody, cloudEvent.Subject, cloudEvent.Time ?? default(DateTimeOffset)); TracePublishedEvent(eventId, cloudEvent); // Assert var receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId); ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, cloudEvent.Type, cloudEvent.Subject, licensePlate, receivedEvent); }
public async Task <IActionResult> Emit(string eventType, [FromBody, Required] object eventPayload, string eventId, string eventTimestamp, string eventSubject = "/", string dataVersion = "1.0") { eventId = string.IsNullOrWhiteSpace(eventId) ? Guid.NewGuid().ToString() : eventId; eventTimestamp = string.IsNullOrWhiteSpace(eventTimestamp) ? DateTimeOffset.UtcNow.ToString(format: "O") : eventTimestamp; if (DateTimeOffset.TryParse(eventTimestamp, out DateTimeOffset parsedEventTimeStamp) == false) { return(BadRequest($"Unable to parse specified event timestamp '{eventTimestamp}'")); } var source = new Uri($"{Request.Scheme}://{Request.Host}{Request.PathBase}"); await _eventGridPublisher.PublishRawCloudEventAsync( CloudEventsSpecVersion.V1_0, eventId, eventType, source, eventPayload.ToString(), eventSubject, parsedEventTimeStamp.DateTime); Response.Headers.Add(Headers.Response.Events.Id, eventId); Response.Headers.Add(Headers.Response.Events.Subject, eventSubject); Response.Headers.Add(Headers.Response.Events.Timestamp, eventTimestamp); Response.Headers.Add(Headers.Response.Events.DataVersion, dataVersion); return(NoContent()); }