PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 92 lines | 62 code | 14 blank | 16 comment | 0 complexity | 54fed432e08d17f095425e04f0d928da 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 OpenQuestionFixture
26    {
27        [TestMethod]
28        public void WhenQuestionIsNew_ThenItIsNotComplete()
29        {
30            var question = new OpenQuestion { MaxLength = 10 };
31            Assert.IsFalse(question.IsComplete);
32        }
33
34        [TestMethod]
35        public void WhenQuestionIsNew_ThenTemplateValuesAreCopied()
36        {
37            var question = new OpenQuestion { MaxLength = 10 };
38            Assert.AreEqual(10, question.MaxLength);
39        }
40
41        [TestMethod]
42        public void WhenQuestionHasInvalidValue_ThenItIsNotComplete()
43        {
44            var question = new OpenQuestion { MaxLength = 10 };
45            question.Response = "aaaaaaaaaaaaaaaaaaaaaaaaa";
46
47            Assert.IsFalse(question.IsComplete);
48        }
49
50        [TestMethod]
51        public void WhenQuestionHasEmptyValue_ThenItIsNotComplete()
52        {
53            var question = new OpenQuestion { MaxLength = 10 };
54            question.Response = "";
55
56            Assert.IsFalse(question.IsComplete);
57        }
58
59        [TestMethod]
60        public void WhenQuestionHasValidValue_ThenItIsComplete()
61        {
62            var question = new OpenQuestion { MaxLength = 10 };
63            question.Response = "aaaa";
64
65            Assert.IsTrue(question.IsComplete);
66        }
67
68        [TestMethod]
69        public void WhenResponseLengthExceedsMaxLength_ThenIndicatesErrorOnResponse()
70        {
71            var question = new OpenQuestion { MaxLength = 10 };
72            var notifyErrorInfo = (INotifyDataErrorInfo)question;
73
74            question.Response = "ThisIsLongerThanTenCharacters";
75
76            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
77        }
78
79        [TestMethod]
80        public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
81        {
82            var question = new OpenQuestion { MaxLength = 10 };
83            var notifyErrorInfo = (INotifyDataErrorInfo)question;
84
85            question.Response = "valid";
86            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
87
88            question.Response = null;
89            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
90        }
91    }
92}