Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Snapshooter.MSTest/MSTestSnapshotFullNameReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ private static string GetMethodSnapshotName(MethodBase method)
DataRowAttribute currentRow =
dataRowAttributes.ElementAt(dataTestMethodRowIndex[method.Name]);

return $"{method.DeclaringType.Name}." +
method.Name +
$"_{string.Join("_", currentRow.Data.Select(d => d.ToString()))}";
return $"{method.DeclaringType.Name}.{method.Name}" +
SnapshotNameExtension.Create(currentRow.Data).ToParamsString();
}
}
}
14 changes: 11 additions & 3 deletions src/Snapshooter/Core/MatchOperators/AcceptMatchOperator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Snapshooter.Exceptions;
Expand Down Expand Up @@ -137,7 +138,7 @@ private void VerifyFieldType(string path, object field)
}
}

private string CreateAcceptExceptionMessage(
private static string CreateAcceptExceptionMessage(
string path, object field, string message)
{
return
Expand All @@ -147,9 +148,16 @@ private string CreateAcceptExceptionMessage(
$"{message}";
}

private string GetAcceptFieldValueString(object field)
private static string GetAcceptFieldValueString(object field)
{
return field is { } ? field.ToString() : "Null";
return field switch
{
null => "Null",
decimal decimalValue => decimalValue.ToString(CultureInfo.InvariantCulture),
double doubleValue => doubleValue.ToString(CultureInfo.InvariantCulture),
float floatValue => floatValue.ToString(CultureInfo.InvariantCulture),
_ => field.ToString()
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Snapshooter.Core;
using Snapshooter.Exceptions;
using Xunit;
using System.Globalization;

#nullable enable

Expand Down Expand Up @@ -62,9 +63,18 @@ public static void AssertAcceptWrongTypeExceptionCase<TAccept, TTestee>(
Assert.Equal(exception.Message,
$"Accept match option failed, " +
$"because the field value of '{nameof(testee.Value)}' " +
$"is '{testeeValue ?? testee.Value!.ToString()}', " +
$"is '{testeeValue ?? FormatInvariant(testee.Value)}', " +
$"and therefore not of type '{typeName}'.");
}
}

private static string FormatInvariant(object? value)
{
if (value == null) return "Null";
if (value is decimal d) return d.ToString(CultureInfo.InvariantCulture);
if (value is double db) return db.ToString(CultureInfo.InvariantCulture);
if (value is float f) return f.ToString(CultureInfo.InvariantCulture);
return value.ToString()!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Snapshooter.Core;
using Snapshooter.Exceptions;
using Xunit;
using System.Globalization;

#nullable enable

Expand Down Expand Up @@ -62,9 +63,18 @@ public static void AssertAcceptWrongTypeExceptionCase<TAccept, TTestee>(
Assert.Equal(exception.Message,
$"Accept match option failed, " +
$"because the field value of '{nameof(testee.Value)}' " +
$"is '{testeeValue ?? testee.Value!.ToString()}', " +
$"is '{testeeValue ?? FormatInvariant(testee.Value)}', " +
$"and therefore not of type '{typeName}'.");
}
}

private static string FormatInvariant(object? value)
{
if (value == null) return "Null";
if (value is decimal d) return d.ToString(CultureInfo.InvariantCulture);
if (value is double db) return db.ToString(CultureInfo.InvariantCulture);
if (value is float f) return f.ToString(CultureInfo.InvariantCulture);
return value.ToString()!;
}
}
}