Skip to content

Commit dd0f250

Browse files
committed
Add AOT analyzers to tests.
1 parent ad4ce85 commit dd0f250

File tree

11 files changed

+23
-16
lines changed

11 files changed

+23
-16
lines changed

DependencyInjection/test/AppCoreNet.Extensions.DependencyInjection.AssemblyExtensions.Tests/AssemblyResolverTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using AppCoreNet.Extensions.DependencyInjection.Activator;
89
using AppCoreNet.Extensions.DependencyInjection.Facilities;
@@ -12,17 +13,14 @@
1213

1314
namespace AppCoreNet.Extensions.DependencyInjection;
1415

16+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1517
public class AssemblyResolverTests
1618
{
1719
private readonly IActivator _activator;
1820

1921
public AssemblyResolverTests()
2022
{
21-
var activator = Substitute.For<IActivator>();
22-
activator.CreateInstance(Arg.Any<Type>(), Arg.Any<object[]>())
23-
.Returns(ci => System.Activator.CreateInstance(ci.ArgAt<Type>(0)));
24-
25-
_activator = activator;
23+
_activator = DefaultActivator.Instance;
2624
}
2725

2826
[Fact]

DependencyInjection/test/AppCoreNet.Extensions.DependencyInjection.AssemblyExtensions.Tests/AssemblyScannerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// Licensed under the MIT license.
22
// Copyright (c) The AppCore .NET project.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using FluentAssertions;
67
using Xunit;
78
using static AppCoreNet.Extensions.DependencyInjection.TestContracts;
89

910
namespace AppCoreNet.Extensions.DependencyInjection;
1011

12+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1113
public class AssemblyScannerTests
1214
{
1315
[Fact]
1416
public void FindsAllImplementationsOfInterface()
1517
{
16-
var scanner = new AssemblyScanner(
17-
typeof(IContract));
18+
var scanner = new AssemblyScanner(typeof(IContract));
1819

1920
scanner.Filters.Clear();
2021
scanner.Assemblies.Add(typeof(AssemblyScannerTests).GetTypeInfo().Assembly);

DependencyInjection/test/AppCoreNet.Extensions.DependencyInjection.AssemblyExtensions.Tests/AssemblyServicesDescriptorResolverTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using FluentAssertions;
78
using Microsoft.Extensions.DependencyInjection;
89
using Xunit;
910
using static AppCoreNet.Extensions.DependencyInjection.TestContracts;
1011

1112
namespace AppCoreNet.Extensions.DependencyInjection;
1213

14+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1315
public class AssemblyServicesDescriptorResolverTests
1416
{
1517
[Fact]

DependencyInjection/test/AppCoreNet.Extensions.DependencyInjection.Tests/Facilities/FacilityBuilderTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ public class FacilityBuilderTests
1818

1919
public FacilityBuilderTests()
2020
{
21-
var activator = Substitute.For<IActivator>();
22-
activator.CreateInstance(Arg.Any<Type>(), Arg.Any<object[]>())
23-
.Returns(ci => System.Activator.CreateInstance(ci.ArgAt<Type>(0), ci.ArgAt<object[]>(1)));
24-
25-
_activator = activator;
21+
_activator = DefaultActivator.Instance;
2622
_services = new ServiceCollection();
2723
}
2824

DependencyInjection/test/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<IsPackable>false</IsPackable>
66
<NoWarn>$(NoWarn);VSTHRD200</NoWarn>
7+
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</EnableTrimAnalyzer>
78
</PropertyGroup>
89

910
<ItemGroup>

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.Tests/PluginFacilityResolverTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) The AppCore .NET project.
33

44
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
67
using AppCoreNet.Extensions.DependencyInjection;
78
using FluentAssertions;
@@ -10,6 +11,7 @@
1011

1112
namespace AppCoreNet.Extensions.Hosting.Plugins;
1213

14+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1315
public class PluginFacilityResolverTests
1416
{
1517
#nullable disable

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.Tests/PluginManagerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using System.Reflection;
89
using AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -14,6 +15,7 @@
1415

1516
namespace AppCoreNet.Extensions.Hosting.Plugins;
1617

18+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1719
public class PluginManagerTests
1820
{
1921
[Fact]

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.Tests/PluginServiceDescriptorResolverTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Copyright (c) The AppCore .NET project.
33

44
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
56
using AppCoreNet.Extensions.DependencyInjection;
67
using FluentAssertions;
78
using Microsoft.Extensions.DependencyInjection;
89
using Xunit;
910

1011
namespace AppCoreNet.Extensions.Hosting.Plugins;
1112

13+
[RequiresUnreferencedCode("This test requires types that may be trimmed by the linker.")]
1214
public class PluginServiceDescriptorResolverTests
1315
{
1416
#nullable disable

Hosting/test/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<IsPackable>false</IsPackable>
66
<NoWarn>$(NoWarn);VSTHRD200</NoWarn>
7+
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</EnableTrimAnalyzer>
78
</PropertyGroup>
89

910
<ItemGroup>

Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationParameters.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace AppCoreNet.Extensions.Http.Authentication;
1212
/// </summary>
1313
public class AuthenticationParameters
1414
{
15-
private IDictionary<string, object> _parameters;
15+
private readonly IDictionary<string, object> _parameters;
1616

1717
/// <summary>
1818
/// Gets or sets a value indicating whether to force renewing the authentication.
@@ -49,10 +49,11 @@ protected AuthenticationParameters(IDictionary<string, object> parameters)
4949
public T Clone<T>()
5050
where T : AuthenticationParameters, new()
5151
{
52-
var clone = new T
52+
var clone = new T();
53+
foreach (KeyValuePair<string, object> parameter in _parameters)
5354
{
54-
_parameters = new Dictionary<string, object>(_parameters, StringComparer.Ordinal),
55-
};
55+
clone._parameters[parameter.Key] = parameter.Value;
56+
}
5657

5758
return clone;
5859
}

0 commit comments

Comments
 (0)