-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add extension to simplify timespan
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/MyNet.Utilities.UnitTests/Extensions/TimeSpanExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Stéphane ANDRE. All Right Reserved. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using MyNet.Utilities.Units; | ||
using Xunit; | ||
|
||
namespace MyNet.Utilities.UnitTests.Extensions | ||
{ | ||
public class TimeSpanExtensionsTests | ||
{ | ||
[Theory] | ||
[InlineData(0, 0, 30, 30, TimeUnit.Minute)] | ||
[InlineData(0, 5, 0, 5, TimeUnit.Hour)] | ||
[InlineData(2, 0, 0, 2, TimeUnit.Day)] | ||
[InlineData(30, 0, 0, 1, TimeUnit.Month)] | ||
[InlineData(365, 0, 0, 1, TimeUnit.Year)] | ||
[InlineData(0, 0, 0, 0, TimeUnit.Millisecond)] | ||
[InlineData(14, 0, 0, 2, TimeUnit.Week)] | ||
[InlineData(60, 0, 0, 2, TimeUnit.Month)] | ||
[InlineData(730, 0, 0, 2, TimeUnit.Year)] | ||
[InlineData(22, 0, 0, 22, TimeUnit.Day)] | ||
[InlineData(0, 1, 23, 83, TimeUnit.Minute)] | ||
[InlineData(1, 0, 42, 1482, TimeUnit.Minute)] | ||
public void Simplify_ShouldReturnExpectedResult(int days, int hours, int minutes, int expectedValue, TimeUnit expectedUnit) | ||
{ | ||
var (value, unit) = new TimeSpan(days, hours, minutes, 0).Simplify(); | ||
|
||
Assert.Equal(expectedValue, value); | ||
Assert.Equal(expectedUnit, unit); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters