Skip to content

Commit

Permalink
Update to Preview7 SDK (#106333)
Browse files Browse the repository at this point in the history
* Update to Preview7 SDK

* Enable use of DefaultValueAttribute in trimming test

* Fix the _DefaultValueAttributeSupport in generated trimming tests

* Make DefaultValueAttributeCtorTest trimming test enable _DefaultValueAttributeSupport

* Condition some DefaultValueAttributeTests on DefaultValueAttribute.IsSupported switch

* Fix AmbientValueAttribute when IDesignerHost.IsSupported is false

Throw only when type constructor is used. Fix tests to condition on this.

* Condition some XmlSerializer tests

These tests serialize types that use DefaultValueAttribute which is
disabled.

* Update to final Preview7 versions

* Fix ToolboxItemAttributeTests when IDesignerHost.IsSupported is false
  • Loading branch information
ericstj authored Aug 14, 2024
1 parent 7963a49 commit 605ff6f
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 18 deletions.
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"sdk": {
"version": "9.0.100-preview.6.24328.19",
"version": "9.0.100-preview.7.24407.12",
"allowPrerelease": true,
"rollForward": "major"
},
"tools": {
"dotnet": "9.0.100-preview.6.24328.19"
"dotnet": "9.0.100-preview.7.24407.12"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24408.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed class AmbientValueAttribute : Attribute
/// This is the default value.
/// </summary>
private object? _value;
private static readonly object? s_throwSentinel = IDesignerHost.IsSupported ? null : new();

/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.AmbientValueAttribute'/> class, converting the
Expand All @@ -32,6 +33,7 @@ public AmbientValueAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemb
Debug.Assert(IDesignerHost.IsSupported, "Runtime instantiation of this attribute is not allowed with trimming.");
if (!IDesignerHost.IsSupported)
{
_value = s_throwSentinel;
return;
}

Expand Down Expand Up @@ -142,7 +144,7 @@ public AmbientValueAttribute(object? value)
public object? Value {
get
{
if (!IDesignerHost.IsSupported)
if (!IDesignerHost.IsSupported && ReferenceEquals(_value, s_throwSentinel))
{
throw new ArgumentException(SR.RuntimeInstanceNotAllowed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace System.ComponentModel.Tests
{
public class AmbientValueAttributeTests
{
[Theory]
public static bool IDesignerHostIsSupported => AppContext.TryGetSwitch("System.ComponentModel.Design.IDesignerHost.IsSupported", out bool isSupported) ? isSupported : true;

[ConditionalTheory(nameof(IDesignerHostIsSupported))]
[InlineData(null, null, null)]
[InlineData(typeof(int*), "1", null)]
[InlineData(typeof(string), "1", "1")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ namespace System.ComponentModel
{
public class ToolboxItemAttributeTests
{
internal static bool IDesignerHostIsSupported => AppContext.TryGetSwitch("System.ComponentModel.Design.IDesignerHost.IsSupported", out bool isSupported) ? isSupported : true;

[Theory]
[InlineData(true)]
[InlineData(false)]
public void Ctor_Bool(bool defaultType)
{
if (!IDesignerHostIsSupported && defaultType)
{
AssertExtensions.Throws<NotSupportedException>(() => new ToolboxItemAttribute(defaultType));
return;
}

var attribute = new ToolboxItemAttribute(defaultType);
if (defaultType)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<Project DefaultTargets="Build">
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />

<ItemGroup>
<TestConsoleAppSourceFiles Include="TypeConverterAttributeStringArgCtorTest.cs">
<EnabledProperties>_DefaultValueAttributeSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="TypeConverterAttributeTypeArgCtorTest.cs">
<EnabledProperties>_DefaultValueAttributeSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="TypeDescriptionProviderAttributeCtorTest.cs" />
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static XmlSerializerTests()
}
#endif

public static bool DefaultValueAttributeIsSupported => AppContext.TryGetSwitch("System.ComponentModel.DefaultValueAttribute.IsSupported", out bool isEnabled) ? isEnabled : true;

[Fact]
public static void Xml_TypeWithDateTimePropertyAsXmlTime()
{
Expand Down Expand Up @@ -823,7 +825,7 @@ public static void Xml_TypeWithTimeSpanProperty()
Assert.StrictEqual(obj.TimeSpanProperty, deserializedObj.TimeSpanProperty);
}

[Fact]
[ConditionalFact(nameof(DefaultValueAttributeIsSupported))]
public static void Xml_TypeWithDefaultTimeSpanProperty()
{
var obj = new TypeWithDefaultTimeSpanProperty { TimeSpanProperty2 = new TimeSpan(0, 1, 0) };
Expand Down Expand Up @@ -868,7 +870,7 @@ public static void Xml_DeserializeEmptyTimeSpanType()
}
}

[Fact]
[ConditionalFact(nameof(DefaultValueAttributeIsSupported))]
public static void Xml_TypeWithDateTimeOffsetProperty()
{
var now = new DateTimeOffset(DateTime.Now);
Expand All @@ -893,7 +895,7 @@ public static void Xml_TypeWithDateTimeOffsetProperty()
Assert.True(deserializedObj.NullableDTOWithDefault == null);
}

[Fact]
[ConditionalFact(nameof(DefaultValueAttributeIsSupported))]
public static void Xml_DeserializeTypeWithEmptyDateTimeOffsetProperties()
{
//var def = DateTimeOffset.Parse("3/17/1977 5:00:01 PM -05:00"); // "1977-03-17T17:00:01-05:00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace System.ComponentModel.Tests
{
public class DefaultValueAttributeTests
{
public static bool DefaultValueAttributeIsSupported => AppContext.TryGetSwitch("System.ComponentModel.DefaultValueAttribute.IsSupported", out bool isEnabled) ? isEnabled : true;

[Fact]
public static void Ctor()
public static void Ctor_value()
{
Assert.Equal((object)true, new DefaultValueAttribute(true).Value);
Assert.Equal((object)false, new DefaultValueAttribute(false).Value);
Expand All @@ -37,7 +39,11 @@ public static void Ctor()
Assert.Equal("test", new DefaultValueAttribute("test").Value);

Assert.Equal("test", new DefaultValueAttribute((object)"test").Value);
}

[ConditionalFact(nameof(DefaultValueAttributeIsSupported))]
public static void Ctor_type_string()
{
Assert.Equal(DayOfWeek.Monday, new DefaultValueAttribute(typeof(DayOfWeek), "Monday").Value);
Assert.Equal(TimeSpan.FromHours(1), new DefaultValueAttribute(typeof(TimeSpan), "1:00:00").Value);

Expand All @@ -63,7 +69,7 @@ public class CustomType2
public int Value { get; set; }
}

[Fact]
[ConditionalFact(nameof(DefaultValueAttributeIsSupported))]
public static void Ctor_CustomTypeConverter()
{
TypeDescriptor.AddAttributes(typeof(CustomType), new TypeConverterAttribute(typeof(CustomConverter)));
Expand Down Expand Up @@ -99,7 +105,7 @@ public void Ctor_TypeDescriptorNotFound_ExceptionFallback(Type type, bool return
}, type.ToString(), returnNull.ToString(), stringToConvert, expectedValue.ToString()).Dispose();
}

[Theory]
[ConditionalTheory(nameof(DefaultValueAttributeIsSupported))]
[InlineData(typeof(CustomType2))]
[InlineData(typeof(DefaultValueAttribute))]
public static void Ctor_DefaultTypeConverter_Null(Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<TestConsoleAppSourceFiles Include="DebuggerVisualizerAttributeTests.cs" >
<EnabledProperties>DebuggerSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DefaultValueAttributeCtorTest.cs" />
<TestConsoleAppSourceFiles Include="DefaultValueAttributeCtorTest.cs">
<EnabledProperties>_DefaultValueAttributeSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="GenericArraySortHelperTest.cs" />
<TestConsoleAppSourceFiles Include="InheritedAttributeTests.cs" />
<TestConsoleAppSourceFiles Include="InterfacesOnArrays.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/blazor-frame/blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<ItemGroup>
<!-- TODO un-pin this when it's possible -->
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-preview.6.24328.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-preview.6.24328.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-preview.7.24406.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-preview.7.24406.2" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0-preview.6.24328.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0-preview.7.24406.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<!-- versions are pinned but when run from WBT level, it's taking in-tree runtime -->
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-preview.6.24328.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-preview.6.24328.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-preview.7.24406.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-preview.7.24406.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<!-- versions are pinned but when run from WBT level, it's taking in-tree runtime -->
<ItemGroup>
<PackageReference Include="System.Net.Http.Json" Version="9.0.0-preview.6.24327.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0-preview.6.24328.4" />
<PackageReference Include="System.Net.Http.Json" Version="9.0.0-preview.7.24405.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0-preview.7.24406.2" />
</ItemGroup>
</Project>

0 comments on commit 605ff6f

Please sign in to comment.