public void WhenUpdatingTheElementsInTheSelectionsListInTheViewModel_ThenResponseIsSetInTheModelAndValidationIsUpdated()
        {
            var question = new MultipleSelectionQuestion { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            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 question = new MultipleSelectionQuestion { Range = new[] { "a", "b", "c" } };
            var viewModel = new MultipleSelectionQuestionViewModel(question);

            CollectionAssert.AreEqual(new string[0], question.Response.ToArray());
        }
        public void WhenQuestionIsNew_ThenItIsNotComplete()
        {
            var question =
                new MultipleSelectionQuestion()
                {
                    Range = new[] { "one", "two", "three" },
                    MaxSelections = 2
                };

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

            Assert.IsFalse(question.IsComplete);
        }
        public void WhenUpdatingTheCollectionInitializedByTheViewModel_ThenTheViewModelNotifiesChangesToTheResponse()
        {
            var question = new MultipleSelectionQuestion { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            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 question = new MultipleSelectionQuestion { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var viewModel = new MultipleSelectionQuestionViewModel(question);
            int responseChanges = 0;
            viewModel.ResponseChanged += (s, e) => responseChanges++;

            viewModel.Selections.Add("a");

            Assert.IsTrue(responseChanges > 0);
        }
        public void WhenCreatingTheViewModel_ThenHasChangesIsFalse()
        {
            var question = new MultipleSelectionQuestion { Range = new[] { "a", "b", "c" }, MaxSelections = 2 };
            var viewModel = new MultipleSelectionQuestionViewModel(question);

            bool hasChanges = false;
            viewModel.ResponseChanged += (o, e) => { hasChanges = true; };            
            Assert.IsFalse(hasChanges);
        }
        public void WhenResponseHasLessElementsThanMax_ThenIndicatesNoErrorOnResponse()
        {
            var question =
                new MultipleSelectionQuestion()
                {
                    Range = new[] { "one", "two", "three" },
                    MaxSelections = 2
                };

            var notifyErrorInfo = (INotifyDataErrorInfo)question;

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

            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
        }
        public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
        {
            var question =
                new MultipleSelectionQuestion()
                {
                    Range = new[] { "one", "two", "three" },
                    MaxSelections = 2
                };

            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = new[] { "one" };
            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());

            question.Response = null;
            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
        }