Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -26,10 +26,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU

View File

@@ -16,7 +16,7 @@
<FrameworkReference>System.ComponentModel.DataAnnotations</FrameworkReference>
</InboxOnTargetFramework>
<InboxOnTargetFramework Include="netcoreapp2.0" />
<InboxOnTargetFramework Include="uap10.1" />
<InboxOnTargetFramework Include="$(UAPvNextTFM)" />
<InboxOnTargetFramework Include="win8" />
<InboxOnTargetFramework Include="portable-net45+win8" />
<InboxOnTargetFramework Include="xamarinios10" />

View File

@@ -133,6 +133,9 @@
<data name="MinLengthAttribute_ValidationError" xml:space="preserve">
<value>The field {0} must be a string or array type with a minimum length of '{1}'.</value>
</data>
<data name="LengthAttribute_InvalidValueType" xml:space="preserve">
<value>The field of type {0} must be a string, array or ICollection type.</value>
</data>
<data name="PhoneAttribute_Invalid" xml:space="preserve">
<value>The {0} field is not a valid phone number.</value>
</data>

View File

@@ -25,10 +25,7 @@ namespace System.ComponentModel.DataAnnotations
public string OtherPropertyDisplayName { get; internal set; }
public override bool RequiresValidationContext
{
get { return true; }
}
public override bool RequiresValidationContext => true;
public override string FormatErrorMessage(string name)
{
@@ -56,27 +53,15 @@ namespace System.ComponentModel.DataAnnotations
{
if (OtherPropertyDisplayName == null)
{
OtherPropertyDisplayName = GetDisplayNameForProperty(validationContext.ObjectType, OtherProperty);
OtherPropertyDisplayName = GetDisplayNameForProperty(validationContext.ObjectType, otherPropertyInfo);
}
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
return null;
}
private static string GetDisplayNameForProperty(Type containerType, string propertyName)
private string GetDisplayNameForProperty(Type containerType, PropertyInfo property)
{
var property = containerType.GetRuntimeProperties()
.SingleOrDefault(
prop =>
IsPublic(prop) &&
string.Equals(propertyName, prop.Name, StringComparison.OrdinalIgnoreCase));
if (property == null)
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
SR.Common_PropertyNotFound, containerType.FullName, propertyName));
}
var attributes = CustomAttributeExtensions.GetCustomAttributes(property, true);
var display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
if (display != null)
@@ -84,7 +69,7 @@ namespace System.ComponentModel.DataAnnotations
return display.GetName();
}
return propertyName;
return OtherProperty;
}
private static bool IsPublic(PropertyInfo p)

View File

@@ -184,12 +184,7 @@ namespace System.ComponentModel.DataAnnotations
}
catch (TargetInvocationException tie)
{
if (tie.InnerException != null)
{
throw tie.InnerException;
}
throw;
throw tie.InnerException;
}
}

View File

