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.Globalization; 7 using System.ComponentModel; 8 using System.ComponentModel.Design.Serialization; 9 using Xunit; 10 11 namespace System.Security.Authentication.ExtendedProtection.Tests 12 { 13 public class ExtendedProtectionPolicyTypeConverterTests 14 { 15 [Theory] 16 [InlineData(typeof(int))] 17 [InlineData(typeof(ExtendedProtectionPolicy))] 18 [InlineData(typeof(bool))] 19 [InlineData(null)] 20 [InlineData(typeof(float))] 21 [InlineData(typeof(TypeConverter))] CanConvertTo_NegativeTests(Type destinationType)22 public void CanConvertTo_NegativeTests(Type destinationType) 23 { 24 Assert.False(converter.CanConvertTo(null, destinationType)); 25 } 26 27 [Fact] CanConvertTo_PositiveTests()28 public void CanConvertTo_PositiveTests() 29 { 30 Assert.True(converter.CanConvertTo(null, typeof(string))); 31 Assert.True(converter.CanConvertTo(null, typeof(InstanceDescriptor))); 32 } 33 34 [Fact] ConvertTo_NullTypeTests()35 public void ConvertTo_NullTypeTests() 36 { 37 Assert.Throws<ArgumentNullException>(() => converter.ConvertTo(null, CultureInfo.InvariantCulture, new ExtendedProtectionPolicy(PolicyEnforcement.Never), null)); 38 } 39 40 [Fact] ConvertTo_PositiveTests()41 public void ConvertTo_PositiveTests() 42 { 43 ExtendedProtectionPolicy policy = new ExtendedProtectionPolicy(PolicyEnforcement.Never); 44 45 InstanceDescriptor instanceDescriptor = converter.ConvertTo(null, CultureInfo.InvariantCulture, policy, typeof(InstanceDescriptor)) as InstanceDescriptor; 46 ExtendedProtectionPolicy instanceResult = instanceDescriptor.Invoke() as ExtendedProtectionPolicy; 47 Assert.NotNull(instanceDescriptor); 48 Assert.NotNull(instanceResult); 49 Assert.Equal(PolicyEnforcement.Never, instanceResult.PolicyEnforcement); 50 Assert.Equal(policy.ProtectionScenario, instanceResult.ProtectionScenario); 51 Assert.Null(instanceResult.CustomServiceNames); 52 53 Assert.Equal(string.Empty, 54 converter.ConvertTo(null, CultureInfo.InvariantCulture, null, typeof(string)) as string); 55 Assert.Equal(policy.ToString(), 56 converter.ConvertTo(null, CultureInfo.InvariantCulture, policy, typeof(string)) as string); 57 } 58 59 [Theory] 60 [InlineData(typeof(int))] 61 [InlineData(typeof(ExtendedProtectionPolicy))] 62 [InlineData(typeof(bool))] 63 [InlineData(typeof(float))] 64 [InlineData(typeof(TypeConverter))] ConvertTo_NegativeTests(Type destinationType)65 public void ConvertTo_NegativeTests(Type destinationType) 66 { 67 ExtendedProtectionPolicy policy = new ExtendedProtectionPolicy(PolicyEnforcement.Never); 68 69 Assert.Throws<NotSupportedException>(() => converter.ConvertTo(null, CultureInfo.InvariantCulture, policy, destinationType)); 70 } 71 72 private ExtendedProtectionPolicyTypeConverter converter = new ExtendedProtectionPolicyTypeConverter(); 73 } 74 } 75