public override string TryToExecute(CommandReceivedEventArgs eventArgs)
        {
            if (!eventArgs.ChatUser.IsInThisRoleOrHigher(UserRole.Mod))
            {
                return($"Sorry, {eventArgs.ChatUser.DisplayName}, only mods can add new words.");
            }

            var word = eventArgs?.Arguments?.ElementAtOrDefault(1)?.ToLowerInvariant();

            if (string.IsNullOrEmpty(word))
            {
                return(HelpText);
            }

            HangmanWord existingWord = _repository.Single(HangmanWordPolicy.ByWord(word));

            if (existingWord != null)
            {
                return($"The word \"{existingWord.Word}\" already exists in the hangman database.");
            }

            _repository.Create(new HangmanWord(word));

            return($"Added \"{word}\" to the hangman dictionary.");
        }
        public void HangmanWordIsWordGuessed_WhenNotGuessed_ShouldReturnFalse()
        {
            var word = "cookie";
            var hangmanWord = new HangmanWord(word);

            var actual = hangmanWord.IsWordGuessed();

            Assert.IsFalse(actual);
        }
        public void HangmanWordIsGuessedForTheFirstTime_WhenIsTheFirstTime_ShouldReturnTrue()
        {
            string word = "cookie";
            var letter = "o";
            var hangmanWord = new HangmanWord(word);

            var actual = hangmanWord.IsLetterGuessedForFirstTime(letter);

            Assert.IsTrue(actual);
        }
        public void HangmanWordIsWordGuessed_WhenGuessed_ShouldReturnFalse()
        {
            var word = "cookie";
            var hangmanWord = new HangmanWord(word);
            foreach (var ch in word)
            {
                hangmanWord.IsLetterInTheWord(ch.ToString());
            }

            var actual = hangmanWord.IsWordGuessed();

            Assert.IsTrue(actual);
        }
示例#5
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HangmanWord = await _context.HangmanWords.FirstOrDefaultAsync(m => m.Id == id);

            if (HangmanWord == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HangmanWord = await _context.HangmanWords.FindAsync(id);

            if (HangmanWord != null)
            {
                _context.HangmanWords.Remove(HangmanWord);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public void HangmanWordPrintTheWord_WhenNoLetterIsGuessed_ShouldPrintOnlyUnderscores()
        {
            var word = "cookie";
            var hangmanWord = new HangmanWord(word);
            var printer = new Mock<IPrinter>();

            var calledCount = 0;

            printer.Setup(pr => pr.Print("The secret word is: "))
                    .Callback(() => ++calledCount);

            var underscoredWord = new string('_', word.Length);
            underscoredWord = string.Join(" ", underscoredWord.ToCharArray());
            underscoredWord += " ";

            printer.Setup(pr => pr.Print(underscoredWord))
                .Callback(() => ++calledCount);

            printer.Setup(pr => pr.PrintLine())
                .Callback(() => ++calledCount);

            hangmanWord.PrintTheWord(printer.Object);

            Assert.AreEqual(3, calledCount);
        }
        public void HangmanWord_WhenWordIsValid_ShouldGenerateHiddenWordWithLenghtEqualToChosenWordLength()
        {
            string word = "cookie";
            var hangmanWord = new HangmanWord(word);

            Assert.AreEqual(hangmanWord.TheChosenWord.Length, hangmanWord.HiddenWord.Length);
        }
 public void HangmanWord_WhenNullWordIsProvided_ShouldThrow()
 {
     string word = null;
     var hangmanWord = new HangmanWord(word);
 }
 public void HangmanWord_ShouldChosenWordLenghtEqualToHiddenWordLength()
 {
     var word = "cookie";
     var hangmanWord = new HangmanWord(word);
     Assert.AreEqual(hangmanWord.TheChosenWord.Length, hangmanWord.HiddenWord.Length);
 }