Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnet/corefx
Browse files Browse the repository at this point in the history
  • Loading branch information
luqun committed Jun 7, 2017
2 parents 381d9ba + 935a2bc commit e59e1f6
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 31 deletions.
2 changes: 1 addition & 1 deletion BuildToolsVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0-prerelease-01702-02
2.0.0-prerelease-01706-03
3 changes: 3 additions & 0 deletions dir.traversal.targets
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<Error Condition="'$(MSBuildLastTaskResult)'=='false'" />
</Target>

<!-- Dumpling.targets needs to install dumpling.py before running tests. -->
<Import Project="$(ToolsDir)Dumpling.targets" Condition="Exists('$(ToolsDir)Dumpling.targets') AND ('$(EnableDumpling)' == 'true' OR '$(EnableCloudTest)' == 'true')" />

<Target Name="GetFilesToPackage"
DependsOnTargets="FilterProjects"
Returns="@(FilesToPackage)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public virtual void OnDeserialization(Object sender)
{
if (_siInfo == null)
{
return; //Somebody had a dependency on this Dictionary and fixed us up before the ObjectManager got to it.
return; //Somebody had a dependency on this LinkedList and fixed us up before the ObjectManager got to it.
}

int realVersion = _siInfo.GetInt32(VersionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public DisplayFormatAttribute() { }
public string DataFormatString { get { throw null; } set { } }
public bool HtmlEncode { get { throw null; } set { } }
public string NullDisplayText { get { throw null; } set { } }
public Type NullDisplayTextResourceType { get { throw null; } set { } }
public string GetNullDisplayText() { throw null; }
}
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
public sealed partial class EditableAttribute : System.Attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace System.ComponentModel.DataAnnotations
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class DisplayFormatAttribute : Attribute
{
private readonly LocalizableString _nullDisplayText = new LocalizableString("NullDisplayText");

/// <summary>
/// Default constructor
/// </summary>
Expand All @@ -27,9 +29,29 @@ public DisplayFormatAttribute()
public string DataFormatString { get; set; }

/// <summary>
/// Gets or sets the string to display when the value is null
/// Gets or sets the string to display when the value is null, which may be a resource key string.
/// <para>
/// Consumers should use the <see cref="GetNullDisplayText" /> method to retrieve the UI display string.
/// </para>
/// </summary>
public string NullDisplayText { get; set; }
/// <remarks>
/// The property contains either the literal, non-localized string or the resource key
/// to be used in conjunction with <see cref="NullDisplayTextResourceType" /> to configure a localized
/// name for display.
/// <para>
/// The <see cref="GetNullDisplayText" /> method will return either the literal, non-localized
/// string or the localized string when <see cref="NullDisplayTextResourceType" /> has been specified.
/// </para>
/// </remarks>
/// <value>
/// The null dispay text is generally used as placeholder when the value is not specified.
/// A <c>null</c> or empty string is legal, and consumers must allow for that.
/// </value>
public string NullDisplayText
{
get { return _nullDisplayText.Value; }
set { _nullDisplayText.Value = value; }
}

/// <summary>
/// Gets or sets a value indicating whether empty strings should be set to null
Expand All @@ -45,5 +67,45 @@ public DisplayFormatAttribute()
/// Gets or sets a value indicating whether the field should be html encoded
/// </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>
public Type NullDisplayTextResourceType
{
get { return _nullDisplayText.ResourceType; }
set { _nullDisplayText.ResourceType = value; }
}

/// <summary>
/// Gets the UI display string for NullDisplayText.
/// <para>
/// This can be either a literal, non-localized string provided to <see cref="NullDisplayText" /> or the
/// localized string found when <see cref="NullDisplayTextResourceType" /> has been specified and <see cref="NullDisplayText" />
/// represents a resource key within that resource type.
/// </para>
/// </summary>
/// <returns>
/// When <see cref="NullDisplayTextResourceType" /> has not been specified, the value of
/// <see cref="NullDisplayText" /> will be returned.
/// <para>
/// When <see cref="NullDisplayTextResourceType" /> has been specified and <see cref="NullDisplayText" />
/// represents a resource key within that resource type, then the localized value will be returned.
/// </para>
/// <para>
/// When <see cref="NullDisplayText" /> and <see cref="NullDisplayTextResourceType" /> have not been set, returns <c>null</c>.
/// </para>
/// </returns>
/// <exception cref="InvalidOperationException">
/// After setting both the <see cref="NullDisplayTextResourceType" /> property and the <see cref="NullDisplayText" /> property,
/// but a public static property with a name matching the <see cref="NullDisplayText" /> value couldn't be found
/// on the <see cref="NullDisplayTextResourceType" />.
/// </exception>
public string GetNullDisplayText()
{
return _nullDisplayText.GetLocalizableValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
<Link>Common\System\AssertExtensions.cs</Link>
</Compile>
<Compile Include="DisplayFormatAttributeTest.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FuzzyTests
///
/// </summary>
[Fact]
[ActiveIssue(20744,TargetFrameworkMonikers.UapAot)]
public void Test_Write_Fuzzy()
{
using (var logger = new EventSource("EventSourceName"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static void CheckNoEventSourcesRunning(string message = "")
eventSource.Name != "System.Diagnostics.Eventing.FrameworkEventSource" &&
eventSource.Name != "System.Buffers.ArrayPoolEventSource" &&
eventSource.Name != "System.Threading.SynchronizationEventSource" &&
eventSource.Name != "System.Runtime.InteropServices.InteropEventProvider"
eventSource.Name != "System.Runtime.InteropServices.InteropEventProvider" &&
eventSource.Name != "System.Reflection.Runtime.Tracing"
)
{
eventSourceNames += eventSource.Name + " ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private struct PartB_UserInfo
/// </summary>
[Fact]
[ActiveIssue("dotnet/corefx #19455", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
public void Test_Write_T_EventListener()
{
using (var listener = new EventListenerListener())
Expand All @@ -54,6 +55,7 @@ public void Test_Write_T_EventListener()
/// </summary>
[Fact]
[ActiveIssue("dotnet/corefx #19455", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
public void Test_Write_T_EventListener_UseEvents()
{
Test_Write_T(new EventListenerListener(true));
Expand Down Expand Up @@ -410,6 +412,7 @@ private void Test_Write_T(Listener listener)
/// </summary>
[Fact]
[ActiveIssue("dotnet/corefx #18806", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
public void Test_Write_T_In_Manifest_Serialization()
{
using (var eventListener = new EventListenerListener())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace System.IO.MemoryMappedFiles.Tests
public class CrossProcessTests : RemoteExecutorTestBase
{
[Fact]
[ActiveIssue(19909, TargetFrameworkMonikers.Uap)] // Remote executor in Uap and Process.Start() in UapAot
public void DataShared()
{
// Create a new file and load it into an MMF
Expand Down
Loading

0 comments on commit e59e1f6

Please sign in to comment.