PageRenderTime 44ms CodeModel.GetById 16ms 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. //===================================================================================
  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 OpenQuestionFixture
  25. {
  26. [TestMethod]
  27. public void WhenQuestionIsNew_ThenItIsNotComplete()
  28. {
  29. var question = new OpenQuestion { MaxLength = 10 };
  30. Assert.IsFalse(question.IsComplete);
  31. }
  32. [TestMethod]
  33. public void WhenQuestionIsNew_ThenTemplateValuesAreCopied()
  34. {
  35. var question = new OpenQuestion { MaxLength = 10 };
  36. Assert.AreEqual(10, question.MaxLength);
  37. }
  38. [TestMethod]
  39. public void WhenQuestionHasInvalidValue_ThenItIsNotComplete()
  40. {
  41. var question = new OpenQuestion { MaxLength = 10 };
  42. question.Response = "aaaaaaaaaaaaaaaaaaaaaaaaa";
  43. Assert.IsFalse(question.IsComplete);
  44. }
  45. [TestMethod]
  46. public void WhenQuestionHasEmptyValue_ThenItIsNotComplete()
  47. {
  48. var question = new OpenQuestion { MaxLength = 10 };
  49. question.Response = "";
  50. Assert.IsFalse(question.IsComplete);
  51. }
  52. [TestMethod]
  53. public void WhenQuestionHasValidValue_ThenItIsComplete()
  54. {
  55. var question = new OpenQuestion { MaxLength = 10 };
  56. question.Response = "aaaa";
  57. Assert.IsTrue(question.IsComplete);
  58. }
  59. [TestMethod]
  60. public void WhenResponseLengthExceedsMaxLength_ThenIndicatesErrorOnResponse()
  61. {
  62. var question = new OpenQuestion { MaxLength = 10 };
  63. var notifyErrorInfo = (INotifyDataErrorInfo)question;
  64. question.Response = "ThisIsLongerThanTenCharacters";
  65. Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  66. }
  67. [TestMethod]
  68. public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
  69. {
  70. var question = new OpenQuestion { MaxLength = 10 };
  71. var notifyErrorInfo = (INotifyDataErrorInfo)question;
  72. question.Response = "valid";
  73. Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  74. question.Response = null;
  75. Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast<string>().Any());
  76. }
  77. }
  78. }