Skip to content

Commit

Permalink
Merge branch 'release/v2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalpen committed Jan 22, 2024
2 parents 0f2c807 + 5fdafc9 commit 98ee4b9
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 16 deletions.
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# http://www.appveyor.com/docs/appveyor-yml

environment:
base_version: 2.2.0
base_version: 2.3.0

# version format
version: $(base_version).{build}
Expand All @@ -27,7 +27,7 @@ for:
skip_tags: true

install:
- dotnet tool install Nuke.GlobalTool --global --version 6.3.0 --no-cache
- dotnet tool install Nuke.GlobalTool --global --no-cache

before_build:
- dotnet restore ./build/_build.csproj
Expand All @@ -46,7 +46,7 @@ for:
skip_tags: true

install:
- dotnet tool install Nuke.GlobalTool --global --version 6.3.0 --no-cache
- dotnet tool install Nuke.GlobalTool --global --no-cache

before_build:
- dotnet restore ./build/_build.csproj
Expand Down
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;

[Parameter("Version to be injected in the Build")]
public string Version { get; set; } = $"2.2.0";
public string Version { get; set; } = $"2.3.0";

[Parameter("The Buildnumber provided by the CI")]
public int BuildNo = 1;
Expand Down
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
23 changes: 23 additions & 0 deletions src/Polaroider/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace Polaroider
{
/// <summary>
///
/// </summary>
public static class ObjectExtensions
{
/// <summary>
/// Map a object to another object. Can be used to make simpler snapshots
/// </summary>
/// <typeparam name="Tout"></typeparam>
/// <typeparam name="Tin"></typeparam>
/// <param name="obj"></param>
/// <param name="factory"></param>
/// <returns></returns>
public static Tout MapTo<Tout, Tin>(this Tin obj, Func<Tin, Tout> factory)
{
return factory(obj);
}
}
}
32 changes: 32 additions & 0 deletions src/Tests/Polaroider.Tests/ObjectExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using FluentAssertions;
using NUnit.Framework;

namespace Polaroider.Tests
{
public class ObjectExtensionsTests
{
[Test]
public void ObjectExtensions_MapTo()
{
var obj = new
{
Age = 25,
Name = "John",
LastName = "Doe"
};

obj.MapTo(o =>
new
{
Name = o.Name,
LastName = o.LastName
})
.Should()
.BeEquivalentTo(new
{
Name = "John",
LastName = "Doe"
});
}
}
}
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 98ee4b9

Please sign in to comment.