-
Notifications
You must be signed in to change notification settings - Fork 857
Add project name normalization to match aspire's code generator logic #6818
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
7 commits
Select commit
Hold shift + click to select a range
c826374
Add project name normalization to match aspire's code generator for -…
ViveliDuCh 8d333a8
Address PR feedback: Update regex logic and execution test.
ViveliDuCh 9f68b2f
Address PR feedback: Test combine all available providers with aspire…
ViveliDuCh d9529c8
PR suggestions: Add more test cases
ViveliDuCh 724290b
Add an [EnvironmentVariableSkipCondition] attribute for conditional t…
jeffhandley e3de840
Merge pull request #1 from jeffhandley/jeffhandley/conditional-theory
ViveliDuCh d1864e7
Regex logic and _Web append into one step. Rename test skip for clarity.
ViveliDuCh 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
10BC0
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
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
86 changes: 86 additions & 0 deletions
86
test/TestUtilities/XUnit/EnvironmentVariableConditionAttribute.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,86 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.TestUtilities; | ||
|
|
||
| /// <summary> | ||
| /// Skips a test based on the value of an environment variable. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] | ||
| public class EnvironmentVariableConditionAttribute : Attribute, ITestCondition | ||
| { | ||
| private string? _currentValue; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="EnvironmentVariableConditionAttribute"/> class. | ||
| /// </summary> | ||
| /// <param name="variableName">Name of the environment variable.</param> | ||
| /// <param name="values">Value(s) of the environment variable to match for the condition.</param> | ||
| /// <remarks> | ||
| /// By default, the test will be run if the value of the variable matches any of the supplied values. | ||
| /// Set <see cref="RunOnMatch"/> to <c>False</c> to run the test only if the value does not match. | ||
| /// </remarks> | ||
| public EnvironmentVariableConditionAttribute(string variableName, params string[] values) | ||
| { | ||
| if (string.IsNullOrEmpty(variableName)) | ||
| { | ||
| throw new ArgumentException("Value cannot be null or empty.", nameof(variableName)); | ||
| } | ||
|
|
||
| if (values == null || values.Length == 0) | ||
| { | ||
| throw new ArgumentException("You must supply at least one value to match.", nameof(values)); | ||
| } | ||
|
|
||
| VariableName = variableName; | ||
| Values = values; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the test should run if the value of the variable matches any | ||
| /// of the supplied values. If <c>False</c>, the test runs only if the value does not match any of the | ||
| /// supplied values. Default is <c>True</c>. | ||
| /// </summary> | ||
| public bool RunOnMatch { get; set; } = true; | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the environment variable. | ||
| /// </summary> | ||
| public string VariableName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the value(s) of the environment variable to match for the condition. | ||
| /// </summary> | ||
| public string[] Values { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether the condition is met for the configured environment variable and values. | ||
| /// </summary> | ||
| public bool IsMet | ||
| { | ||
| get | ||
| { | ||
| _currentValue ??= Environment.GetEnvironmentVariable(VariableName); | ||
| var hasMatched = Values.Any(value => string.Equals(value, _currentValue, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| return RunOnMatch ? hasMatched : !hasMatched; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating the reason the test was skipped. | ||
| /// </summary> | ||
| public string SkipReason | ||
| { | ||
| get | ||
| { | ||
| var value = _currentValue ?? "(null)"; | ||
|
|
||
| return $"Test skipped on environment variable with name '{VariableName}' and value '{value}' " + | ||
| $"for the '{nameof(RunOnMatch)}' value of '{RunOnMatch}'."; | ||
| } | ||
| } | ||
| } |
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.