Skip to content

Commit

Permalink
Fix value parsing for DateTime and double
Browse files Browse the repository at this point in the history
  • Loading branch information
ttu committed Jan 30, 2019
1 parent eec82dc commit 4007fa9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion FakeServer.Test/ObjectHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ObjectHelper.GetValueAsCorrectType("2"));
Expand Down
5 changes: 3 additions & 2 deletions FakeServer/Common/ObjectHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Linq;

namespace FakeServer.Common
Expand Down Expand Up @@ -116,8 +117,8 @@ private static dynamic ParseFields(ExpandoObject s, IEnumerable<string> 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)
};

/// <summary>
Expand Down

0 comments on commit 4007fa9

Please sign in to comment.