Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // Xunit.Sdk.ArgumentFormatter.FormatComplexValue
  2. // to see the real values of expectedStates, actualStates
  3. string FormatComplexValue(object value, Type type)
  4. {
  5. var fields = type.GetRuntimeFields()
  6. .Where(f => f.IsPublic && !f.IsStatic)
  7. .Select(f => new { name = f.Name, value = f.GetValue(value) });
  8. var properties = type.GetRuntimeProperties()
  9. .Where(p => p.GetMethod != null && p.GetMethod.IsPublic)
  10. .Select(p => new { name = p.Name, value = p.GetValue(value) });
  11. var parameters = fields.Concat(properties)
  12. .OrderBy(p => p.name)
  13. .ToList();
  14.  
  15. if (parameters.Count == 0)
  16. {
  17. return $"{type.Name} {{ }}";
  18. }
  19.  
  20. var formattedParameters = string.Join(", ", parameters
  21. .Select(p => $"{p.name} = {p.value}"));
  22.  
  23. return $"{type.Name} {{ {formattedParameters} }}";
  24. }
  25.  
  26. void LogEnumerable(string name, IEnumerable<object> enumerable)
  27. {
  28. _output.WriteLine(
  29. "{0} is {1}",
  30. name,
  31. string.Join(
  32. ", ",
  33. enumerable.Select((x, i) =>
  34. (i % 3 == 0 ? "\n" : string.Empty) +
  35. FormatComplexValue(x, x.GetType()))));
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement