PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/UnitTests/ExtensionMethods/ExtendedFormat_AnonymousType_UnitTests.cs

http://github.com/fredericaltorres/DynamicSugarNet
C# | 63 lines | 55 code | 8 blank | 0 comment | 0 complexity | 8491bdd5368164b0159bc7bf9ec9d665 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. {
  9. [TestClass]
  10. public class ExtendedFormat_AnonymousType_UnitTests
  11. {
  12. [TestMethod]
  13. public void OneProperty()
  14. {
  15. string format = "LastName:{LastName}";
  16. string expected = "LastName:TORRES";
  17. Assert.AreEqual(expected, ExtendedFormat.Format(new { LastName = "TORRES" }, format));
  18. }
  19. [TestMethod]
  20. public void Format_DictionaryOfAnonymousTypeWithPropertyAsIntList()
  21. {
  22. var dic = new Dictionary<int, object>() {
  23. { 100, new { LastName = "TORRES", Values = DS.List(1,2,3) } },
  24. { 101, new { LastName = "ALBERT", Values = DS.List(1,2,3) } },
  25. { 102, new { LastName = "LEROY" , Values = DS.List(1,2,3) } },
  26. };
  27. StringBuilder b = new StringBuilder(1024);
  28. string format = "LastName:{LastName}, Values:{Values}";
  29. var expected = @"LastName:TORRES, Values:[1, 2, 3]
  30. LastName:ALBERT, Values:[1, 2, 3]
  31. LastName:LEROY, Values:[1, 2, 3]
  32. ";
  33. foreach(var v in dic.Values){
  34. b.Append(ExtendedFormat.Format(v, format)).AppendLine();
  35. }
  36. var s = b.ToString();
  37. Assert.AreEqual(expected, b.ToString());
  38. }
  39. [TestMethod]
  40. public void Format_DictionaryOfAnonymousTypeWithPropertyAsStringList(){
  41. var dic = new Dictionary<int, object>() {
  42. { 100, new { LastName = "TORRES", Values = DS.List("1","2","3") } },
  43. };
  44. StringBuilder b = new StringBuilder(1024);
  45. string format = "LastName:{LastName}, Values:{Values}";
  46. var expected = @"LastName:TORRES, Values:[""1"", ""2"", ""3""]
  47. ";
  48. foreach (var v in dic.Values) {
  49. b.Append(ExtendedFormat.Format(v, format)).AppendLine();
  50. }
  51. var s = b.ToString();
  52. Assert.AreEqual(expected, b.ToString());
  53. }
  54. }
  55. }