public void ProcessCommand_PollOpen_PollClosed() { //Arrange BotCommand command = new BotCommandBuilder().WithUser(_ADMINUSER).WithMessage("!poll !option 1 !option 2 !option 3").Build(); BotCommand command2 = new BotCommandBuilder().WithUser(_ADMINUSER).WithMessage("!poll").Build(); var poll = new Mock <IPoll>(); poll.Setup(x => x.EndPoll()).Returns("End Poll"); var pollFacotry = new Mock <IPollFactory>(); pollFacotry.Setup(x => x.CreatePoll(new string[] { "option 1", "option 2", "option 3" })).Returns(poll.Object); var pollCommandHandler = new PollCommandHandler(pollFacotry.Object); //Act CommandHandlerResult result = pollCommandHandler.ProcessCommand(command, _channel).Result; result = pollCommandHandler.ProcessCommand(command2, _channel).Result; //Assert Assert.AreEqual(ResultType.HandledWithMessage, result.ResultType); Assert.AreEqual($"End Poll", result.Message); Assert.AreEqual("#channel", result.Channel); }
public void ProcessCommand_UserCastsVote_VoteIsCast() { //Arrange BotCommand command = new BotCommandBuilder().WithUser(_ADMINUSER).WithMessage("!poll !option 1 !option 2 !option 3").Build(); BotCommand command2 = new BotCommandBuilder().WithUser("user").WithMessage("!vote 2").Build(); var poll = new Mock <IPoll>(); poll.Setup(x => x.CastVote("user", 2)).Returns(1); var pollFacotry = new Mock <IPollFactory>(); pollFacotry.Setup(x => x.CreatePoll(new string[] { "option 1", "option 2", "option 3" })).Returns(poll.Object); var pollCommandHandler = new PollCommandHandler(pollFacotry.Object); //Act CommandHandlerResult result = pollCommandHandler.ProcessCommand(command, _channel).Result; result = pollCommandHandler.ProcessCommand(command2, _channel).Result; //Assert poll.Verify(x => x.CastVote("user", 2), Times.Once()); Assert.AreEqual(ResultType.Handled, result.ResultType); Assert.AreEqual(null, result.Message); Assert.AreEqual(null, result.Channel); }
public void ProcessCommand_8_NoQuestionAsked() { //Arrange var command = new BotCommandBuilder().WithMessage("!8 ").Build(); //Act CommandHandlerResult result = _commandHandler.ProcessCommand(command, _channel).Result; //Assert Assert.IsNotNull(result.Message); Assert.AreEqual(ResultType.HandledWithMessage, result.ResultType); }
public void ProcessCommand_Roll_ValidInputNegativeModifier() { //Arrange var command = new BotCommandBuilder().WithMessage("!roll 2d6-2").Build(); //Act CommandHandlerResult result = _commandHandler.ProcessCommand(command, _channel).Result; //Assert Assert.GreaterOrEqual(Int32.Parse(result.Message), 0); Assert.LessOrEqual(Int32.Parse(result.Message), 10); }
public void ProcessCommand_Roll_ValidInputNoModifier() { //Arrange var command = new BotCommandBuilder().WithMessage("!roll 1d4").Build(); //Act CommandHandlerResult result = _commandHandler.ProcessCommand(command, _channel).Result; //Assert Assert.AreEqual(ResultType.HandledWithMessage, result.ResultType); Assert.GreaterOrEqual(Int32.Parse(result.Message), 1); Assert.LessOrEqual(Int32.Parse(result.Message), 4); }
public void ProcessCommand_UnauthorizedUserCreatesPoll_ResultTypeIsHandled() { //Arrange BotCommand command = new BotCommandBuilder().WithUser("bob").WithMessage("!poll !option 1 !option 2 !option 3").Build(); var poll = new Mock <IPoll>(); var pollFacotry = new Mock <IPollFactory>(); var pollCommandHandler = new PollCommandHandler(pollFacotry.Object); //Act CommandHandlerResult result = pollCommandHandler.ProcessCommand(command, _channel).Result; //Assert Assert.AreEqual(ResultType.Handled, result.ResultType); Assert.AreEqual(null, result.Message); Assert.AreEqual(null, result.Channel); }
public void ProcessCommand_NoOpenPoll_NewPollCreated() { //Arrange var command = new BotCommandBuilder().WithUser(_ADMINUSER).WithMessage("!poll !option 1 !option 2 !option 3").Build(); var poll = new Mock <IPoll>(); poll.Setup(x => x.PrintPoll()).Returns("Print Poll"); var pollFacotry = new Mock <IPollFactory>(); pollFacotry.Setup(x => x.CreatePoll(new string[] { "option 1", "option 2", "option 3" })).Returns(poll.Object); var pollCommandHandler = new PollCommandHandler(pollFacotry.Object); //Act CommandHandlerResult result = pollCommandHandler.ProcessCommand(command, _channel).Result; //Assert Assert.AreEqual(ResultType.HandledWithMessage, result.ResultType); Assert.AreEqual($"Poll started! use !vote <number> to case your vote. Print Poll", result.Message); Assert.AreEqual("#channel", result.Channel); }