From 5569b1c3b8893e87d13bfff9ae355cb16b21d845 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Fri, 22 Sep 2017 17:13:13 +0200 Subject: [PATCH] Add test to prove proper support for TimeSpan in AppSettings --- .../Settings/SettingValueConversionsTests.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs b/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs index 3ee1bc118..9dacbe050 100644 --- a/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs +++ b/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs @@ -1,4 +1,5 @@ -using Serilog.Events; +using System; +using Serilog.Events; using Serilog.Formatting; using Serilog.Formatting.Json; using Serilog.Settings.KeyValuePairs; @@ -49,5 +50,21 @@ public void StringValuesConvertToDefaultInstancesIfTargetIsInterface() var result = SettingValueConversions.ConvertToType("Serilog.Formatting.Json.JsonFormatter", typeof(ITextFormatter)); Assert.IsType(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(actual); + Assert.Equal(expectedTimeSpan, actual); + } } }