diff --git a/appveyor.yml b/appveyor.yml index 780308a..d9595cb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,11 +2,11 @@ # version format -version: 2.0.1.{build} +version: 2.0.2.{build} environment: - rc_version: 2.0.1-RC{build} - base_version: 2.0.1 + rc_version: 2.0.2-RC{build} + base_version: 2.0.2 # you can use {branch} name in version format too # version: 1.0.{build}-{branch} diff --git a/docs/changelog.md b/docs/changelog.md index 54def2d..6564a41 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -5,7 +5,11 @@ nav_order: 99 --- ## Polaroider Changelog -### 2.0.x +### 2.0.2 +- Mocking Guids also adds a directive to replace string Guids +- Mocking DateTimes also adds a directive to replace ISO 8601 string DateTimes + +### 2.0.1 - Mocking dynamic data - Indexers are ignored when mapping properties - Map only properties that have getters diff --git a/src/Polaroider/SnapshotOptions.cs b/src/Polaroider/SnapshotOptions.cs index 4298f48..b90ebdd 100644 --- a/src/Polaroider/SnapshotOptions.cs +++ b/src/Polaroider/SnapshotOptions.cs @@ -266,7 +266,7 @@ public static SnapshotOptions UseBasicFormatters(this SnapshotOptions options) /// /// Mocks changing values to a compareable format "0000-00-00T00:00:00.0000". Else the Snapshot would always fail due to changes in the time. - /// This simply adds a to the options. + /// This adds a and a directive to the options. /// /// /// @@ -276,15 +276,25 @@ public static SnapshotOptions MockDateTimes(this SnapshotOptions options) options.AddFormatter(typeof(DateTime), formatter); options.AddFormatter(typeof(DateTime?), formatter); + options.AddDirective(d => d.ReplaceDateTime()); + return options; } + /// + /// Mocks a values to a compareable default format "00000000-0000-0000-0000-000000000000". Else the Snapshot would always fail due to changes in the Guid. + /// This adds a and a directive to the options. + /// + /// + /// public static SnapshotOptions MockGuids(this SnapshotOptions options) { var formatter = new MockGuidFormatter(); options.AddFormatter(typeof(Guid), formatter); options.AddFormatter(typeof(Guid?), formatter); + options.AddDirective(d => d.ReplaceGuid()); + return options; } diff --git a/src/Tests/Polaroider.Tests/Mapper/Formatters/MockDateTimeFormatterTests.cs b/src/Tests/Polaroider.Tests/Mapper/Formatters/MockDateTimeFormatterTests.cs index a544211..855459a 100644 --- a/src/Tests/Polaroider.Tests/Mapper/Formatters/MockDateTimeFormatterTests.cs +++ b/src/Tests/Polaroider.Tests/Mapper/Formatters/MockDateTimeFormatterTests.cs @@ -54,6 +54,13 @@ public void Mapper_MockDateTime_Tokenize_Nullable_Nullable_Null() new { Value = (DateTime?)null }.Tokenize(options).ToString().Should().Be("Value: "); } + [Test] + public void Mapper_MockDateTime_ISOStringDate() + { + var options = SnapshotOptions.Create(o => o.MockDateTimes()); + new { Value = DateTime.Now.ToString("o") }.Tokenize(options).ToString().Should().Be("Value: 0000-00-00T00:00:00.0000"); + } + [Test] public void Mapper_MockGuids_SnapshotOptions_Tokenize() { @@ -76,5 +83,12 @@ public void Mapper_MockGuid_Tokenize_Nullable_Nullable_Null() var options = SnapshotOptions.Create(o => o.MockGuids()); new { Value = (Guid?)null }.Tokenize(options).ToString().Should().Be("Value: "); } + + [Test] + public void Mapper_MockGuids_StringFuid() + { + var options = SnapshotOptions.Create(o => o.MockGuids()); + new { Value = Guid.NewGuid().ToString() }.Tokenize(options).ToString().Should().Be("Value: 00000000-0000-0000-0000-000000000000"); + } } }