Skip to content

Commit 7bcf80a

Browse files
authored
Fix DependencyModel tests on NativeAOT (#87666)
1 parent 053ca3f commit 7bcf80a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextTests.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using FluentAssertions;
4+
using System;
55
using System.IO;
66
using System.Linq;
7+
using FluentAssertions;
78
using Xunit;
89

910
namespace Microsoft.Extensions.DependencyModel.Tests
@@ -280,13 +281,20 @@ public void MergeMergesRuntimeGraph()
280281
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "GetEntryAssembly() returns null")]
281282
public void DefaultWorksCorrectly()
282283
{
283-
// only need to assert the context contains non-null properties.
284-
285284
var context = DependencyContext.Default;
286-
Assert.NotNull(context);
287-
Assert.NotNull(context.RuntimeGraph);
288-
Assert.NotNull(context.RuntimeLibraries);
289-
Assert.NotNull(context.Target);
285+
if (PlatformDetection.IsSingleFile)
286+
{
287+
// single-file apps return a null default DependencyContext
288+
Assert.Null(context);
289+
}
290+
else
291+
{
292+
// only need to assert the context contains non-null properties.
293+
Assert.NotNull(context);
294+
Assert.NotNull(context.RuntimeGraph);
295+
Assert.NotNull(context.RuntimeLibraries);
296+
Assert.NotNull(context.Target);
297+
}
290298
}
291299

292300
private TargetInfo CreateTargetInfo()

0 commit comments

Comments
 (0)