@@ -68,11 +68,11 @@ namespace System.ComponentModel.DataAnnotations
/// </summary>
public bool HtmlEncode { get; set; }
/// <summary>
/// Gets or sets the <see cref="Type" /> that contains the resources for <see cref="NullDisplayText" />.
/// Using <see cref="NullDisplayTextResourceType" /> along with <see cref="NullDisplayText" />, allows the <see cref="GetNullDisplayText" />
/// method to return localized values.
/// </summary>
/// <summary>
/// Gets or sets the <see cref="Type" /> that contains the resources for <see cref="NullDisplayText" />.
/// Using <see cref="NullDisplayTextResourceType" /> along with <see cref="NullDisplayText" />, allows the <see cref="GetNullDisplayText" />
/// method to return localized values.
/// </summary>
public Type NullDisplayTextResourceType
{
get { return _nullDisplayText.ResourceType; }

View File

@@ -72,24 +72,19 @@ namespace System.ComponentModel.DataAnnotations
{
return true;
}
var str = value as string;
if (str != null)
if (value is string str)
{
length = str.Length;
}
else
{
ICollection collection = value as ICollection;
if (collection != null)
if (value is ICollection collection)
{
length = collection.Count;
}
else
{
// A cast exception previously occurred if a non-{string|array} property was passed
// in so preserve this behavior if the value does not implement ICollection
length = ((Array)value).Length;
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
}
}

View File

@@ -56,24 +56,19 @@ namespace System.ComponentModel.DataAnnotations
{
return true;
}
var str = value as string;
if (str != null)
if (value is string str)
{
length = str.Length;
}
else
{
ICollection collection = value as ICollection;
if (collection != null)
if (value is ICollection collection)
{
length = collection.Count;
}
else
{
// A cast exception previously occurred if a non-{string|array} property was passed
// in so preserve this behavior if the value does not implement ICollection
length = ((Array)value).Length;
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
}
}

View File

@@ -253,6 +253,7 @@ nameof(propertyName));
internal PropertyStoreItem(Type propertyType, IEnumerable<Attribute> attributes)
: base(attributes)
{
Debug.Assert(propertyType != null);
_propertyType = propertyType;
}

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
@@ -352,12 +353,9 @@ namespace System.ComponentModel.DataAnnotations
/// </param>
/// <returns>A new <see cref="ValidationContext" /> for the <paramref name="instance" /> provided.</returns>
/// <exception cref="ArgumentNullException">When <paramref name="validationContext" /> is null.</exception>
internal static ValidationContext CreateValidationContext(object instance, ValidationContext validationContext)
private static ValidationContext CreateValidationContext(object instance, ValidationContext validationContext)
{
if (validationContext == null)
{
throw new ArgumentNullException(nameof(validationContext));
}
Debug.Assert(validationContext != null);
// Create a new context using the existing ValidationContext that acts as an IServiceProvider and contains our existing items.
var context = new ValidationContext(instance, validationContext, validationContext.Items);
@@ -376,11 +374,6 @@ namespace System.ComponentModel.DataAnnotations
/// <exception cref="ArgumentNullException">When <paramref name="destinationType" /> is null.</exception>
private static bool CanBeAssigned(Type destinationType, object value)
{
if (destinationType == null)
{
throw new ArgumentNullException(nameof(destinationType));
}
if (value == null)
{
// Null can be assigned only to reference types or Nullable or Nullable<>
@@ -431,10 +424,7 @@ nameof(value));
private static IEnumerable<ValidationError> GetObjectValidationErrors(object instance,
ValidationContext validationContext, bool validateAllProperties, bool breakOnFirstError)
{
if (instance == null)
{
throw new ArgumentNullException(nameof(instance));
}
Debug.Assert(instance != null);
if (validationContext == null)
{
@@ -633,10 +623,7 @@ nameof(value));
private static bool TryValidate(object value, ValidationContext validationContext, ValidationAttribute attribute,
out ValidationError validationError)
{
if (validationContext == null)
{
throw new ArgumentNullException(nameof(validationContext));
}
Debug.Assert(validationContext != null);
var validationResult = attribute.GetValidationResult(value, validationContext);
if (validationResult != ValidationResult.Success)
@@ -669,10 +656,7 @@ nameof(value));
internal ValidationResult ValidationResult { get; set; }
internal void ThrowValidationException()
{
throw new ValidationException(ValidationResult, ValidationAttribute, Value);
}
internal Exception ThrowValidationException() => throw new ValidationException(ValidationResult, ValidationAttribute, Value);
}
}
}

View File

