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.Collections.Generic;
6 using Xunit;
7 
8 namespace System.ComponentModel.Tests
9 {
10     public class MergablePropertyAttributeTests
11     {
12         [Theory]
13         [InlineData(true)]
14         [InlineData(false)]
Ctor_AllowMerge(bool allowMerge)15         public void Ctor_AllowMerge(bool allowMerge)
16         {
17             var attribute = new MergablePropertyAttribute(allowMerge);
18             Assert.Equal(allowMerge, attribute.AllowMerge);
19             Assert.Equal(allowMerge, attribute.IsDefaultAttribute());
20         }
21 
Equals_TestData()22         public static IEnumerable<object[]> Equals_TestData()
23         {
24             yield return new object[] { MergablePropertyAttribute.Yes, MergablePropertyAttribute.Yes, true };
25             yield return new object[] { MergablePropertyAttribute.Yes, new MergablePropertyAttribute(true), true };
26             yield return new object[] { MergablePropertyAttribute.Yes, MergablePropertyAttribute.No, false };
27 
28             yield return new object[] { MergablePropertyAttribute.Yes, new object(), false };
29             yield return new object[] { MergablePropertyAttribute.Yes, null, false };
30         }
31 
32         [Theory]
33         [MemberData(nameof(Equals_TestData))]
Equals_Object_ReturnsExpected(MergablePropertyAttribute attribute, object other, bool expected)34         public void Equals_Object_ReturnsExpected(MergablePropertyAttribute attribute, object other, bool expected)
35         {
36             Assert.Equal(expected, attribute.Equals(other));
37             if (other is MergablePropertyAttribute)
38             {
39                 Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
40             }
41         }
42 
DefaultProperties_TestData()43         private static IEnumerable<object[]> DefaultProperties_TestData()
44         {
45             yield return new object[] { MergablePropertyAttribute.Yes, true };
46             yield return new object[] { MergablePropertyAttribute.Default, true };
47             yield return new object[] { MergablePropertyAttribute.No, false };
48         }
49 
50         [Theory]
51         [MemberData(nameof(DefaultProperties_TestData))]
DefaultProperties_GetAllowMerge_ReturnsExpected(MergablePropertyAttribute attribute, bool expectedAllowMerge)52         public void DefaultProperties_GetAllowMerge_ReturnsExpected(MergablePropertyAttribute attribute, bool expectedAllowMerge)
53         {
54             Assert.Equal(expectedAllowMerge, attribute.AllowMerge);
55             Assert.Equal(expectedAllowMerge, attribute.IsDefaultAttribute());
56         }
57     }
58 }
59