From 24708eb0dead63d4056bde2c8fe72314077b0ace Mon Sep 17 00:00:00 2001 From: Riad Lakehal-Ayat Date: Fri, 10 Jan 2020 12:10:11 +0100 Subject: [PATCH] Fix failing unit test Set MinValue of DateTimeOffset when out of range --- .../PropertyNameConversionTests.cs | 2 ++ src/Couchbase.Lite.Mapping/ObjectExtensions.cs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Couchbase.Lite.Mapping.Shared.Tests/PropertyNameConversionTests.cs b/src/Couchbase.Lite.Mapping.Shared.Tests/PropertyNameConversionTests.cs index 661b64f..18da1bc 100644 --- a/src/Couchbase.Lite.Mapping.Shared.Tests/PropertyNameConversionTests.cs +++ b/src/Couchbase.Lite.Mapping.Shared.Tests/PropertyNameConversionTests.cs @@ -14,6 +14,8 @@ public void TestDefaultPropertyNameConverterToMutableDocument() StringValue = "Test Value" }; + Settings.PropertyNameConverter = null; + var mutableDocument = simpleObject.ToMutableDocument(); var result = mutableDocument?.Keys.Contains("stringValue"); diff --git a/src/Couchbase.Lite.Mapping/ObjectExtensions.cs b/src/Couchbase.Lite.Mapping/ObjectExtensions.cs index 259d64f..ff51f3e 100644 --- a/src/Couchbase.Lite.Mapping/ObjectExtensions.cs +++ b/src/Couchbase.Lite.Mapping/ObjectExtensions.cs @@ -105,7 +105,11 @@ static void AddDictionaryValue(ref Dictionary dictionary, } else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { - dictionary[propertyName] = new DateTimeOffset((DateTime)propertyValue); + DateTime dateTimePropertyValue = (DateTime)propertyValue; + DateTimeOffset dateTimeOffset = dateTimePropertyValue.ToUniversalTime() <= DateTimeOffset.MinValue.UtcDateTime + ? DateTimeOffset.MinValue + : new DateTimeOffset(dateTimePropertyValue); + dictionary[propertyName] = dateTimeOffset; } else if (!propertyType.IsSimple() && !propertyType.IsEnum && propertyType.IsClass && propertyValue != null) {