@@ -55,14 +55,30 @@ namespace System.ComponentModel.DataAnnotations.Tests
public static void Validate_Indexer_ThrowsArgumentException_Netcoreapp()
{
CompareAttribute attribute = new CompareAttribute("Item");
Assert.Throws<ArgumentException>(null, () => attribute.Validate("b", s_context));
AssertExtensions.Throws<ArgumentException>(null, () => attribute.Validate("b", s_context));
}
[Fact]
public static void Validate_SetOnlyProperty_ThrowsArgumentException()
{
CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.SetOnlyProperty));
Assert.Throws<ArgumentException>(null, () => attribute.Validate("b", s_context));
AssertExtensions.Throws<ArgumentException>(null, () => attribute.Validate("b", s_context));
}
[Fact]
public static void Validate_LowerAndUpperPropertyName_Success()
{
CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.comparepropertycased));
Assert.NotNull(attribute.GetValidationResult("b", s_context).ErrorMessage);
Assert.Equal(ValidationResult.Success, attribute.GetValidationResult(null, s_context));
Assert.Equal(nameof(CompareObject.comparepropertycased), attribute.OtherPropertyDisplayName);
}
[Fact]
public static void Validate_PrivateProperty_ThrowsArgumentException()
{
CompareAttribute attribute = new CompareAttribute("PrivateProperty");
Assert.Throws<ValidationException>(() => attribute.Validate("b", s_context));
}
[Fact]
@@ -96,6 +112,10 @@ namespace System.ComponentModel.DataAnnotations.Tests
public string this[int index] { get { return "abc"; } set { } }
public string SetOnlyProperty { set { } }
private string PrivateProperty { get; set; }
public string ComparePropertyCased { get; set; }
public string comparepropertycased { get; set; }
public CompareObject(string otherValue)
{

View File

@@ -3,6 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netstandard;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -69,6 +69,26 @@ namespace System.ComponentModel.DataAnnotations.Tests
Assert.Equal(method, attribute.Method);
}
[Fact]
public void FormatErrorMessage_NotPerformedValidation_ContainsName()
{
CustomValidationAttribute attribute = GetAttribute(nameof(CustomValidator.CorrectValidationMethodOneArg));
string errorMessage = attribute.FormatErrorMessage("name");
Assert.Contains("name", errorMessage);
Assert.Equal(errorMessage, attribute.FormatErrorMessage("name"));
}
[Fact]
public void FormatErrorMessage_PerformedValidation_DoesNotContainName()
{
CustomValidationAttribute attribute = GetAttribute(nameof(CustomValidator.CorrectValidationMethodOneArg));
Assert.False(attribute.IsValid(new TestClass("AnyString")));
string errorMessage = attribute.FormatErrorMessage("name");
Assert.DoesNotContain("name", errorMessage);
Assert.Equal(errorMessage, attribute.FormatErrorMessage("name"));
}
[Theory]
[InlineData(nameof(CustomValidator.CorrectValidationMethodOneArg), false)]
[InlineData(nameof(CustomValidator.CorrectValidationMethodOneArgStronglyTyped), false)]
@@ -150,7 +170,7 @@ namespace System.ComponentModel.DataAnnotations.Tests
public static void Validate_MethodThrowsCustomException_IsNotCaught()
{
CustomValidationAttribute attribute = GetAttribute(nameof(CustomValidator.ValidationMethodThrowsException));
Assert.Throws<ArgumentException>(() => attribute.Validate(new IConvertibleImplementor(), s_testValidationContext));
AssertExtensions.Throws<ArgumentException>(null, () => attribute.Validate(new IConvertibleImplementor(), s_testValidationContext));
}
internal class NonPublicCustomValidator

View File

@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
{
public class DisplayColumnAttributeTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("DisplayColumn")]
public void Ctor_DisplayColumn(string displayColumn)
{
var attribute = new DisplayColumnAttribute(displayColumn);
Assert.Equal(displayColumn, attribute.DisplayColumn);
Assert.Null(attribute.SortColumn);
Assert.False(attribute.SortDescending);
}
[Theory]
[InlineData(null, null)]
[InlineData("", "")]
[InlineData("DisplayColumn", "SortColumn")]
public void Ctor_DisplayColumn_SortColumn(string displayColumn, string sortColumn)
{
var attribute = new DisplayColumnAttribute(displayColumn, sortColumn);
Assert.Equal(displayColumn, attribute.DisplayColumn);
Assert.Equal(sortColumn, attribute.SortColumn);
Assert.False(attribute.SortDescending);
}
[Theory]
[InlineData(null, null, false)]
[InlineData("", "", false)]
[InlineData("DisplayColumn", "SortColumn", true)]
public void Ctor_DisplayColumn_SortColumn_SortDescending(string displayColumn, string sortColumn, bool sortDescending)
{
var attribute = new DisplayColumnAttribute(displayColumn, sortColumn, sortDescending);
Assert.Equal(displayColumn, attribute.DisplayColumn);
Assert.Equal(sortColumn, attribute.SortColumn);
Assert.Equal(sortDescending, attribute.SortDescending);
}
}
}

View File

