Skip to content

Commit

Permalink
Add test to prove proper support for TimeSpan in AppSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
tsimbalar committed Sep 22, 2017
1 parent 47e72dc commit 5569b1c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/Serilog.Tests/Settings/SettingValueConversionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Serilog.Events;
using System;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Json;
using Serilog.Settings.KeyValuePairs;
Expand Down Expand Up @@ -49,5 +50,21 @@ public void StringValuesConvertToDefaultInstancesIfTargetIsInterface()
var result = SettingValueConversions.ConvertToType("Serilog.Formatting.Json.JsonFormatter", typeof(ITextFormatter));
Assert.IsType<JsonFormatter>(result);
}

[Theory]
[InlineData("3.14:21:18.986", 3 /*days*/, 14 /*hours*/, 21 /*min*/, 18 /*sec*/, 986 /*ms*/)]
[InlineData("4", 4, 0, 0, 0, 0)] // minimal : days
[InlineData("2:0", 0, 2, 0, 0, 0)] // minimal hours
[InlineData("0:5", 0, 0, 5, 0, 0)] // minimal minutes
[InlineData("0:0:7", 0, 0, 0, 7, 0)] // minimal seconds
[InlineData("0:0:0.2", 0, 0, 0, 0, 200)] // minimal milliseconds
public void TimeSpanValuesCanBeParsed(string input, int expDays, int expHours, int expMin, int expSec, int expMs)
{
var expectedTimeSpan = new TimeSpan(expDays, expHours, expMin, expSec, expMs);
var actual = SettingValueConversions.ConvertToType(input, typeof(TimeSpan));

Assert.IsType<TimeSpan>(actual);
Assert.Equal(expectedTimeSpan, actual);
}
}
}

0 comments on commit 5569b1c

Please sign in to comment.