AnalyzeJSONUnitTests.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using analyzeJSON;
  4. using Newtonsoft.Json.Linq;
  5. using Xunit;
  6. namespace analyzeJSONTests
  7. {
  8. public record TestCase(string Input, string ExpectedOutput);
  9. public class AnalyzeJSONUnitTests
  10. {
  11. [Fact]
  12. public void AnalyzeJSON_EmptyJObject()
  13. {
  14. var test = new AnalyzeJSON(new JObject());
  15. var result = test.Traverse((token) => Console.WriteLine(token));
  16. Assert.False(result.Success);
  17. Assert.NotEmpty(result.Message);
  18. }
  19. [Fact]
  20. public void GetNameFromPath_NullTokenPath()
  21. {
  22. Assert.Empty(AnalyzeJSON.GetNameFromPath(null));
  23. }
  24. [Fact]
  25. public void GetNameFromPath_EmptyTokenPath()
  26. {
  27. Assert.Empty(AnalyzeJSON.GetNameFromPath(string.Empty));
  28. }
  29. [Fact]
  30. public void GetNameFromPath_DifferentCases()
  31. {
  32. var testCases = new List<TestCase>
  33. {
  34. new TestCase("abc", "abc"),
  35. new TestCase("abc.def", "def"),
  36. new TestCase("abc.", string.Empty),
  37. new TestCase("abc.def.", string.Empty),
  38. };
  39. foreach (var testCase in testCases)
  40. Assert.Equal(testCase.ExpectedOutput, AnalyzeJSON.GetNameFromPath(testCase.Input));
  41. }
  42. }
  43. }