private static void AssertEqualComponents(Adjuster adjuster, TimeSpanComponent adjustedComponent, int adjustedValue) { var adjusted = adjuster(sample, adjustedValue); for (var component = TimeSpanComponent.Milliseconds; component <= TimeSpanComponent.Days; component++) { AssertEqualComponent(component); } void AssertEqualComponent(TimeSpanComponent testedComponent) { var adjustedTimeSpanComponent = adjusted.GetComponent(testedComponent); var expectedComponent = testedComponent == adjustedComponent ? adjustedValue : sample.GetComponent(testedComponent); Assert.AreEqual(expectedComponent, adjustedTimeSpanComponent); } }
/// <summary>Gets the specified component of the given <seealso cref="TimeSpan"/> instance.</summary> /// <param name="timeSpan">The <seealso cref="TimeSpan"/> instance whose component to get.</param> /// <param name="component">The component of the <seealso cref="TimeSpan"/> instance to get.</param> /// <returns>The requested component of the <seealso cref="TimeSpan"/> instance, represented by the specified <seealso cref="TimeSpanComponent"/>.</returns> public static long GetComponentInt64(this TimeSpan timeSpan, TimeSpanComponent component) => component switch {