Пример #1
0
        public void When_all_correct_values_for_all_cells_are_added_should_return_true_if_IsWordAnswerCorrect_is_called()
        {
            var wordViewModel = new WordViewModel();
            wordViewModel.Cells = new ObservableCollection<CellEmptyViewModel>();
            const string word = "testword";
            int row = 0;
            foreach (object character in word)
            {
                var cell = new CellViewModel(0, row, character.ToString(), wordViewModel, string.Empty);
                row += 1;
                wordViewModel.Cells.Add(cell);
            }

            foreach (CellEmptyViewModel cell in wordViewModel.Cells)
            {
                var keyReceivedMessage = new KeyReceivedMessage {KeyChar = cell.Value};
                var cellValueChangedMesage = new CellValueChangedMessage()
                        {
                            Character = keyReceivedMessage.KeyChar,
                            Col = cell.Col,
                            Row = cell.Row
                        };

                Messenger.Default.Send(cellValueChangedMesage);
            }

            Assert.IsTrue(wordViewModel.IsWordAnswerCorrect);
        }
 private void HandleKeyEvent(KeyReceivedMessage keyReceivedMessage)
 {
     if(SelectedWord == null) return;
     switch (keyReceivedMessage.KeyCharType)
     {
         case KeyCharType.Delete:
         case KeyCharType.BackSpace:
             if (_currentWordPosition > 0)
             {
                 _currentWordPosition -= 1;
                 SelectedWord.Cells[_currentWordPosition].EnteredValue = string.Empty;
             }
             break;
         default:
             if (_currentWordPosition < SelectedWord.Cells.Count)
             {
                 SelectedWord.Cells[_currentWordPosition].EnteredValue = keyReceivedMessage.KeyChar;
                 var cellValueChangedMesage =
                     new CellValueChangedMessage()
                         {
                             Character = keyReceivedMessage.KeyChar,
                             Col = SelectedWord.Cells[_currentWordPosition].Col,
                             Row = SelectedWord.Cells[_currentWordPosition].Row
                         };
                 Messenger.Default.Send(cellValueChangedMesage);
                 _currentWordPosition += 1;
             }
             break;
     }
     ShowCompleteTick = SetShowCompleteTick();
 }