Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. [TestFixture]
  2. public class StringFormatUtilsTest
  3. {
  4. [TestCase("tttt", "")]
  5. [TestCase("", "")]
  6. [TestCase("t3a4b5", "345")]
  7. [TestCase("3&5*", "35")]
  8. [TestCase("123", "123")]
  9. public void StripNonNumeric(string before, string expected)
  10. {
  11. string actual = FormatUtils.StripNonNumeric(before);
  12. Assert.AreEqual(expected, actual);
  13. }
  14. }
  15.  
  16. public class UnitTest1 : TestBase
  17. { }
  18.  
  19. [TestClass]
  20. public class UnitTest1 : TestBase
  21. {
  22. private IEnumerable<int> Stuff
  23. {
  24. get
  25. {
  26. //This could do anything, get a dynamic list from anywhere....
  27. return new List<int> { 1, 2, 3 };
  28. }
  29. }
  30. }
  31.  
  32. [TestMethod]
  33. [DataSource("Namespace.UnitTest1.Stuff")]
  34. public void TestMethod1()
  35. {
  36. var number = this.TestContext.GetRuntimeDataSourceObject<int>();
  37.  
  38. Assert.IsNotNull(number);
  39. }
  40.  
  41. using Microsoft.VisualStudio.TestTools.UnitTesting;
  42. using MSTestHacks;
  43.  
  44. namespace Namespace
  45. {
  46. [TestClass]
  47. public class UnitTest1 : TestBase
  48. {
  49. private IEnumerable<int> Stuff
  50. {
  51. get
  52. {
  53. //This could do anything, get a dynamic list from anywhere....
  54. return new List<int> { 1, 2, 3 };
  55. }
  56. }
  57.  
  58. [TestMethod]
  59. [DataSource("Namespace.UnitTest1.Stuff")]
  60. public void TestMethod1()
  61. {
  62. var number = this.TestContext.GetRuntimeDataSourceObject<int>();
  63.  
  64. Assert.IsNotNull(number);
  65. }
  66. }
  67. }
  68.  
  69. [TestClass]
  70. public class StringFormatUtilsTest
  71. {
  72. [TestMethod]
  73. [DataRow("tttt", "")]
  74. [DataRow("", "")]
  75. [DataRow("t3a4b5", "345")]
  76. [DataRow("3&amp;5*", "35")]
  77. [DataRow("123", "123")]
  78. public void StripNonNumeric(string before, string expected)
  79. {
  80. string actual = FormatUtils.StripNonNumeric(before);
  81. Assert.AreEqual(expected, actual);
  82. }
  83. }
  84.  
  85. public static class Extensions
  86. {
  87. /// <summary>
  88. /// Get the Qtr with optional offset to add or subtract quarters
  89. /// </summary>
  90. public static int GetQuarterNumber(this DateTime parmDate, int offset = 0)
  91. {
  92. return (int)Math.Ceiling(parmDate.AddMonths(offset * 3).Month / 3m);
  93. }
  94. }
  95.  
  96. [TestMethod]
  97. public void MonthReturnsProperQuarterWithOffset()
  98. {
  99. // Arrange
  100. var values = new[] {
  101. new { inputDate = new DateTime(2013, 1, 1), offset = 1, expectedQuarter = 2},
  102. new { inputDate = new DateTime(2013, 1, 1), offset = -1, expectedQuarter = 4},
  103. new { inputDate = new DateTime(2013, 4, 1), offset = 1, expectedQuarter = 3},
  104. new { inputDate = new DateTime(2013, 4, 1), offset = -1, expectedQuarter = 1},
  105. new { inputDate = new DateTime(2013, 7, 1), offset = 1, expectedQuarter = 4},
  106. new { inputDate = new DateTime(2013, 7, 1), offset = -1, expectedQuarter = 2},
  107. new { inputDate = new DateTime(2013, 10, 1), offset = 1, expectedQuarter = 1},
  108. new { inputDate = new DateTime(2013, 10, 1), offset = -1, expectedQuarter = 3}
  109. // Could add as many rows as you want, or extract to a private method that
  110. // builds the array of data
  111. };
  112. values.ToList().ForEach(val =>
  113. {
  114. // Act
  115. int actualQuarter = val.inputDate.GetQuarterNumber(val.offset);
  116. // Assert
  117. Assert.AreEqual(val.expectedQuarter, actualQuarter,
  118. "Failed for inputDate={0}, offset={1} and expectedQuarter={2}.", val.inputDate, val.offset, val.expectedQuarter);
  119. });
  120. }
  121. }
  122.  
  123. [TestClass]
  124. public class StringFormatUtilsTest
  125. {
  126. [TestMethod]
  127. [DataRow("tttt", "")]
  128. [DataRow("", "")]
  129. [DataRow("t3a4b5", "345")]
  130. [DataRow("3&amp;5*", "35")]
  131. [DataRow("123", "123")]
  132. public void StripNonNumeric(string before, string expected)
  133. {
  134. string actual = FormatUtils.StripNonNumeric(before);
  135. Assert.AreEqual(expected, actual);
  136. }
  137. }
Add Comment
Please, Sign In to add comment