PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/UnitTests/Format/FormatValueBasedOnType_UnitTests.cs

http://github.com/fredericaltorres/DynamicSugarNet
C# | 64 lines | 53 code | 11 blank | 0 comment | 0 complexity | 1ccc8e3130271a79cbe244dbb779a3dd 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. using DynamicSugar;
  7. namespace DynamicSugarSharp_UnitTests {
  8. [TestClass]
  9. public class FormatValueBasedOnType_UnitTests {
  10. const string A_STRING = "OK";
  11. private object o (object o) { return o; }
  12. private object _byte (byte o) { return o; }
  13. private object _sbyte (sbyte o) { return o; }
  14. private object _short (short o) { return o; }
  15. private object _single(Single o) { return o; }
  16. private object _int (int o) { return o; }
  17. private object _long (long o) { return o; }
  18. private object _ulong (ulong o) { return o; }
  19. private object _UInt64(UInt64 o) { return o; }
  20. private object _Int64 (UInt64 o) { return o; }
  21. [TestMethod]
  22. public void String() {
  23. Assert.AreEqual(A_STRING, Generated.FormatValueBasedOnType(A_STRING, null));
  24. }
  25. [TestMethod]
  26. public void Null() {
  27. Assert.AreEqual(null, Generated.FormatValueBasedOnType(null, null));
  28. }
  29. [TestMethod]
  30. public void TestMultipleType() {
  31. var DateTestCases = DS.List(
  32. Tuple.Create(A_STRING, o(A_STRING), ""),
  33. Tuple.Create("12/11/1964", o(new DateTime(1964, 12, 11)), "MM/dd/yyyy"),
  34. Tuple.Create("12 12 Dec December", o(new DateTime(1964, 12, 11)), "M MM MMM MMMM"),
  35. Tuple.Create("001.10", o(1.1f), "000.00"),
  36. Tuple.Create("001.10", o(1.1M), "000.00"),
  37. Tuple.Create("001.100", o(1.1), "000.000"),
  38. Tuple.Create("001", _byte(1), "000"),
  39. Tuple.Create("001", _sbyte(1), "000"),
  40. Tuple.Create("001", _short(1), "000"),
  41. Tuple.Create("001", _single(1), "000"),
  42. Tuple.Create("001", _int(1), "000"),
  43. Tuple.Create("001", _long(1), "000"),
  44. Tuple.Create("001", _ulong(1), "000"),
  45. Tuple.Create("001", _UInt64(1), "000"),
  46. Tuple.Create("001", _Int64(1), "000")
  47. );
  48. foreach(var t in DateTestCases){
  49. Assert.AreEqual(t.Item1, Generated.FormatValueBasedOnType(t.Item2, t.Item3));
  50. }
  51. }
  52. }
  53. }