-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix web root for WebApplication #32604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have a better way to do this from the csproj now? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostEnvironmentTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.AspNetCore.Tests | ||
| { | ||
| public class WebHostEnvironmentTests | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test making sure static files works? |
||
| { | ||
| [Fact] | ||
| public void ApplyConfigurationSettingsUsesTheCorrectKeys() | ||
| { | ||
| var configBuilder = new ConfigurationBuilder(); | ||
| configBuilder.AddInMemoryCollection(new[] | ||
| { | ||
| new KeyValuePair<string, string>(WebHostDefaults.ApplicationKey, WebHostDefaults.ApplicationKey), | ||
| new KeyValuePair<string, string>(WebHostDefaults.EnvironmentKey, WebHostDefaults.EnvironmentKey), | ||
| new KeyValuePair<string, string>(WebHostDefaults.ContentRootKey, WebHostDefaults.ContentRootKey), | ||
| new KeyValuePair<string, string>(WebHostDefaults.WebRootKey, WebHostDefaults.WebRootKey), | ||
| }); | ||
|
|
||
| var env = new WebHostEnvironment(); | ||
|
|
||
| // Basically call ApplyConfigurationSettings(config) but without creating PhysicalFileProviders. | ||
| env.ReadConfigurationSettings(configBuilder.Build()); | ||
|
|
||
| Assert.Equal(WebHostDefaults.ApplicationKey, env.ApplicationName); | ||
| Assert.Equal(WebHostDefaults.EnvironmentKey, env.EnvironmentName); | ||
| Assert.Equal(WebHostDefaults.ContentRootKey, env.ContentRootPath); | ||
| Assert.Equal(WebHostDefaults.WebRootKey, env.WebRootPath); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ApplyEnvironmentSettingsUsesTheCorrectKeys() | ||
| { | ||
| var env = new WebHostEnvironment | ||
| { | ||
| ApplicationName = WebHostDefaults.ApplicationKey, | ||
| EnvironmentName = WebHostDefaults.EnvironmentKey, | ||
| ContentRootPath = WebHostDefaults.ContentRootKey, | ||
| WebRootPath = WebHostDefaults.WebRootKey, | ||
| }; | ||
|
|
||
| var settings = new Dictionary<string, string>(); | ||
|
|
||
| env.ApplyEnvironmentSettings(new TestWebHostBuilder(settings)); | ||
|
|
||
| Assert.Equal(WebHostDefaults.ApplicationKey, settings[WebHostDefaults.ApplicationKey]); | ||
| Assert.Equal(WebHostDefaults.EnvironmentKey, settings[WebHostDefaults.EnvironmentKey]); | ||
| Assert.Equal(WebHostDefaults.ContentRootKey, settings[WebHostDefaults.ContentRootKey]); | ||
| Assert.Equal(WebHostDefaults.WebRootKey, settings[WebHostDefaults.WebRootKey]); | ||
| } | ||
|
|
||
| private class TestWebHostBuilder : IWebHostBuilder | ||
| { | ||
| private readonly Dictionary<string, string> _settings; | ||
|
|
||
| public TestWebHostBuilder(Dictionary<string, string> settingsDictionary) | ||
| { | ||
| _settings = settingsDictionary; | ||
| } | ||
|
|
||
| public IWebHost Build() | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public IWebHostBuilder ConfigureServices(Action<IServiceCollection> configureServices) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public IWebHostBuilder ConfigureServices(Action<WebHostBuilderContext, IServiceCollection> configureServices) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public string GetSetting(string key) | ||
| { | ||
| _settings.TryGetValue(key, out var value); | ||
| return value; | ||
| } | ||
|
|
||
| public IWebHostBuilder UseSetting(string key, string value) | ||
| { | ||
| _settings[key] = value; | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you manually tested this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I can write a
manualautomated test. There aren't any e2e tests in DefaultBuilder that don't hit the network stack so I was a little lazy and just went with the unit tests and the sample.