public void WhenQuestionIsNew_ThenItIsNotComplete()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenQuestionIsCreated_ThenTemplateValuesAreCopied()
        {
            var question = new NumericQuestionTemplate()
            {
                MaxValue = 35
            }.CreateNewQuestion() as NumericQuestion;

            Assert.AreEqual(35, question.MaxValue);
        }
        public void WhenCreatingANewViewModel_ThenHasChangesIsFalse()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            // Assertions
            Assert.IsFalse(viewModel.HasChanges);
        }
        public void WhenQuestionHasValidValue_ThenItIsComplete()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;

            question.Response = 10;

            Assert.IsTrue(question.IsComplete);
        }
        public void WhenQuestionHasNullValue_ThenItIsNotComplete()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;

            question.Response = 10;
            question.Response = null;

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenQuestionHasNegativeValue_ThenItIsNotComplete()
        {
            var question = new NumericQuestionTemplate()
            {
                MaxValue = 15
            }.CreateNewQuestion() as NumericQuestion;

            question.Response = -1;

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenResponseIsPositiveWithNoMaximum_ThenIndicatesNoErrorOnResponse()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;
            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = 15;

            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast <ValidationResult>().Any());
        }
        public void WhenResponseIsNegative_ThenIndicatesErrorOnResponse()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;
            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = -15;

            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast <ValidationResult>().Any());
        }
        public void WhenResponseIsSetOnTheModel_ThenHasChangesIsTrue()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            question.Response = 15;

            // Assertions
            Assert.IsTrue(viewModel.HasChanges);
        }
        public void WhenViewModelHasErrorIsSet_ThenDoesNotHaveCompletedResponse()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            question.Response         = 15;
            viewModel.HasBindingError = true;

            // Assertions
            Assert.IsFalse(viewModel.ResponseComplete);
        }
Exemple #11
0
        public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
        {
            var question = new NumericQuestionTemplate()
            {
            }.CreateNewQuestion() as NumericQuestion;
            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = 10;
            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast <ValidationResult>().Any());

            question.Response = null;
            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast <ValidationResult>().Any());
        }
        public void WhenResponseChangesOnTheModel_ThenResponseValueChangeIsFired()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            bool responseChangeFired = false;

            viewModel.ResponseChanged += (s, e) => { responseChangeFired = true; };
            question.Response          = 15;

            // Assertions
            Assert.IsTrue(responseChangeFired);
        }
        public void WhenHasErrorIsChangedToFalseOnTheViewModel_ThenResponseValueChangeIsFired()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            viewModel.HasBindingError = true;
            bool responseChangeFired = false;

            viewModel.ResponseChanged += (s, e) => { responseChangeFired = true; };
            viewModel.HasBindingError  = false;

            // Assertions
            Assert.IsTrue(responseChangeFired);
        }
        public void WhenResponseIsSetOnTheModel_ThenTheHasErrorPropertyInTheViewModelIsCleared()
        {
            var question = new NumericQuestionTemplate {
                MaxValue = 100
            }.CreateNewQuestion() as NumericQuestion;
            var viewModel = new NumericQuestionViewModel(question);

            viewModel.HasBindingError = true;
            int responseChanges = 0;

            viewModel.ResponseChanged += (s, e) => { responseChanges++; };
            question.Response          = 15;

            // Assertions
            Assert.IsFalse(viewModel.HasBindingError);
            Assert.AreEqual(1, responseChanges);
        }