public void givenAnEmptyIncomingMessageItCreatesNoPunishments() { IncomingMessage message = new IncomingMessage(); List <Punishment> punishments = new WebHookParser(message).Exec(); Assert.That(punishments, Is.Empty); }
public void itIgnoresNonMentionEntities() { IncomingMessage message = new IncomingMessage(); message.Entities.Add(new Entity("biz", null, null)); List <Punishment> punishments = new WebHookParser(message).Exec(); Assert.That(punishments, Is.Empty); }
public Reply Insert([FromBody] IncomingMessage message) { List <Punishment> toSave = new WebHookParser(message).Exec(); toSave.ForEach(punishment => { db.Punishments.Add(punishment); }); db.IncomingMessages.Add(message); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); return(new Reply("Saved!")); }
public void givenAnIncomingMessageWithAMentionItCreatesASinglePunishments() { IncomingMessage message = new IncomingMessage(); TeamMember mentioned = new TeamMember("Foo"); TeamMember author = new TeamMember("Bar"); message.From = author; message.Entities.Add(new Entity("mention", mentioned, "<at>Foo</at>")); List <Punishment> punishments = new WebHookParser(message).Exec(); Assert.That(punishments.Count, Is.EqualTo(1)); Assert.That(punishments[0].Recipient, Is.EqualTo(mentioned)); Assert.That(punishments[0].Author, Is.EqualTo(author)); }
public void givenAnIncomingMessageWithMultipleMentionsItCreatesAMultiplePunishmentsThatSteamFromTheSameMessage() { IncomingMessage message = new IncomingMessage(); TeamMember mentioned1 = new TeamMember("Foo1"); TeamMember mentioned2 = new TeamMember("Foo2"); TeamMember author = new TeamMember("Bar"); message.From = author; message.Entities.Add(new Entity("mention", mentioned1, "<at>Foo</at>")); message.Entities.Add(new Entity("mention", mentioned2, "<at>Foo</at>")); List <Punishment> punishments = new WebHookParser(message).Exec(); Assert.That(punishments.Count, Is.EqualTo(2)); Assert.That(punishments[0].Recipient, Is.EqualTo(mentioned1)); Assert.That(punishments[0].Author, Is.EqualTo(author)); Assert.That(punishments[1].Recipient, Is.EqualTo(mentioned2)); Assert.That(punishments[1].Author, Is.EqualTo(author)); Assert.That(punishments[0].From, Is.EqualTo(punishments[1].From)); }