TestExplicitMembersOnly.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Topten.JsonKit;
  6. using System.IO;
  7. using System.Reflection;
  8. using Xunit;
  9. namespace TestCases
  10. {
  11. [Obfuscation(Exclude = true, ApplyToMembers = true)]
  12. public class TestExplicitMembersOnly
  13. {
  14. class Thing
  15. {
  16. public string Apples = "apples";
  17. }
  18. [Json(ExplicitMembersOnly = true)]
  19. class Thing2
  20. {
  21. public string Apples = "apples";
  22. }
  23. [Json(ExplicitMembersOnly = true)]
  24. class Thing3
  25. {
  26. [Json("apples")]
  27. public string Apples = "apples";
  28. }
  29. [Fact]
  30. public void TestNonDecoratedClass()
  31. {
  32. var thing = new Thing();
  33. // Save it
  34. var json = Json.Format(thing);
  35. // Check the object kinds were written out
  36. Assert.Contains("\"apples\":", json);
  37. }
  38. [Fact]
  39. public void TestDecoratedEmptyClass()
  40. {
  41. var thing = new Thing2();
  42. // Save it
  43. var json = Json.Format(thing);
  44. // Check the object kinds were written out
  45. Assert.DoesNotContain("\"apples\":", json);
  46. }
  47. [Fact]
  48. public void TestDecoratedNonEmptyClass()
  49. {
  50. var thing = new Thing3();
  51. // Save it
  52. var json = Json.Format(thing);
  53. // Check the object kinds were written out
  54. Assert.Contains("\"apples\":", json);
  55. }
  56. }
  57. }