Created
August 14, 2019 07:37
-
-
Save moreal/6f54ff48e75c9760048e744f68c4e0a1 to your computer and use it in GitHub Desktop.
Dark-magic!!! Xunit bye-bye!!!!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Xunit.Sdk.ArgumentFormatter.FormatComplexValue | |
// to see the real values of expectedStates, actualStates | |
string FormatComplexValue(object value, Type type) | |
{ | |
var fields = type.GetRuntimeFields() | |
.Where(f => f.IsPublic && !f.IsStatic) | |
.Select(f => new { name = f.Name, value = f.GetValue(value) }); | |
var properties = type.GetRuntimeProperties() | |
.Where(p => p.GetMethod != null && p.GetMethod.IsPublic) | |
.Select(p => new { name = p.Name, value = p.GetValue(value) }); | |
var parameters = fields.Concat(properties) | |
.OrderBy(p => p.name) | |
.ToList(); | |
if (parameters.Count == 0) | |
{ | |
return $"{type.Name} {{ }}"; | |
} | |
var formattedParameters = string.Join(", ", parameters | |
.Select(p => $"{p.name} = {p.value}")); | |
return $"{type.Name} {{ {formattedParameters} }}"; | |
} | |
void LogEnumerable(string name, IEnumerable<object> enumerable) | |
{ | |
_output.WriteLine( | |
"{0} is {1}", | |
name, | |
string.Join( | |
", ", | |
enumerable.Select((x, i) => | |
(i % 3 == 0 ? "\n" : string.Empty) + | |
FormatComplexValue(x, x.GetType())))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment