|
5 | 5 | using System.Diagnostics;
|
6 | 6 | using System.Diagnostics.Tracing;
|
7 | 7 | using System.Net;
|
8 |
| -using System.Net.Http; |
9 | 8 | using System.Reflection;
|
10 | 9 | using System.Security.Claims;
|
11 | 10 | using System.Text;
|
12 | 11 | using System.Text.Encodings.Web;
|
13 | 12 | using Microsoft.AspNetCore.Authentication;
|
14 |
| -using Microsoft.AspNetCore.Authorization; |
15 | 13 | using Microsoft.AspNetCore.Builder;
|
16 | 14 | using Microsoft.AspNetCore.HostFiltering;
|
17 | 15 | using Microsoft.AspNetCore.Hosting;
|
|
23 | 21 | using Microsoft.AspNetCore.TestHost;
|
24 | 22 | using Microsoft.AspNetCore.Testing;
|
25 | 23 | using Microsoft.AspNetCore.Tests;
|
| 24 | +using Microsoft.DotNet.RemoteExecutor; |
26 | 25 | using Microsoft.Extensions.Configuration;
|
27 | 26 | using Microsoft.Extensions.DependencyInjection;
|
28 | 27 | using Microsoft.Extensions.DependencyInjection.Extensions;
|
@@ -556,9 +555,57 @@ public void SettingContentRootToRelativePathUsesAppContextBaseDirectoryAsPathBas
|
556 | 555 | builder.WebHost.UseContentRoot("");
|
557 | 556 |
|
558 | 557 | Assert.Equal(NormalizePath(AppContext.BaseDirectory), NormalizePath(builder.Environment.ContentRootPath));
|
| 558 | + } |
| 559 | + |
| 560 | + private static string NormalizePath(string unnormalizedPath) => |
| 561 | + Path.TrimEndingDirectorySeparator(Path.GetFullPath(unnormalizedPath)); |
| 562 | + |
| 563 | + [ConditionalFact] |
| 564 | + [RemoteExecutionSupported] |
| 565 | + public void ContentRootIsDefaultedToCurrentDirectory() |
| 566 | + { |
| 567 | + var tmpDir = Directory.CreateTempSubdirectory(); |
| 568 | + |
| 569 | + try |
| 570 | + { |
| 571 | + var options = new RemoteInvokeOptions(); |
| 572 | + options.StartInfo.WorkingDirectory = tmpDir.FullName; |
| 573 | + |
| 574 | + using var remoteHandle = RemoteExecutor.Invoke(static () => |
| 575 | + { |
| 576 | + foreach (object[] data in CreateBuilderFuncs) |
| 577 | + { |
| 578 | + var createBuilder = (CreateBuilderFunc)data[0]; |
| 579 | + var builder = createBuilder(); |
559 | 580 |
|
560 |
| - static string NormalizePath(string unnormalizedPath) => |
561 |
| - Path.TrimEndingDirectorySeparator(Path.GetFullPath(unnormalizedPath)); |
| 581 | + Assert.Equal(NormalizePath(Environment.CurrentDirectory), NormalizePath(builder.Environment.ContentRootPath)); |
| 582 | + } |
| 583 | + }, options); |
| 584 | + } |
| 585 | + finally |
| 586 | + { |
| 587 | + tmpDir.Delete(recursive: true); |
| 588 | + } |
| 589 | + } |
| 590 | + |
| 591 | + [ConditionalFact] |
| 592 | + [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] |
| 593 | + [RemoteExecutionSupported] |
| 594 | + public void ContentRootIsBaseDirectoryWhenCurrentIsSpecialFolderSystem() |
| 595 | + { |
| 596 | + var options = new RemoteInvokeOptions(); |
| 597 | + options.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System); |
| 598 | + |
| 599 | + using var remoteHandle = RemoteExecutor.Invoke(static () => |
| 600 | + { |
| 601 | + foreach (object[] data in CreateBuilderFuncs) |
| 602 | + { |
| 603 | + var createBuilder = (CreateBuilderFunc)data[0]; |
| 604 | + var builder = createBuilder(); |
| 605 | + |
| 606 | + Assert.Equal(NormalizePath(AppContext.BaseDirectory), NormalizePath(builder.Environment.ContentRootPath)); |
| 607 | + } |
| 608 | + }, options); |
562 | 609 | }
|
563 | 610 |
|
564 | 611 | [Theory]
|
@@ -795,6 +842,43 @@ public void WebApplicationBuilderApplicationNameCanBeOverridden(WebApplicationBu
|
795 | 842 | Assert.Equal(assemblyName, webHostEnv.ApplicationName);
|
796 | 843 | }
|
797 | 844 |
|
| 845 | + [ConditionalFact] |
| 846 | + [RemoteExecutionSupported] |
| 847 | + public void WebApplicationBuilderConfigurationSourcesOrderedCorrectly() |
| 848 | + { |
| 849 | + // all WebApplicationBuilders have the following configuration sources ordered highest to lowest priority: |
| 850 | + // 1. Command-line arguments |
| 851 | + // 2. Non-prefixed environment variables |
| 852 | + // 3. DOTNET_-prefixed environment variables |
| 853 | + // 4. ASPNETCORE_-prefixed environment variables |
| 854 | + |
| 855 | + var options = new RemoteInvokeOptions(); |
| 856 | + options.StartInfo.EnvironmentVariables.Add("one", "unprefixed_one"); |
| 857 | + options.StartInfo.EnvironmentVariables.Add("two", "unprefixed_two"); |
| 858 | + options.StartInfo.EnvironmentVariables.Add("DOTNET_one", "DOTNET_one"); |
| 859 | + options.StartInfo.EnvironmentVariables.Add("DOTNET_two", "DOTNET_two"); |
| 860 | + options.StartInfo.EnvironmentVariables.Add("DOTNET_three", "DOTNET_three"); |
| 861 | + options.StartInfo.EnvironmentVariables.Add("ASPNETCORE_one", "ASPNETCORE_one"); |
| 862 | + options.StartInfo.EnvironmentVariables.Add("ASPNETCORE_two", "ASPNETCORE_two"); |
| 863 | + options.StartInfo.EnvironmentVariables.Add("ASPNETCORE_three", "ASPNETCORE_three"); |
| 864 | + options.StartInfo.EnvironmentVariables.Add("ASPNETCORE_four", "ASPNETCORE_four"); |
| 865 | + |
| 866 | + using var remoteHandle = RemoteExecutor.Invoke(static () => |
| 867 | + { |
| 868 | + var args = new[] { "--one=command_line_one" }; |
| 869 | + foreach (object[] data in CreateBuilderArgsFuncs) |
| 870 | + { |
| 871 | + var createBuilder = (CreateBuilderArgsFunc)data[0]; |
| 872 | + var builder = createBuilder(args); |
| 873 | + |
| 874 | + Assert.Equal("command_line_one", builder.Configuration["one"]); |
| 875 | + Assert.Equal("unprefixed_two", builder.Configuration["two"]); |
| 876 | + Assert.Equal("DOTNET_three", builder.Configuration["three"]); |
| 877 | + Assert.Equal("ASPNETCORE_four", builder.Configuration["four"]); |
| 878 | + } |
| 879 | + }, options); |
| 880 | + } |
| 881 | + |
798 | 882 | [Theory]
|
799 | 883 | [MemberData(nameof(CreateBuilderArgsFuncs))]
|
800 | 884 | public void WebApplicationBuilderCanFlowCommandLineConfigurationToApplication(CreateBuilderArgsFunc createBuilder)
|
@@ -976,7 +1060,7 @@ public async Task WebApplicationCanObserveSourcesClearedInBuild(CreateBuilderFun
|
976 | 1060 |
|
977 | 1061 | [Theory]
|
978 | 1062 | [MemberData(nameof(CreateBuilderOptionsFuncs))]
|
979 |
| - public async Task WebApplicationCanObserveSourcesClearedInConfiguratHostConfiguration(CreateBuilderOptionsFunc createBuilder) |
| 1063 | + public async Task WebApplicationCanObserveSourcesClearedInHostConfiguration(CreateBuilderOptionsFunc createBuilder) |
980 | 1064 | {
|
981 | 1065 | // This mimics what WebApplicationFactory<T> does and runs configure
|
982 | 1066 | // services callbacks
|
|
0 commit comments