diff --git a/src/Polaroider/Mapping/DefaultMapper.cs b/src/Polaroider/Mapping/DefaultMapper.cs index 81cc9cd..af442d2 100644 --- a/src/Polaroider/Mapping/DefaultMapper.cs +++ b/src/Polaroider/Mapping/DefaultMapper.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Linq; using System.Reflection; +using System.Text; namespace Polaroider.Mapping { @@ -69,22 +70,33 @@ public void Map(MapperContext ctx, object item) .Where(p => p.GetGetMethod() != null) .OrderBy(p => p.Name)) { - var header = $"{property.Name}:".Indent(ctx.Indentation); - var value = property.GetValue(item); + try + { + var header = $"{property.Name}:".Indent(ctx.Indentation); + var value = property.GetValue(item); - if (MapValueType(ctx, property.PropertyType, value, $"{header} ")) - { - continue; - } + if (MapValueType(ctx, property.PropertyType, value, $"{header} ")) + { + continue; + } - ctx.AddLine(new Line(header)); + ctx.AddLine(new Line(header)); - if (MapRegisteredType(property.PropertyType, ctx.Clone(ctx.Indentation + 2), value)) - { - continue; - } + if (MapRegisteredType(property.PropertyType, ctx.Clone(ctx.Indentation + 2), value)) + { + continue; + } - Map(ctx.Clone(ctx.Indentation + 2), value); + Map(ctx.Clone(ctx.Indentation + 2), value); + } + catch(NotSupportedException e) + { + var msg = new StringBuilder() + .AppendLine($"Could not map property {property.Name} to the Snapshot") + .AppendLine(e.Message) + .AppendLine(e.StackTrace); + System.Diagnostics.Trace.WriteLine(msg.ToString()); + } } } diff --git a/src/Tests/Polaroider.Tests/ObjectMapTests.cs b/src/Tests/Polaroider.Tests/ObjectMapTests.cs new file mode 100644 index 0000000..4022856 --- /dev/null +++ b/src/Tests/Polaroider.Tests/ObjectMapTests.cs @@ -0,0 +1,15 @@ +using NUnit.Framework; +using System.Text; + +namespace Polaroider.Tests +{ + public class ObjectMapTests + { + [Test] + public void ObjectMap_Encoding() + { + new UTF8Encoding(true, true) + .MatchSnapshot(); + } + } +} diff --git a/src/Tests/Polaroider.Tests/_Snapshots/ObjectMapTests_ObjectMap_Encoding.snapshot b/src/Tests/Polaroider.Tests/_Snapshots/ObjectMapTests_ObjectMap_Encoding.snapshot new file mode 100644 index 0000000..436aea2 --- /dev/null +++ b/src/Tests/Polaroider.Tests/_Snapshots/ObjectMapTests_ObjectMap_Encoding.snapshot @@ -0,0 +1,17 @@ +---data +BodyName: utf-8 +CodePage: 65001 +DecoderFallback: + MaxCharCount: 0 +EncoderFallback: + MaxCharCount: 0 +EncodingName: Unicode (UTF-8) +HeaderName: utf-8 +IsBrowserDisplay: True +IsBrowserSave: True +IsMailNewsDisplay: True +IsMailNewsSave: True +IsReadOnly: True +IsSingleByte: False +WebName: utf-8 +WindowsCodePage: 1200