public void WhenUpdatingTheElementsInTheSelectionsListInTheViewModel_ThenResponseIsSetInTheModelAndValidationIsUpdated()
        {
            var template = new MultipleSelectionQuestionTemplate { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            var questionAsINDEI = question as INotifyDataErrorInfo;
            var viewModel = new MultipleSelectionQuestionViewModel(question);

            viewModel.Selections.Add("a");

            CollectionAssert.AreEqual((ICollection)viewModel.Selections, question.Response.ToArray());
            Assert.IsFalse(questionAsINDEI.HasErrors);

            viewModel.Selections.Add("b");

            CollectionAssert.AreEqual((ICollection)viewModel.Selections, question.Response.ToArray());
            Assert.IsFalse(questionAsINDEI.HasErrors);

            viewModel.Selections.Add("c");

            CollectionAssert.AreEqual((ICollection)viewModel.Selections, question.Response.ToArray());
            Assert.IsTrue(questionAsINDEI.HasErrors);

            viewModel.Selections.Remove("a");

            CollectionAssert.AreEqual((ICollection)viewModel.Selections, question.Response.ToArray());
            Assert.IsFalse(questionAsINDEI.HasErrors);
        }
        public void WhenCreatingAViewModelForAQuestionWithNullResponse_ThenInitializesTheResponseToAnEmptyCollection()
        {
            var template = new MultipleSelectionQuestionTemplate { Range = new[] { "a", "b", "c" } };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            var viewModel = new MultipleSelectionQuestionViewModel(question);

            CollectionAssert.AreEqual(new string[0], question.Response.ToArray());
        }
        public void WhenQuestionIsCreated_ThenTemplateValuesAreCopied()
        {
            var theRange = new string[] { "aRangeValue", "anotherRangeValue" };
            var maxSelections = 1;
            var question = new MultipleSelectionQuestionTemplate() { Range = theRange, MaxSelections = maxSelections }.CreateNewQuestion() as MultipleSelectionQuestion;

            Assert.AreEqual(theRange, question.Range);
            Assert.AreEqual(maxSelections, question.MaxSelections);
        }
        public void WhenQuestionIsNew_ThenItIsNotComplete()
        {
            var template = new MultipleSelectionQuestionTemplate()
                               {
                                   Range = new[] { "one", "two", "three" },
                                   MaxSelections = 2
                               };
            var question = template.CreateNewQuestion();

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenQuestionHasInvalidValue_ThenItIsNotComplete()
        {
            var template = new MultipleSelectionQuestionTemplate()
                               {
                                   Range = new[] { "one", "two", "three" },
                                   MaxSelections = 2
                               };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            question.Response = new[] { "one", "two", "three" };

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenUpdatingTheCollectionInitializedByTheViewModel_ThenTheViewModelNotifiesChangesToTheResponse()
        {
            var template = new MultipleSelectionQuestionTemplate { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            var viewModel = new MultipleSelectionQuestionViewModel(question);
            int responseChanges = 0;
            viewModel.ResponseChanged += (s, e) => responseChanges++;

            viewModel.Selections.Add("a");

            Assert.AreEqual(1, responseChanges);

            viewModel.Selections.Add("b");

            Assert.AreEqual(2, responseChanges);

            viewModel.Selections.Add("c");

            Assert.AreEqual(3, responseChanges);

            viewModel.Selections.Remove("b");

            Assert.AreEqual(4, responseChanges);
        }
        public void WhenSettingASelectionOnTheViewModel_ThenHasChangesIsTrue()
        {
            var template = new MultipleSelectionQuestionTemplate { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            var viewModel = new MultipleSelectionQuestionViewModel(question);
            int responseChanges = 0;
            viewModel.ResponseChanged += (s, e) => responseChanges++;

            viewModel.Selections.Add("a");

            Assert.IsTrue(viewModel.HasChanges);
        }
        public void WhenCreatingTheViewModel_ThenHasChangesIsFalse()
        {
            var template = new MultipleSelectionQuestionTemplate { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;
            var viewModel = new MultipleSelectionQuestionViewModel(question);

            Assert.IsFalse(viewModel.HasChanges);
        }
        public void WhenResponseHasLessElementsThanMax_ThenIndicatesNoErrorOnResponse()
        {
            var template = new MultipleSelectionQuestionTemplate()
                               {
                                   Range = new[] { "one", "two", "three" },
                                   MaxSelections = 2
                               };
            var question = template.CreateNewQuestion() as MultipleSelectionQuestion;

            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = new[] { "one" };

            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<ValidationResult>().Any());
        }