1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System;
6 using System.Collections.Generic;
7 using Xunit;
8 
9 namespace Windows.UI.Xaml.Media.Animation.Tests
10 {
11     public class KeyTimeTests
12     {
13         [Fact]
Ctor_Default()14         public void Ctor_Default()
15         {
16             var keyTime = new KeyTime();
17             Assert.Equal(TimeSpan.Zero, keyTime.TimeSpan);
18         }
19 
20         [Theory]
21         [InlineData(0)]
22         [InlineData(1)]
FromTimeSpan_ValidTimeSpan_ReturnsExpected(int seconds)23         public void FromTimeSpan_ValidTimeSpan_ReturnsExpected(int seconds)
24         {
25             KeyTime keyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds));
26             Assert.Equal(TimeSpan.FromSeconds(seconds), keyTime.TimeSpan);
27         }
28 
29         [Fact]
FromTimeSpan_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()30         public void FromTimeSpan_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()
31         {
32             AssertExtensions.Throws<ArgumentOutOfRangeException>("timeSpan", () => KeyTime.FromTimeSpan(TimeSpan.FromTicks(-1)));
33         }
34 
35         [Fact]
Operator_ValidTimeSpan_ReturnsExpected()36         public void Operator_ValidTimeSpan_ReturnsExpected()
37         {
38             KeyTime keyTime = TimeSpan.FromSeconds(2);
39             Assert.Equal(TimeSpan.FromSeconds(2), keyTime);
40         }
41 
42         [Fact]
Operator_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()43         public void Operator_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()
44         {
45             TimeSpan timeSpan = TimeSpan.FromTicks(-1);
46             AssertExtensions.Throws<ArgumentOutOfRangeException>("timeSpan", () => (KeyTime)timeSpan);
47         }
48 
Equals_TestData()49         public static IEnumerable<object[]> Equals_TestData()
50         {
51             yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), true };
52             yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), false };
53 
54             yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), new object(), false };
55             yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), null, false };
56         }
57 
58         [Theory]
59         [MemberData(nameof(Equals_TestData))]
Equals_Object_ReturnsExpected(KeyTime keyTime, object other, bool expected)60         public void Equals_Object_ReturnsExpected(KeyTime keyTime, object other, bool expected)
61         {
62             Assert.Equal(expected, keyTime.Equals(other));
63             if (other is KeyTime otherKeyTime)
64             {
65                 Assert.Equal(expected, keyTime.Equals(otherKeyTime));
66                 Assert.Equal(expected, keyTime == otherKeyTime);
67                 Assert.Equal(!expected, keyTime != otherKeyTime);
68                 Assert.Equal(expected, keyTime.GetHashCode().Equals(otherKeyTime.GetHashCode()));
69             }
70         }
71 
ToString_TestData()72         public static IEnumerable<object[]> ToString_TestData()
73         {
74             yield return new object[] { new KeyTime(), TimeSpan.Zero.ToString() };
75             yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), TimeSpan.FromSeconds(2).ToString() };
76         }
77 
78         [Theory]
79         [MemberData(nameof(ToString_TestData))]
ToString_Invoke_ReturnsExpected(KeyTime keyTime, string expected)80         public void ToString_Invoke_ReturnsExpected(KeyTime keyTime, string expected)
81         {
82             Assert.Equal(expected, keyTime.ToString());
83         }
84     }
85 }