private void CompareNotes( IMeetingMessage msg, IReadOnlyMeetingNote note, string userName = user1, DateTime?time = null, MeetingAction?expectedMeetingAction = null ) { Assert.AreEqual(expectedMeetingAction ?? msg.MeetingAction, note.MeetingAction); Assert.AreEqual(userName, note.UserName); Assert.AreEqual(time ?? this.testTime, note.TimeStamp); // Unknown should be just the args, everything else is prefix then args. if (msg.MeetingAction == MeetingAction.Unknown) { Assert.AreEqual(msg.CommandArgs, note.Message); } else { Assert.AreEqual($"{msg.CommandPrefix} {msg.CommandArgs}", note.Message); } }
public void ChairUnchair1PersonTest() { // Chair 1 user. { const string prefix = "#chair"; const string args = user1; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure chair can not unchair owner. { const string prefix = "#unchair"; const string args = owner; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user1, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.CanNotDoThisToOwner, result); Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user1); // Chair list should not be modified. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure nonchair can not unchair chair { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user2, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.ChairOnlyCommand, result); Assert.AreEqual(3, uut.MeetingNotes.Count); // Invalid permission, meeting message becomes standard message so it // doesn't show up in the log as something special. IReadOnlyMeetingNote note = uut.MeetingNotes.Last(); Assert.AreEqual(MeetingAction.Unknown, note.MeetingAction); Assert.AreEqual($"{msg.CommandPrefix} {msg.CommandArgs}", note.Message); Assert.AreEqual(user2, note.UserName); // Chair list should not be modified. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure owner can unchair chair. { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(4, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // User should no longer be a chair. Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } }