-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tomasbruckner/version-1-2-0
[1.2.0] improved configuration
- Loading branch information
Showing
11 changed files
with
260 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace JestDotnet.Core.Settings | ||
{ | ||
public static class SnapshotSettings | ||
{ | ||
/// <summary> | ||
/// Default snapshot extension | ||
/// </summary> | ||
public const string DefaultSnapshotExtension = "snap"; | ||
|
||
/// <summary> | ||
/// default snapshot directory | ||
/// </summary> | ||
public const string DefaultSnapshotDirectory = "__snapshots__"; | ||
|
||
/// <summary> | ||
/// snapshot extension | ||
/// </summary> | ||
public static string SnapshotExtension = DefaultSnapshotExtension; | ||
|
||
/// <summary> | ||
/// snapshot directory | ||
/// </summary> | ||
public static string SnapshotDirectory = DefaultSnapshotDirectory; | ||
|
||
/// <summary> | ||
/// default snapshot dot extension creator | ||
/// </summary> | ||
public static readonly Func<string> DefaultCreateSnapshotDotExtension = () => $".{SnapshotExtension}"; | ||
|
||
/// <summary> | ||
/// snapshot dot extension creator | ||
/// </summary> | ||
public static Func<string> CreateSnapshotDotExtension = DefaultCreateSnapshotDotExtension; | ||
|
||
/// <summary> | ||
/// default function that creates snapshot path | ||
/// </summary> | ||
public static readonly Func<(string sourceFilePath, string memberName, string hint), string> DefaultCreatePath = | ||
SnapshotResolver.CreatePath; | ||
|
||
/// <summary> | ||
/// function that creates snapshot path | ||
/// </summary> | ||
public static Func<(string sourceFilePath, string memberName, string hint), string> CreatePath = | ||
DefaultCreatePath; | ||
|
||
/// <summary> | ||
/// default JSON serializer creator | ||
/// </summary> | ||
public static readonly Func<JsonSerializer> DefaultCreateJsonSerializer = JsonSerializer.CreateDefault; | ||
|
||
/// <summary> | ||
/// JSON serializer creator | ||
/// </summary> | ||
public static Func<JsonSerializer> CreateJsonSerializer = DefaultCreateJsonSerializer; | ||
|
||
/// <summary> | ||
/// default JToken writer creator | ||
/// </summary> | ||
public static readonly Func<JTokenWriter> DefaultCreateJTokenWriter = () => new JTokenWriter(); | ||
|
||
/// <summary> | ||
/// JToken writer creator | ||
/// </summary> | ||
public static Func<JTokenWriter> CreateJTokenWriter = DefaultCreateJTokenWriter; | ||
|
||
/// <summary> | ||
/// default string writer creator | ||
/// </summary> | ||
public static readonly Func<StringWriter> DefaultCreateStringWriter = | ||
() => new StringWriter(CultureInfo.InvariantCulture); | ||
|
||
/// <summary> | ||
/// string writer creator | ||
/// </summary> | ||
public static Func<StringWriter> CreateStringWriter = DefaultCreateStringWriter; | ||
|
||
/// <summary> | ||
/// default text writer creator | ||
/// </summary> | ||
public static readonly Func<StringWriter, JsonTextWriter> DefaultCreateTextWriter = stringWriter => | ||
new JsonTextWriter(stringWriter) {Formatting = Formatting.Indented}; | ||
|
||
/// <summary> | ||
/// text writer creator | ||
/// </summary> | ||
public static Func<StringWriter, JsonTextWriter> CreateTextWriter = DefaultCreateTextWriter; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using JestDotnet; | ||
using JestDotnet.Core.Settings; | ||
using Xunit; | ||
using XUnitTests.Helpers; | ||
|
||
namespace XUnitTests | ||
{ | ||
public class SettingsTests | ||
{ | ||
[Fact] | ||
public void ShouldMatchCustomSnapExtension() | ||
{ | ||
SnapshotSettings.CreateStringWriter = () => new StringWriter(CultureInfo.InvariantCulture) | ||
{ | ||
NewLine = "\n" | ||
}; | ||
|
||
SnapshotSettings.SnapshotExtension = "snap2"; | ||
|
||
var testObject = new Person | ||
{ | ||
Age = 13, | ||
DateOfBirth = new DateTime(2008, 7, 7), | ||
FirstName = "John", | ||
LastName = "Bam" | ||
}; | ||
|
||
JestAssert.ShouldMatchSnapshot(testObject); | ||
|
||
SnapshotSettings.SnapshotExtension = SnapshotSettings.DefaultSnapshotExtension; | ||
} | ||
|
||
[Fact] | ||
public void ShouldMatchLinuxLineEnding() | ||
{ | ||
SnapshotSettings.CreateStringWriter = () => new StringWriter(CultureInfo.InvariantCulture) | ||
{ | ||
NewLine = "\n" | ||
}; | ||
|
||
var testObject = new Person | ||
{ | ||
Age = 13, | ||
DateOfBirth = new DateTime(2008, 7, 7), | ||
FirstName = "John", | ||
LastName = "Bam" | ||
}; | ||
|
||
JestAssert.ShouldMatchSnapshot(testObject); | ||
} | ||
|
||
[Fact] | ||
public void ShouldMatchWindowsLineEnding() | ||
{ | ||
SnapshotSettings.CreateStringWriter = () => new StringWriter(CultureInfo.InvariantCulture) | ||
{ | ||
NewLine = "\r\n" | ||
}; | ||
|
||
var testObject = new Person | ||
{ | ||
Age = 13, | ||
DateOfBirth = new DateTime(2008, 7, 7), | ||
FirstName = "John", | ||
LastName = "Bam" | ||
}; | ||
|
||
JestAssert.ShouldMatchSnapshot(testObject); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
JestDotnet/XUnitTests/__snapshots__/SettingsTestsShouldMatchCustomSnapExtension.snap2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"FirstName": "John", | ||
"LastName": "Bam", | ||
"DateOfBirth": "2008-07-07T00:00:00", | ||
"Age": 13 | ||
} |
6 changes: 6 additions & 0 deletions
6
JestDotnet/XUnitTests/__snapshots__/SettingsTestsShouldMatchLinuxLineEnding.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"FirstName": "John", | ||
"LastName": "Bam", | ||
"DateOfBirth": "2008-07-07T00:00:00", | ||
"Age": 13 | ||
} |
6 changes: 6 additions & 0 deletions
6
JestDotnet/XUnitTests/__snapshots__/SettingsTestsShouldMatchWindowsLineEnding.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"FirstName": "John", | ||
"LastName": "Bam", | ||
"DateOfBirth": "2008-07-07T00:00:00", | ||
"Age": 13 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters