Skip to content

Commit

Permalink
Snapshot of objects like Encoding caused a NotSupportedException
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalpen committed Jan 22, 2024
1 parent d28bbe9 commit 288e446
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/Polaroider/Mapping/DefaultMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Polaroider.Mapping
{
Expand Down Expand Up @@ -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());
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/Tests/Polaroider.Tests/ObjectMapTests.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 288e446

Please sign in to comment.