PageRenderTime 38ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/Quickstarts/MVVM/MVVM.Test/Model/MultipleSelectionQuestionFixture.cs

#
C# | 138 lines | 100 code | 22 blank | 16 comment | 0 complexity | 1c19e3ab539e5a45a79b08242b0f1bd9 MD5 | raw file
  1//===================================================================================
  2// Microsoft patterns & practices
  3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4//===================================================================================
  5// Copyright (c) Microsoft Corporation.  All rights reserved.
  6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9// FITNESS FOR A PARTICULAR PURPOSE.
 10//===================================================================================
 11// The example companies, organizations, products, domain names,
 12// e-mail addresses, logos, people, places, and events depicted
 13// herein are fictitious.  No association with any real company,
 14// organization, product, domain name, email address, logo, person,
 15// places, or events is intended or should be inferred.
 16//===================================================================================
 17using System.ComponentModel;
 18using System.Linq;
 19using MVVM.Model;
 20using Microsoft.VisualStudio.TestTools.UnitTesting;
 21
 22namespace MVVM.Test.Model
 23{
 24    [TestClass]
 25    public class MultipleSelectionQuestionFixture
 26    {
 27        [TestMethod]
 28        public void WhenQuestionIsNew_ThenItIsNotComplete()
 29        {
 30            var question =
 31                new MultipleSelectionQuestion()
 32                {
 33                    Range = new[] { "one", "two", "three" },
 34                    MaxSelections = 2
 35                };
 36
 37            Assert.IsFalse(question.IsComplete);
 38        }
 39
 40        [TestMethod]
 41        public void WhenQuestionHasInvalidValue_ThenItIsNotComplete()
 42        {
 43            var question =
 44                new MultipleSelectionQuestion()
 45                {
 46                    Range = new[] { "one", "two", "three" },
 47                    MaxSelections = 2
 48                };
 49            question.Response = new[] { "one", "two", "three" };
 50
 51            Assert.IsFalse(question.IsComplete);
 52        }
 53
 54        [TestMethod]
 55        public void WhenQuestionHasNullValue_ThenItIsNotComplete()
 56        {
 57            var question =
 58                new MultipleSelectionQuestion()
 59                {
 60                    Range = new[] { "one", "two", "three" },
 61                    MaxSelections = 2
 62                };
 63
 64            question.Response = new[] { "one" };
 65            question.Response = null;
 66
 67            Assert.IsFalse(question.IsComplete);
 68        }
 69
 70        [TestMethod]
 71        public void WhenQuestionHasValidValue_ThenItIsComplete()
 72        {
 73            var question =
 74                new MultipleSelectionQuestion()
 75                {
 76                    Range = new[] { "one", "two", "three" },
 77                    MaxSelections = 2
 78                };
 79
 80            question.Response = new[] { "one" };
 81
 82            Assert.IsTrue(question.IsComplete);
 83        }
 84
 85        [TestMethod]
 86        public void WhenResponseHasLessElementsThanMax_ThenIndicatesNoErrorOnResponse()
 87        {
 88            var question =
 89                new MultipleSelectionQuestion()
 90                {
 91                    Range = new[] { "one", "two", "three" },
 92                    MaxSelections = 2
 93                };
 94
 95            var notifyErrorInfo = (INotifyDataErrorInfo)question;
 96
 97            question.Response = new[] { "one" };
 98
 99            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
100        }
101
102        [TestMethod]
103        public void WhenResponseHasMoreElementsThanMax_ThenIndicatesErrorOnResponse()
104        {
105            var question =
106                new MultipleSelectionQuestion()
107                {
108                    Range = new[] { "one", "two", "three" },
109                    MaxSelections = 2
110                };
111
112            var notifyErrorInfo = (INotifyDataErrorInfo)question;
113
114            question.Response = new[] { "one", "two", "three" };
115
116            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
117        }
118
119        [TestMethod]
120        public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
121        {
122            var question =
123                new MultipleSelectionQuestion()
124                {
125                    Range = new[] { "one", "two", "three" },
126                    MaxSelections = 2
127                };
128
129            var notifyErrorInfo = (INotifyDataErrorInfo)question;
130
131            question.Response = new[] { "one" };
132            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
133
134            question.Response = null;
135            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
136        }
137    }
138}