Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestFixture]
- public class StringFormatUtilsTest
- {
- [TestCase("tttt", "")]
- [TestCase("", "")]
- [TestCase("t3a4b5", "345")]
- [TestCase("3&5*", "35")]
- [TestCase("123", "123")]
- public void StripNonNumeric(string before, string expected)
- {
- string actual = FormatUtils.StripNonNumeric(before);
- Assert.AreEqual(expected, actual);
- }
- }
- public class UnitTest1 : TestBase
- { }
- [TestClass]
- public class UnitTest1 : TestBase
- {
- private IEnumerable<int> Stuff
- {
- get
- {
- //This could do anything, get a dynamic list from anywhere....
- return new List<int> { 1, 2, 3 };
- }
- }
- }
- [TestMethod]
- [DataSource("Namespace.UnitTest1.Stuff")]
- public void TestMethod1()
- {
- var number = this.TestContext.GetRuntimeDataSourceObject<int>();
- Assert.IsNotNull(number);
- }
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using MSTestHacks;
- namespace Namespace
- {
- [TestClass]
- public class UnitTest1 : TestBase
- {
- private IEnumerable<int> Stuff
- {
- get
- {
- //This could do anything, get a dynamic list from anywhere....
- return new List<int> { 1, 2, 3 };
- }
- }
- [TestMethod]
- [DataSource("Namespace.UnitTest1.Stuff")]
- public void TestMethod1()
- {
- var number = this.TestContext.GetRuntimeDataSourceObject<int>();
- Assert.IsNotNull(number);
- }
- }
- }
- [TestClass]
- public class StringFormatUtilsTest
- {
- [TestMethod]
- [DataRow("tttt", "")]
- [DataRow("", "")]
- [DataRow("t3a4b5", "345")]
- [DataRow("3&5*", "35")]
- [DataRow("123", "123")]
- public void StripNonNumeric(string before, string expected)
- {
- string actual = FormatUtils.StripNonNumeric(before);
- Assert.AreEqual(expected, actual);
- }
- }
- public static class Extensions
- {
- /// <summary>
- /// Get the Qtr with optional offset to add or subtract quarters
- /// </summary>
- public static int GetQuarterNumber(this DateTime parmDate, int offset = 0)
- {
- return (int)Math.Ceiling(parmDate.AddMonths(offset * 3).Month / 3m);
- }
- }
- [TestMethod]
- public void MonthReturnsProperQuarterWithOffset()
- {
- // Arrange
- var values = new[] {
- new { inputDate = new DateTime(2013, 1, 1), offset = 1, expectedQuarter = 2},
- new { inputDate = new DateTime(2013, 1, 1), offset = -1, expectedQuarter = 4},
- new { inputDate = new DateTime(2013, 4, 1), offset = 1, expectedQuarter = 3},
- new { inputDate = new DateTime(2013, 4, 1), offset = -1, expectedQuarter = 1},
- new { inputDate = new DateTime(2013, 7, 1), offset = 1, expectedQuarter = 4},
- new { inputDate = new DateTime(2013, 7, 1), offset = -1, expectedQuarter = 2},
- new { inputDate = new DateTime(2013, 10, 1), offset = 1, expectedQuarter = 1},
- new { inputDate = new DateTime(2013, 10, 1), offset = -1, expectedQuarter = 3}
- // Could add as many rows as you want, or extract to a private method that
- // builds the array of data
- };
- values.ToList().ForEach(val =>
- {
- // Act
- int actualQuarter = val.inputDate.GetQuarterNumber(val.offset);
- // Assert
- Assert.AreEqual(val.expectedQuarter, actualQuarter,
- "Failed for inputDate={0}, offset={1} and expectedQuarter={2}.", val.inputDate, val.offset, val.expectedQuarter);
- });
- }
- }
- [TestClass]
- public class StringFormatUtilsTest
- {
- [TestMethod]
- [DataRow("tttt", "")]
- [DataRow("", "")]
- [DataRow("t3a4b5", "345")]
- [DataRow("3&5*", "35")]
- [DataRow("123", "123")]
- public void StripNonNumeric(string before, string expected)
- {
- string actual = FormatUtils.StripNonNumeric(before);
- Assert.AreEqual(expected, actual);
- }
- }
Add Comment
Please, Sign In to add comment