public async Task DeleveredEventTest() { var json = @" [ { 'email': '*****@*****.**', 'timestamp': 1513299569, 'smtp-id': '<14c5d75ce93.dfd.64b469@ismtpd-555>', 'event': 'delivered', 'category': 'cat facts', 'sg_event_id': 'sg_event_id', 'sg_message_id': 'sg_message_id', 'response': '200 OK' } ] "; IEnumerable <Event> events = await EventParser.ParseAsync(json); events.Count().ShouldBe(1); var defferedEvent = (DeliveredEvent)events.Single(); defferedEvent.Email.ShouldBe("*****@*****.**"); defferedEvent.Timestamp.ShouldBe(DateTime.UnixEpoch.AddSeconds(1513299569)); defferedEvent.SmtpId.ShouldBe("<14c5d75ce93.dfd.64b469@ismtpd-555>"); defferedEvent.EventType.ShouldBe(EventType.Delivered); defferedEvent.Category.Value[0].ShouldBe("cat facts"); defferedEvent.SendGridEventId.ShouldBe("sg_event_id"); defferedEvent.SendGridMessageId.ShouldBe("sg_message_id"); defferedEvent.Response.ShouldBe("200 OK"); }
public async Task UnsubscribeEventTest() { var json = @" [ { 'email': '*****@*****.**', 'timestamp': 1513299569, 'smtp-id': '<14c5d75ce93.dfd.64b469@ismtpd-555>', 'event': 'unsubscribe', 'category': 'cat facts', 'sg_event_id': 'sg_event_id', 'sg_message_id': 'sg_message_id' } ] "; IEnumerable <Event> events = await EventParser.ParseAsync(json); events.Count().ShouldBe(1); var spamReportEvent = (UnsubscribeEvent)events.Single(); spamReportEvent.Email.ShouldBe("*****@*****.**"); spamReportEvent.Timestamp.ShouldBe(DateTime.UnixEpoch.AddSeconds(1513299569)); spamReportEvent.SmtpId.ShouldBe("<14c5d75ce93.dfd.64b469@ismtpd-555>"); spamReportEvent.EventType.ShouldBe(EventType.Unsubscribe); spamReportEvent.Category.Value[0].ShouldBe("cat facts"); spamReportEvent.SendGridEventId.ShouldBe("sg_event_id"); spamReportEvent.SendGridMessageId.ShouldBe("sg_message_id"); }
public async Task DroppedEventTest() { var json = @" [ { 'email': '*****@*****.**', 'timestamp': 1513299569, 'smtp-id': '<14c5d75ce93.dfd.64b469@ismtpd-555>', 'event': 'dropped', 'category': 'cat facts', 'sg_event_id': 'sg_event_id', 'sg_message_id': 'sg_message_id', 'reason': 'Bounced Address', 'status': '5.0.0' } ] "; IEnumerable <Event> events = await EventParser.ParseAsync(json); events.Count().ShouldBe(1); var droppedEvent = (DroppedEvent)events.Single(); droppedEvent.Email.ShouldBe("*****@*****.**"); droppedEvent.Timestamp.ShouldBe(DateTime.UnixEpoch.AddSeconds(1513299569)); droppedEvent.SmtpId.ShouldBe("<14c5d75ce93.dfd.64b469@ismtpd-555>"); droppedEvent.EventType.ShouldBe(EventType.Dropped); droppedEvent.Category.Value[0].ShouldBe("cat facts"); droppedEvent.SendGridEventId.ShouldBe("sg_event_id"); droppedEvent.SendGridMessageId.ShouldBe("sg_message_id"); droppedEvent.Reason.ShouldBe("Bounced Address"); droppedEvent.Status.ShouldBe("5.0.0"); }
public async Task ClickEventTest() { var json = @" [ { 'email': '*****@*****.**', 'timestamp': 1513299569, 'smtp-id': '<14c5d75ce93.dfd.64b469@ismtpd-555>', 'event': 'click', 'category': 'cat facts', 'sg_event_id': 'sg_event_id', 'sg_message_id': 'sg_message_id', 'useragent': 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', 'ip': '255.255.255.255', 'url': 'http://www.sendgrid.com/' } ] "; IEnumerable <Event> events = await EventParser.ParseAsync(json); events.Count().ShouldBe(1); var clickEvent = (ClickEvent)events.Single(); clickEvent.Email.ShouldBe("*****@*****.**"); clickEvent.Timestamp.ShouldBe(DateTime.UnixEpoch.AddSeconds(1513299569)); clickEvent.SmtpId.ShouldBe("<14c5d75ce93.dfd.64b469@ismtpd-555>"); clickEvent.EventType.ShouldBe(EventType.Click); clickEvent.Category.Value[0].ShouldBe("cat facts"); clickEvent.SendGridEventId.ShouldBe("sg_event_id"); clickEvent.SendGridMessageId.ShouldBe("sg_message_id"); clickEvent.UserAgent.ShouldBe("Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); clickEvent.IP.ShouldBe("255.255.255.255"); clickEvent.Url.ToString().ShouldBe("http://www.sendgrid.com/"); }
public async Task AllEvents() { var jsonStream = new MemoryStream(File.ReadAllBytes("TestData/events.json")); IEnumerable <Event> events = await EventParser.ParseAsync(jsonStream); events.Count().ShouldBe(11); }
public async Task <IActionResult> Events() { IEnumerable <Event> events = await EventParser.ParseAsync(Request.Body); return(Ok()); }