forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomHostTests.cs
More file actions
46 lines (40 loc) · 1.71 KB
/
CustomHostTests.cs
File metadata and controls
46 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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.Reflection;
using System.Runtime.InteropServices;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.Configuration.Tests
{
/// <summary>
/// Tests ConfigurationManager works even when Assembly.GetEntryAssembly() returns null.
/// </summary>
public class CustomHostTests
{
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Does not apply to .NET Framework.")]
public void FilePathIsPopulatedCorrectly()
{
RemoteExecutor.Invoke(() =>
{
MakeAssemblyGetEntryAssemblyReturnNull();
string expectedFilePathEnding = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"dotnet.exe.config" :
"dotnet.config";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Assert.EndsWith(expectedFilePathEnding, config.FilePath);
}).Dispose();
}
/// <summary>
/// Makes Assembly.GetEntryAssembly() return null using private reflection.
/// </summary>
private static void MakeAssemblyGetEntryAssemblyReturnNull()
{
typeof(Assembly)
.GetField("s_forceNullEntryPoint", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, true);
Assert.Null(Assembly.GetEntryAssembly());
}
}
}