PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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. //===================================================================================
  17. using System.ComponentModel;
  18. using System.Linq;
  19. using MVVM.Model;
  20. using Microsoft.VisualStudio.TestTools.UnitTesting;
  21. namespace MVVM.Test.Model
  22. {
  23. [TestClass]
  24. public class MultipleSelectionQuestionFixture
  25. {
  26. [TestMethod]
  27. public void WhenQuestionIsNew_ThenItIsNotComplete()
  28. {
  29. var question =
  30. new MultipleSelectionQuestion()
  31. {
  32. Range = new[] { "one", "two", "three" },
  33. MaxSelections = 2
  34. };
  35. Assert.IsFalse(question.IsComplete);
  36. }
  37. [TestMethod]
  38. public void WhenQuestionHasInvalidValue_ThenItIsNotComplete()
  39. {
  40. var question =
  41. new MultipleSelectionQuestion()
  42. {
  43. Range = new[] { "one", "two", "three" },
  44. MaxSelections = 2
  45. };
  46. question.Response = new[] { "one", "two", "three" };
  47. Assert.IsFalse(question.IsComplete);
  48. }
  49. [TestMethod]
  50. public void WhenQuestionHasNullValue_ThenItIsNotComplete()
  51. {
  52. var question =
  53. new MultipleSelectionQuestion()
  54. {
  55. Range = new[] { "one", "two", "three" },
  56. MaxSelections = 2
  57. };
  58. question.Response = new[] { "one" };
  59. question.Response = null;
  60. Assert.IsFalse(question.IsComplete);
  61. }
  62. [TestMethod]
  63. public void WhenQuestionHasValidValue_ThenItIsComplete()
  64. {
  65. var question =
  66. new MultipleSelectionQuestion()
  67. {
  68. Range = new[] { "one", "two", "three" },
  69. MaxSelections = 2
  70. };
  71. question.Response = new[] { "one" };
  72. Assert.IsTrue(question.IsComplete);
  73. }
  74. [TestMethod]
  75. public void WhenResponseHasLessElementsThanMax_ThenIndicatesNoErrorOnResponse()
  76. {
  77. var question =
  78. new MultipleSelectionQuestion()
  79. {
  80. Range = new[] { "one", "two", "three" },
  81. MaxSelections = 2
  82. };
  83. var notifyErrorInfo = (INotifyDataErrorInfo)question;
  84. question.Response = new[] { "one" };
  85. Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  86. }
  87. [TestMethod]
  88. public void WhenResponseHasMoreElementsThanMax_ThenIndicatesErrorOnResponse()
  89. {
  90. var question =
  91. new MultipleSelectionQuestion()
  92. {
  93. Range = new[] { "one", "two", "three" },
  94. MaxSelections = 2
  95. };
  96. var notifyErrorInfo = (INotifyDataErrorInfo)question;
  97. question.Response = new[] { "one", "two", "three" };
  98. Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  99. }
  100. [TestMethod]
  101. public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
  102. {
  103. var question =
  104. new MultipleSelectionQuestion()
  105. {
  106. Range = new[] { "one", "two", "three" },
  107. MaxSelections = 2
  108. };
  109. var notifyErrorInfo = (INotifyDataErrorInfo)question;
  110. question.Response = new[] { "one" };
  111. Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  112. question.Response = null;
  113. Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  114. }
  115. }
  116. }