@@ -1,154 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
{
public class DisplayFormatAttributeTest
{
[Fact]
public void Ctor()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
Assert.True(attribute.ConvertEmptyStringToNull);
Assert.True(attribute.HtmlEncode);
Assert.False(attribute.ApplyFormatInEditMode);
Assert.Null(attribute.DataFormatString);
Assert.Null(attribute.NullDisplayText);
#if netcoreapp
Assert.Null(attribute.NullDisplayTextResourceType);
#endif
}
[Theory]
[InlineData("{0:C}")]
[InlineData("{0:d}")]
public void DataFormatString_Get_Set(string input)
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.DataFormatString = input;
Assert.Equal(input, attribute.DataFormatString);
}
[Fact]
public void ConvertEmptyStringToNull_Get_Set()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.ConvertEmptyStringToNull = false;
Assert.False(attribute.ConvertEmptyStringToNull);
}
[Fact]
public void ApplyFormatInEditMode_Get_Set()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.ApplyFormatInEditMode = true;
Assert.True(attribute.ApplyFormatInEditMode);
}
[Fact]
public void HtmlEncode_Get_Set()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.HtmlEncode = false;
Assert.False(attribute.HtmlEncode);
}
public static IEnumerable<object[]> Strings_TestData()
{
yield return new object[] { "" };
yield return new object[] { " \r \t \n " };
yield return new object[] { "abc" };
yield return new object[] { "NullDisplayText" };
}
[Theory]
[MemberData(nameof(Strings_TestData))]
public void NullDisplayText_Get_Set(string input)
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.NullDisplayText = input;
Assert.Equal(input, attribute.NullDisplayText);
#if netcoreapp
Assert.NotNull(attribute.GetNullDisplayText());
#endif
// Set again, to cover the setter avoiding operations if the value is the same
attribute.NullDisplayText = input;
Assert.Equal(input, attribute.NullDisplayText);
}
#if netcoreapp
public class FakeResourceType
{
public static string Resource1
{
get { return "Resource1Text"; }
}
public static string Resource2
{
get { return "Resource2Text"; }
}
}
[Fact]
public void NullDisplayTextResourceType_Get_Set()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.NullDisplayTextResourceType = typeof(FakeResourceType);
Assert.Equal(typeof(FakeResourceType), attribute.NullDisplayTextResourceType);
}
[Fact]
public void NullDisplayText_WithResource()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.NullDisplayTextResourceType = typeof(FakeResourceType);
attribute.NullDisplayText = "Resource1";
Assert.Equal(FakeResourceType.Resource1, attribute.GetNullDisplayText());
// Changing target resource
attribute.NullDisplayText = "Resource2";
Assert.Equal(FakeResourceType.Resource2, attribute.GetNullDisplayText());
// Not existing resource in the resource type
attribute.NullDisplayText = "Resource3";
Assert.Throws<InvalidOperationException>(() => attribute.GetNullDisplayText());
}
[Fact]
public void NullDisplayText_NotAResourceType()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
// Setting a type that is not a resource type
attribute.NullDisplayTextResourceType = typeof(string);
attribute.NullDisplayText = "foo";
Assert.Throws<InvalidOperationException>(() => attribute.GetNullDisplayText());
}
[Theory]
[InlineData(null)]
[InlineData(typeof(FakeResourceType))]
public void GetNullDisplayText_WhenNullDisplayTextNotSet(Type input)
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute();
attribute.NullDisplayTextResourceType = input;
Assert.Null(attribute.GetNullDisplayText());
}
#endif
}
}

View File

@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
{
public partial class DisplayFormatAttributeTests
{
[Fact]
public void Ctor_Default()
{
var attribute = new DisplayFormatAttribute();
Assert.True(attribute.ConvertEmptyStringToNull);
Assert.True(attribute.HtmlEncode);
Assert.False(attribute.ApplyFormatInEditMode);
Assert.Null(attribute.DataFormatString);
Assert.Null(attribute.NullDisplayText);
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("{0:C}")]
[InlineData("{0:d}")]
public void DataFormatString_Set_GetReturnsExpected(string input)
{
var attribute = new DisplayFormatAttribute { DataFormatString = input };
Assert.Equal(input, attribute.DataFormatString);
}
[Fact]
public void ConvertEmptyStringToNull_Set_GetReturnsExpected()
{
var attribute = new DisplayFormatAttribute { ConvertEmptyStringToNull = false };
Assert.False(attribute.ConvertEmptyStringToNull);
}
[Fact]
public void ApplyFormatInEditMode_Set_GetReturnsExpected()
{
var attribute = new DisplayFormatAttribute { ApplyFormatInEditMode = true };
Assert.True(attribute.ApplyFormatInEditMode);
}
[Fact]
public void HtmlEncode_Set_GetReturnsExpected()
{
DisplayFormatAttribute attribute = new DisplayFormatAttribute { HtmlEncode = false };
Assert.False(attribute.HtmlEncode);
}
public static IEnumerable<object[]> NullDisplayText_TestData()
{
yield return new object[] { "" };
yield return new object[] { " \r \t \n " };
yield return new object[] { "abc" };
yield return new object[] { "NullDisplayText" };
}
[Theory]
[MemberData(nameof(NullDisplayText_TestData))]
public void NullDisplayText_Get_Set(string input)
{
var attribute = new DisplayFormatAttribute { NullDisplayText = input };
Assert.Equal(input, attribute.NullDisplayText);
// Set again, to cover the setter avoiding operations if the value is the same
attribute.NullDisplayText = input;
Assert.Equal(input, attribute.NullDisplayText);
}
}
}

View File

