/// <inheritdoc /> public override string FormatObject(IDictionary obj) { var sb = new StringBuilder("{"); foreach (DictionaryEntry pair in obj) { var keyCustomFormatter = FormattersStorage.GetCustomFormatter(pair.Key); sb.Append(keyCustomFormatter.Format(pair.Key !)); sb.Append(": "); var valueCustomFormatter = FormattersStorage.GetCustomFormatter(pair.Value); sb.Append(valueCustomFormatter.Format(pair.Value !)); sb.Append(", "); } if (sb.Length != 1) { sb.Remove(sb.Length - 2, 2); } sb.Append("}"); return(sb.ToString()); }
public void AllFormattersTest() { var obj = new List <object> { "123", 123, (ushort)2, new HashSet <int> { 1, 2, 3, 4 }, new Dictionary <string, string> { { "at Radolyn we take", "our jobs very seriously" }, { "yes", null } // haha, suppress null warning with '!', wtf }, null, null, new List <ushort> { 120, 1 }.AsQueryable(), new ArgumentException("oh it works!") }; var res = FormattersStorage.GetCustomFormatterResult(obj); Assert.False(string.IsNullOrWhiteSpace(res)); }
public void GetCustomFormatterResultTest() { FormattersStorage.AddDefault(); FormattersStorage.AddFormatter <EnumerableFormatter>(); FormattersStorage.MaxRecursion = 2; var res = FormattersStorage.GetCustomFormatterResult(new List <object> { "sadasdsda", 123, new List <int> { 1, 2 } }); Assert.True(FormattersStorage.RegisteredFormatters.Any()); Assert.False(string.IsNullOrWhiteSpace(res)); }
public void AssertConsoleProxies() { // actually, we can't test such a things because we can't allocate real console even for a 1 test // so just check the output of this test to see exceptions var properties = typeof(Console).GetProperties(); foreach (var property in properties) { try { var val = property.GetValue(null); if (property.CanWrite) { property.GetValue(val); } } catch (Exception ex) { Output.WriteLine(FormattersStorage.GetCustomFormatterResult(ex) + Environment.NewLine.Repeat(2)); } } }