PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/UnitTests/DS_Dictionary_UnitTests.cs

http://github.com/fredericaltorres/DynamicSugarNet
C# | 57 lines | 43 code | 13 blank | 1 comment | 0 complexity | 86d9e25878bf4045d8278bf186aba7f4 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. using System.Dynamic;
  8. namespace DynamicSugarSharp_UnitTests {
  9. //TODO:Try extension method to List<T>
  10. [TestClass]
  11. public class DS_Dictionary_UnitTests {
  12. [TestMethod]
  13. public void Dictionary_In() {
  14. var d1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });
  15. Assert.IsTrue("a".In(d1));
  16. Assert.IsFalse("aaaa".In(d1));
  17. }
  18. [TestMethod]
  19. public void Dictionary_Identical() {
  20. var d1 = DS.Dictionary( new { a=1, b=2, c=3 } );
  21. Assert.IsTrue(DS.DictionaryHelper.Identical<string,object>(d1,d1));
  22. DS.DictionaryHelper.AssertDictionaryEqual(d1,d1);
  23. }
  24. [TestMethod,ExpectedException(typeof(DynamicSugarSharpException))]
  25. public void Dictionary_Identical_NegativeCase() {
  26. var d1 = DS.Dictionary( new { a=1, b=2, c=3 } );
  27. var d2 = DS.Dictionary( new { a=1, b=2, c="3" } );
  28. Assert.IsFalse(DS.DictionaryHelper.Identical(d1,d2));
  29. DS.DictionaryHelper.AssertDictionaryEqual(d1,d2);
  30. }
  31. [TestMethod]
  32. public void DictionaryFormat_StaticMemberAndExtensionMethod() {
  33. var expected = @"{ a:1, b:2, c:3 }";
  34. Assert.AreEqual(expected, DS.DictionaryHelper.Format(DS.Dictionary( new { a=1, b=2, c=3 } )));
  35. IDictionary<string, object> dic = DS.Dictionary( new { a=1, b=2, c=3 } );
  36. Assert.AreEqual(expected, dic.Format());
  37. Dictionary<string, object> dic2 = DS.Dictionary( new { a=1, b=2, c=3 } );
  38. Assert.AreEqual(expected, dic2.Format());
  39. var dic3 = DS.Dictionary( new { a=1, b=2, c=3 } );
  40. Assert.AreEqual(expected, dic3.Format());
  41. Assert.AreEqual(expected, DS.Dictionary( new { a=1, b=2, c=3 } ).Format());
  42. }
  43. }
  44. }