@@ -0,0 +1,82 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
{
public partial class DisplayFormatAttributeTests
{
[Fact]
public void NullDisplayTextResourceType_GetDefault_ReturnsNull()
{
var attribute = new DisplayFormatAttribute();
Assert.Null(attribute.NullDisplayTextResourceType);
}
[Theory]
[MemberData(nameof(NullDisplayText_TestData))]
public void NullDisplayText_Set_GetReturnsExpected(string input)
{
var attribute = new DisplayFormatAttribute { NullDisplayText = input };
Assert.Equal(input, attribute.GetNullDisplayText());
// Set again, to cover the setter avoiding operations if the value is the same
attribute.NullDisplayText = input;
Assert.Equal(input, attribute.NullDisplayText);
}
[Fact]
public void NullDisplayTextResourceType_Set_GetReturnsExpected()
{
var attribute = new DisplayFormatAttribute { NullDisplayTextResourceType = typeof(FakeResourceType) };
Assert.Equal(typeof(FakeResourceType), attribute.NullDisplayTextResourceType);
}
[Fact]
public void GetNullDisplayText_ValidResource_ReturnsExpected()
{
var attribute = new DisplayFormatAttribute { NullDisplayTextResourceType = typeof(FakeResourceType) };
attribute.NullDisplayText = "Resource1";
Assert.Equal(FakeResourceType.Resource1, attribute.GetNullDisplayText());
// Changing target resource
attribute.NullDisplayText = "Resource2";
Assert.Equal(FakeResourceType.Resource2, attribute.GetNullDisplayText());
}
[Theory]
[InlineData(typeof(FakeResourceType), "Resource3")]
[InlineData(typeof(FakeResourceType), nameof(FakeResourceType.InstanceProperty))]
[InlineData(typeof(FakeResourceType), nameof(FakeResourceType.SetOnlyProperty))]
[InlineData(typeof(FakeResourceType), "NonPublicGetProperty")]
[InlineData(typeof(string), "foo")]
public void GetNullDisplayText_InvalidResourceType_ThrowsInvalidOperationException(Type nullDisplayTextResourceType, string nullDisplayText)
{
var attribute = new DisplayFormatAttribute { NullDisplayTextResourceType = nullDisplayTextResourceType };
attribute.NullDisplayText = nullDisplayText;
Assert.Throws<InvalidOperationException>(() => attribute.GetNullDisplayText());
}
[Theory]
[InlineData(null)]
[InlineData(typeof(FakeResourceType))]
public void GetNullDisplayText_NullDisplayText_ReturnsNull(Type input)
{
var attribute = new DisplayFormatAttribute { NullDisplayTextResourceType = input };
Assert.Null(attribute.GetNullDisplayText());
}
public class FakeResourceType
{
public static string Resource1 => "Resource1Text";
public static string Resource2 => "Resource2Text";
public string InstanceProperty => "InstanceProperty";
public static string SetOnlyProperty { set => Assert.NotNull(value); }
private static string NonPublicGetProperty => "NonPublicGetProperty";
}
}
}

View File

@@ -86,7 +86,7 @@ namespace System.ComponentModel.DataAnnotations.Tests
public static void Validate_InvalidPattern_ThrowsArgumentException()
{
RegularExpressionAttribute attribute = new RegularExpressionAttribute("foo(?<1bar)");
Assert.Throws<ArgumentException>(null, () => attribute.Validate("Any", new ValidationContext(new object())));
AssertExtensions.Throws<ArgumentException>(null, () => attribute.Validate("Any", new ValidationContext(new object())));
}
public class ClassWithValidToString

View File

@@ -34,7 +34,7 @@ namespace System.ComponentModel.DataAnnotations.Schema.Tests
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceName_ThrowsArgumentException(string name)
{
Assert.Throws<ArgumentException>(null, () => new ColumnAttribute(name));
AssertExtensions.Throws<ArgumentException>(null, () => new ColumnAttribute(name));
}
[Theory]
@@ -68,7 +68,7 @@ namespace System.ComponentModel.DataAnnotations.Schema.Tests
public static void TypeName_Set_NullOrWhitespaceValue_ThrowsArgumentException(string value)
{
ColumnAttribute attribute = new ColumnAttribute();
Assert.Throws<ArgumentException>(null, () => attribute.TypeName = value);
AssertExtensions.Throws<ArgumentException>(null, () => attribute.TypeName = value);
}
}
}

View File

@@ -22,7 +22,7 @@ namespace System.ComponentModel.DataAnnotations.Schema.Tests
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceName_ThrowsArgumentException(string name)
{
Assert.Throws<ArgumentException>(null, () => new ForeignKeyAttribute(name));
AssertExtensions.Throws<ArgumentException>(null, () => new ForeignKeyAttribute(name));
}
}
}

Some files were not shown because too many files have changed in this diff Show More