-
Notifications
You must be signed in to change notification settings - Fork 844
AspNetCore.Testing readme, namespaces #4561
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
joperezr
merged 4 commits into
dotnet:release/8.0
from
Tratcher:tratcher/readme_asptesting
Oct 20, 2023
Merged
Changes from 3 commits
Commits
Show all changes
4 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # | ||
| # This file must be used by invoking ". .\activate.ps1" from the command line. | ||
| # You cannot run it directly. See https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_scripts#script-scope-and-dot-sourcing | ||
| # | ||
| # To exit from the environment this creates, execute the 'deactivate' function. | ||
| # | ||
|
|
||
| if ($MyInvocation.CommandOrigin -eq 'runspace') { | ||
| Write-Host -f Red "This script cannot be invoked directly." | ||
| Write-Host -f Red "To function correctly, this script file must be 'dot sourced' by calling `". $PSCommandPath`" (notice the dot at the beginning)." | ||
| exit 1 | ||
| } | ||
|
|
||
| function deactivate ([switch]$init) { | ||
|
|
||
| # reset old environment variables | ||
| if (Test-Path variable:_OLD_PATH) { | ||
| $env:PATH = $_OLD_PATH | ||
| Remove-Item variable:_OLD_PATH | ||
| } | ||
|
|
||
| if (test-path function:_old_prompt) { | ||
| Set-Item Function:prompt -Value $function:_old_prompt -ea ignore | ||
| remove-item function:_old_prompt | ||
| } | ||
|
|
||
| Remove-Item env:DOTNET_ROOT -ea ignore | ||
| Remove-Item 'env:DOTNET_ROOT(x86)' -ea Ignore | ||
| Remove-Item env:DOTNET_MULTILEVEL_LOOKUP -ea ignore | ||
| if (-not $init) { | ||
| # Remove the deactivate function | ||
| Remove-Item function:deactivate | ||
| } | ||
| } | ||
|
|
||
| # Cleanup the environment | ||
| deactivate -init | ||
|
|
||
| $_OLD_PATH = $env:PATH | ||
| # Tell dotnet where to find itself | ||
| $env:DOTNET_ROOT = "$PSScriptRoot\.dotnet" | ||
| ${env:DOTNET_ROOT(x86)} = "$PSScriptRoot\.dotnet\x86" | ||
| # Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things | ||
| $env:DOTNET_MULTILEVEL_LOOKUP = 0 | ||
Tratcher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Put dotnet first on PATH | ||
| $env:PATH = "${env:DOTNET_ROOT};${env:PATH}" | ||
|
|
||
| # Set the shell prompt | ||
| if (-not $env:DISABLE_CUSTOM_PROMPT) { | ||
| $function:_old_prompt = $function:prompt | ||
| function dotnet_prompt { | ||
| # Add a prefix to the current prompt, but don't discard it. | ||
| write-host "($( split-path $PSScriptRoot -leaf )) " -nonewline | ||
| & $function:_old_prompt | ||
| } | ||
|
|
||
| Set-Item Function:prompt -Value $function:dotnet_prompt -ea ignore | ||
| } | ||
|
|
||
| Write-Host -f Magenta "Enabled the .NET Core environment. Execute 'deactivate' to exit." | ||
| if (-not (Test-Path "${env:DOTNET_ROOT}\dotnet.exe")) { | ||
| Write-Host -f Yellow ".NET Core has not been installed yet. Run $PSScriptRoot\restore.cmd to install it." | ||
| } | ||
| else { | ||
| Write-Host "dotnet = ${env:DOTNET_ROOT}\dotnet.exe" | ||
| } | ||
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 |
|---|---|---|
| @@ -1 +1,50 @@ | ||
| README | ||
| # Microsoft.AspNetCore.Testing | ||
|
|
||
| This package provides test fakes for integration testing of ASP.NET Core applications. | ||
|
|
||
| In particular: | ||
|
|
||
| - `IWebHostBuilder` extensions to setup the test web app. | ||
| - `IHost` extensions to access that test web app. | ||
|
|
||
| ## Install the package | ||
|
|
||
| From the command-line: | ||
|
|
||
| ```dotnetcli | ||
| dotnet add package Microsoft.AspNetCore.Testing | ||
| ``` | ||
|
|
||
| Or directly in the C# project file: | ||
|
|
||
| ```xml | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Testing" Version="[CURRENTVERSION]" /> | ||
| </ItemGroup> | ||
| ``` | ||
|
|
||
| ## Usage Example | ||
|
|
||
| ### Creating a Test Web App | ||
|
|
||
| The [`IWebHostBuilder`](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.hosting.iwebhostbuilder) extensions can help set up a host for testing. | ||
|
|
||
| ```csharp | ||
| using var host = await FakeHost.CreateBuilder() | ||
| .ConfigureWebHost(webHost => webHost.UseFakeStartup().ListenHttpOnAnyPort()) | ||
| .StartAsync(); | ||
| ``` | ||
|
|
||
| ### Accessing the test Web App | ||
|
|
||
| The [`IHost`](https://learn.microsoft.com/dotnet/api/microsoft.extensions.hosting.ihost) extensions can help access the test host that was created above. | ||
|
|
||
| ```csharp | ||
| using var client = host.CreateClient(); | ||
|
|
||
| var response = await client.GetAsync("/"); | ||
| ``` | ||
|
|
||
| ## Feedback & Contributing | ||
|
|
||
| We welcome feedback and contributions in [our GitHub repo](https://github.com/dotnet/extensions). |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.