public void BroadcastMinAndMaxGuesses()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatserviceMock = new Mock <IChatService>();

            chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    IsBroadcaster = false,
                    IsModerator   = false,
                    DisplayName   = "User1",
                    Username      = "******"
                }
            };

            sut.Guess(chatserviceMock.Object, cmd);

            cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:59",
                },
                ChatUser = new ChatUser()
                {
                    IsBroadcaster = false,
                    IsModerator   = false,
                    DisplayName   = "User2",
                    Username      = "******"
                }
            };

            sut.Guess(chatserviceMock.Object, cmd);
            cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "close",
                },
                ChatUser = new ChatUser()
                {
                    IsBroadcaster = true,
                    IsModerator   = false,
                    DisplayName   = "User1",
                    Username      = "******"
                }
            };

            sut.Close(chatserviceMock.Object, cmd);

            //verify everything happened as needed
            chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(m => m == "No more guesses...  the race is about to start with 2 guesses from 00:01:23 to 00:01:59")), Times.Once);
            Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState());
        }
        public void NotBeAllowedForRegularChatters()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatserviceMock = new Mock <IChatService>();

            chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "close",
                },
                ChatUser = new ChatUser()
                {
                    IsBroadcaster = false,
                    IsModerator   = false,
                    DisplayName   = "User1",
                    Username      = "******"
                }
            };

            Assert.Throws <InvalidOperationException>(() => sut.Close(chatserviceMock.Object, cmd));

            //verify everything happened as needed
            chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(m => m == "Now taking guesses. Submit your guess with !guess 1:23 where 1 is minutes and 23 is seconds.")), Times.Never);
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
        }
        public void AllowCloseCommandFromModerator()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);

            sut.Close(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>(), ChatUser = new ChatUser()
                {
                    DisplayName = "a", Username = "******", IsModerator = true
                }
            });
            Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState());
        }
        public void NotAllowCloseCommandFromChatter()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);

            Assert.Throws <InvalidOperationException>(() => sut.Close(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>(), ChatUser = new ChatUser()
                {
                    DisplayName = "a", Username = "******"
                }
            }));
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
        }
        public void AnnounceAClosestWinner_GivenUserIsBroadcaster()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatService = new Mock <IChatService>();

            chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:24",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };

            sut.Guess(chatService.Object, cmd);
            sut.Close(chatService.Object, cmd);
            cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "reset",
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };
            sut.Reset(chatService.Object, cmd);
            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
            chatService.Verify(service => service.BroadcastMessageOnChannel(It.Is <string>(s => s == "No winners THIS time, but user1 was closest at just 1 seconds off!")), Times.Once());
        }
        public void AnnounceWinner_GivenUserIsBroadcaster()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatService = new Mock <IChatService>();

            chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };

            sut.Guess(chatService.Object, cmd);
            sut.Close(chatService.Object, cmd);
            cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "reset",
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };
            sut.Reset(chatService.Object, cmd);
            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
            chatService.Verify(service => service.BroadcastMessageOnChannel(It.Is <string>(s => s == "WINNER!!! - Congratulations user1 - you have won!")), Times.Once());
        }
        public void JustReset_GivenUserIsBroadcaster()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatService = new Mock <IChatService>();

            chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:24",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };

            sut.Guess(chatService.Object, cmd);
            sut.Close(chatService.Object, cmd);
            cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "reset",
                    "invalid",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            };
            sut.Reset(chatService.Object, cmd);
            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
            chatService.Verify(service => service.BroadcastMessageOnChannel(It.IsAny <string>()), Times.Once());
        }
예제 #8
0
        public void BroadcastTheUserGuess_WhenInClosedStateAndUserGuessed()
        {
            var sut = new GuessGame(GuessGameState.OpenTakingGuesses);
            Mock <IChatService> chatService = new Mock <IChatService>();

            chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>()));
            var cmd = new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName = "User1",
                    Username    = "******"
                }
            };

            sut.Guess(chatService.Object, cmd);
            sut.Close(chatService.Object, new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:23",
                },
                ChatUser = new ChatUser()
                {
                    DisplayName   = "User1",
                    Username      = "******",
                    IsBroadcaster = true
                }
            });
            sut.Mine(chatService.Object, cmd);
            chatService.Verify(service => service.BroadcastMessageOnChannel(It.Is <string>(s => s == "user1 guessed 00:01:23")), Times.Once());
        }
예제 #9
0
        public void GamePlay()
        {
            var sut = new GuessGame();

            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
            sut.Help(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "help"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = true, IsBroadcaster = false, DisplayName = "bravecobra", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
            sut.Open(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "open"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = true, IsBroadcaster = false, DisplayName = "bravecobra", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:23"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = true, IsBroadcaster = false, DisplayName = "bravecobra", Username = "******"
                }
            });
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "mine"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = true, IsBroadcaster = false, DisplayName = "bravecobra", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:22"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = true, DisplayName = "csharpfritz", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:61"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = false, DisplayName = "someone", Username = "******"
                }
            });
            sut.Mine(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "mine"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = false, DisplayName = "someone", Username = "******"
                }
            });
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:41"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = false, DisplayName = "someone", Username = "******"
                }
            });
            sut.Mine(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "mine"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = false, DisplayName = "someone", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Guess(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "1:25"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = false, DisplayName = "someone", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Close(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "close"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = true, DisplayName = "csharpfritz", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState());
            sut.Open(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "open"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = true, DisplayName = "csharpfritz", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState());
            sut.Close(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "close"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = true, DisplayName = "csharpfritz", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState());
            sut.Reset(new StubChat(_output), new GuessGameCommand()
            {
                ArgumentsAsList = new List <string>()
                {
                    "reset", "1:23"
                },
                ChatUser = new ChatUser()
                {
                    IsModerator = false, IsBroadcaster = true, DisplayName = "csharpfritz", Username = "******"
                }
            });
            Assert.Equal(GuessGameState.NotStarted, sut.CurrentState());
        }