Skip to content

Commit

Permalink
added tryparse to default an invalid weight to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
jensandresen committed Sep 20, 2014
1 parent 856821f commit 8f5d044
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Jump.Location.Specs/FileStoreProviderSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public void It_can_Revive_multiple_records_of_correctly_formatted_text()
db.Records.Count().ShouldEqual(3);
}

[Fact]
public void It_can_Revive_a_record_with_invalid_weight()
{
var lines = new[] {"INVALID_WEIGHT\tFS::C:\\blah"};
File.WriteAllLines(path, lines);
var provider = new FileStoreProvider(path);

var db = provider.Revive();
db.Records.Count().ShouldEqual(1);
db.Records.First().Weight.ShouldEqual(0M);
db.Records.First().Path.ShouldEqual("C:\\blah");
}

[Fact]
public void It_skips_blank_and_empty_lines()
{
Expand Down
3 changes: 2 additions & 1 deletion Jump.Location/FileStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public IDatabase Revive()
if (columns == null || columns.Length != 2)
throw new InvalidOperationException("Row of file didn't have 2 columns separated by a tab");

var weight = decimal.Parse(columns[0], CultureInfo.InvariantCulture);
var weight = 0M;
decimal.TryParse(columns[0], NumberStyles.Any, CultureInfo.InvariantCulture, out weight);
var record = new Record(columns[1], weight);
db.Add(record);
}
Expand Down

0 comments on commit 8f5d044

Please sign in to comment.