PageRenderTime 105ms CodeModel.GetById 28ms RepoModel.GetById 7ms app.codeStats 0ms

/Src/Condor.UnitTests/UnitTest1.cs

http://github.com/kahanu/CondorXE
C# | 208 lines | 119 code | 30 blank | 59 comment | 10 complexity | c9f294de90ac98f9645fb763887d6ac9 MD5 | raw file
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace Condor.UnitTests
  7. {
  8. /// <summary>
  9. /// Summary description for UnitTest1
  10. /// </summary>
  11. [TestClass]
  12. public class UnitTest1
  13. {
  14. public UnitTest1()
  15. {
  16. //
  17. // TODO: Add constructor logic here
  18. //
  19. }
  20. //private TestContext testContextInstance;
  21. ///// <summary>
  22. /////Gets or sets the test context which provides
  23. /////information about and functionality for the current test run.
  24. /////</summary>
  25. //public TestContext TestContext
  26. //{
  27. // get
  28. // {
  29. // return testContextInstance;
  30. // }
  31. // set
  32. // {
  33. // testContextInstance = value;
  34. // }
  35. //}
  36. #region Additional test attributes
  37. //
  38. // You can use the following additional attributes as you write your tests:
  39. //
  40. // Use ClassInitialize to run code before running the first test in the class
  41. // [ClassInitialize()]
  42. // public static void MyClassInitialize(TestContext testContext) { }
  43. //
  44. // Use ClassCleanup to run code after all tests in a class have run
  45. // [ClassCleanup()]
  46. // public static void MyClassCleanup() { }
  47. //
  48. // Use TestInitialize to run code before running each test
  49. // [TestInitialize()]
  50. // public void MyTestInitialize() { }
  51. //
  52. // Use TestCleanup to run code after each test has run
  53. // [TestCleanup()]
  54. // public void MyTestCleanup() { }
  55. //
  56. #endregion
  57. [TestMethod]
  58. public void test_string_split()
  59. {
  60. // Arrange
  61. string originalString = "Id,rowversion";
  62. string[] omitList = originalString.ToLower().Split(',');
  63. // Act
  64. bool actual = omitList.Contains("id");
  65. bool expected = true;
  66. // Assert
  67. Assert.AreEqual(expected, actual);
  68. }
  69. [TestMethod]
  70. public void validate_alias_exists_in_array_equals_true()
  71. {
  72. // Arrange
  73. string originalString = "Id,rowversion";
  74. string[] omitList = originalString.ToLower().Split(',');
  75. string alias = "id";
  76. // Act
  77. bool actual = omitList.Where(o => o == alias).Any();
  78. bool expected = true;
  79. // Assert
  80. Assert.AreEqual(expected, actual);
  81. }
  82. [TestMethod]
  83. public void validate_alias_does_not_exist_in_array_equals_true()
  84. {
  85. // Arrange
  86. string originalString = "Id,rowversion";
  87. string[] omitList = originalString.ToLower().Split(',');
  88. string alias = "phone";
  89. // Act
  90. bool actual = omitList.Where(o => o == alias).Any();
  91. bool expected = false;
  92. // Assert
  93. Assert.AreEqual(expected, actual);
  94. }
  95. [TestMethod]
  96. public void iterate_over_property_array_and_validate_only_non_omitted_properties_are_created()
  97. {
  98. // Arrange
  99. string[] fullPropertyList = new string[] { "Id", "FirstName", "LastName", "Phone", "rowversion" };
  100. string omitString = "Id,rowversion";
  101. string[] omitList = omitString.ToLower().Split(',');
  102. // Act
  103. string actual = string.Empty;
  104. string actualOmitted = string.Empty;
  105. foreach (var item in fullPropertyList)
  106. {
  107. if (!omitList.Where(o => o == item.ToLower()).Any())
  108. {
  109. actual += item.ToLower() + ",";
  110. }
  111. else
  112. {
  113. actualOmitted += item.ToLower() + ",";
  114. }
  115. }
  116. actual += " - " + actualOmitted;
  117. string expected = "firstname,lastname,phone, - id,rowversion,";
  118. // Assert
  119. Assert.AreEqual(expected, actual);
  120. }
  121. [TestMethod]
  122. public void succeeds_with_empty_omitlist()
  123. {
  124. // Arrange
  125. string[] fullPropertyList = new string[] { "Id", "FirstName", "LastName", "Phone", "rowversion" };
  126. string omitString = null;
  127. string[] omitList;
  128. if (!string.IsNullOrEmpty(omitString))
  129. {
  130. omitList = omitString.ToLower().Split(',');
  131. }
  132. else
  133. {
  134. omitList = new string[0];
  135. }
  136. // Act
  137. string actual = string.Empty;
  138. foreach (string item in fullPropertyList)
  139. {
  140. if (!omitList.Where(o => o == item.ToLower()).Any())
  141. {
  142. actual += item.ToLower() + ",";
  143. }
  144. }
  145. string expected = "id,firstname,lastname,phone,rowversion,";
  146. // Assert
  147. Assert.AreEqual(expected, actual);
  148. }
  149. [TestMethod]
  150. public void test_with_amateur_golf_articles_list_table()
  151. {
  152. // Arrange
  153. string[] fullPropertyList = new string[] { "typeID", "type_name", "type_sort", "type_desc" };
  154. string omitString = null;
  155. string[] omitList;
  156. if (!string.IsNullOrEmpty(omitString))
  157. {
  158. omitList = omitString.ToLower().Split(',');
  159. }
  160. else
  161. {
  162. omitList = new string[0];
  163. }
  164. // Act
  165. string actual = string.Empty;
  166. foreach (string item in fullPropertyList)
  167. {
  168. if (!omitList.Where(o => o == item.ToLower()).Any())
  169. {
  170. actual += item.ToLower() + ",";
  171. }
  172. }
  173. string expected = "typeid,type_name,type_sort,type_desc,";
  174. // Assert
  175. Assert.AreEqual(expected, actual);
  176. }
  177. }
  178. }