diff --git a/CHANGELOG.md b/CHANGELOG.md index b64eeca..7fc8426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * ADDED: User defined location for the static files (including SPAs) * ADDED: Console parameter for help and version * FIXED: Adding to the empty collection will use the value of the id-field if it is set +* FIXED: Value parsing for DateTime and double to culture invariant ### [0.8.0] - 2018-10-14 * Release as a dotnet tool diff --git a/FakeServer.Test/ObjectHelperTests.cs b/FakeServer.Test/ObjectHelperTests.cs index bc2c21e..ad2605d 100644 --- a/FakeServer.Test/ObjectHelperTests.cs +++ b/FakeServer.Test/ObjectHelperTests.cs @@ -44,7 +44,7 @@ public void WebSocketMessage() Assert.Equal("POST", msg.Method.Value); } - [Fact(Skip = "DateTime parsing fails when current culture is not en-US")] + [Fact] public void GetValueAsCorrectType() { Assert.IsType(ObjectHelper.GetValueAsCorrectType("2")); diff --git a/FakeServer/Common/ObjectHelper.cs b/FakeServer/Common/ObjectHelper.cs index c21f552..eb7ae82 100644 --- a/FakeServer/Common/ObjectHelper.cs +++ b/FakeServer/Common/ObjectHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Dynamic; +using System.Globalization; using System.Linq; namespace FakeServer.Common @@ -116,8 +117,8 @@ private static dynamic ParseFields(ExpandoObject s, IEnumerable fields) { x => Convert.ToBoolean(x), x => Convert.ToInt32(x), - x => Convert.ToDouble(x), - x => Convert.ToDateTime(x) + x => double.TryParse(x, NumberStyles.Any, CultureInfo.InvariantCulture, out var result) ? result : throw new Exception(), + x => DateTime.Parse(x, CultureInfo.InvariantCulture) }; ///