public void InvalidSentenceTest()
        {
            const string SampleSentence = "Dummy.";
            const string SampleErrorMessage = "Dummy error message";

            _wordsCounterMock.Setup(vm => vm.Count(It.IsAny<string>()))
                .Callback(() => { throw new InvalidSentenceException(SampleErrorMessage); });

            var viewModel = new WordsCounterViewModel();
            viewModel.CheckSentence.Execute(SampleSentence);

            Assert.AreEqual(viewModel.ValidationMessage, SampleErrorMessage, "Proper error message should be set.");
            Assert.IsNull(viewModel.Result, "Result should be null.");
        }
        public void CanExecuteCheckSentenceCommandTest()
        {
            const string NullSentence = null;
            const string EmptySentence = "";
            const string WhiteSentence = " \t \n ";

            var viewModel = new WordsCounterViewModel();

            Assert.IsFalse(viewModel.CheckSentence.CanExecute(NullSentence),
                "Command should not be available for null input string.");
            Assert.IsFalse(viewModel.CheckSentence.CanExecute(EmptySentence),
                "Command should not be available for empty input string.");
            Assert.IsFalse(viewModel.CheckSentence.CanExecute(WhiteSentence),
                "Command should not be available for whitespace input string.");
        }
        public void CheckClearResultTest()
        {
            const string SampleSentence1 = "Dummy1.";
            const string SampleSentence2 = "Dummy2.";

            var viewModel = new WordsCounterViewModel();

            _wordsCounterMock.SetupGet(vm => vm.Result).Returns(new Dictionary<string, int>());

            viewModel.Sentence = SampleSentence1;
            viewModel.CheckSentence.Execute(SampleSentence1);
            Assert.IsNotNull(viewModel.Result, "Result should not be null.");

            viewModel.Sentence = SampleSentence2;
            Assert.IsNull(viewModel.Result, "Result should be null.");
        }
        public void MixedValidationScenarioTest()
        {
            const string InvalidSentence = "A. B.";
            const string SampleSentence = "Dummy.";
            const string SampleErrorMessage = "Dummy error message";

            var viewModel = new WordsCounterViewModel();

            // ------ Invalid sentence scenario ------
            _wordsCounterMock.Setup(vm => vm.Count(It.IsIn(InvalidSentence)))
                .Callback(() => { throw new InvalidSentenceException(SampleErrorMessage); });
            _wordsCounterMock.Setup(vm => vm.Count(It.IsIn(SampleSentence)))
                .Callback(() => { });

            viewModel.CheckSentence.Execute(InvalidSentence);

            Assert.AreEqual(viewModel.ValidationMessage, SampleErrorMessage, "Proper error message should be set.");
            Assert.IsNull(viewModel.Result, "Result should be null.");

            // ------ Valid sentence scenario -------
            var result = new Dictionary<string, int>();
            _wordsCounterMock.SetupGet(vm => vm.Result).Returns(result);

            viewModel.CheckSentence.Execute(SampleSentence);

            Assert.AreEqual(viewModel.ValidationMessage, null, "Validation message should be null.");
            Assert.AreEqual(viewModel.Result, result, "Result object should be equal to this provided by words counter.");
        }
        public void ValidSentenceTest()
        {
            const string SampleSentence = "Dummy.";

            var result = new Dictionary<string, int>();
            _wordsCounterMock.SetupGet(vm => vm.Result).Returns(result);

            var viewModel = new WordsCounterViewModel();
            viewModel.CheckSentence.Execute(SampleSentence);

            Assert.AreEqual(viewModel.ValidationMessage, null, "Validation message should be null.");
            Assert.AreEqual(viewModel.Result, result, "Result object should be equal to this provided by words counter.");
        }
        public void TriggerCheckSentenceExecutionTest()
        {
            const string SampleSentence = "Dummy.";

            var viewModel = new WordsCounterViewModel();

            int counter = 0;

            _wordsCounterMock.Setup(vm => vm.Count(It.IsAny<string>()))
                .Callback(() => { counter++; });
            _wordsCounterMock.SetupGet(vm => vm.Result).Returns(new Dictionary<string, int>());

            viewModel.SelectedAlgorithm = WordCounterAlgorithm.Dict;
            viewModel.Sentence = SampleSentence;
            viewModel.CheckSentence.Execute(SampleSentence);
            Assert.AreEqual(counter, 1, string.Format("Method should be executed {0} number of times", counter));

            // Check method should be executed automatically
            viewModel.SelectedAlgorithm = WordCounterAlgorithm.Linq;
            Assert.AreEqual(counter, 2, string.Format("Method should be executed {0} number of times", counter));

            // Check method should not be executed automatically (since before algorithm change there was no result calculated)
            viewModel.Sentence = null;
            viewModel.SelectedAlgorithm = WordCounterAlgorithm.Dict;
            Assert.AreEqual(counter, 2, string.Format("Method should be executed {0} number of times", counter));
        }