-
Notifications
You must be signed in to change notification settings - Fork 11
Data driven new project wizard #93
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
Open
clrudolphi
wants to merge
14
commits into
main
Choose a base branch
from
DataDrivenNewProjectWizard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c4aa8f5
Alpha
clrudolphi 0be9ff0
Revised substitution model.
clrudolphi 1e8d88d
Working substitution model with all lowercase and no underscores
clrudolphi d09cdbe
Working example using a fixed number of slots for packages.
clrudolphi b28fd7c
dummy implementation for single template param reference substitution
gasparnagy b3faa4b
Now fetching descriptors from URL.
clrudolphi 2175445
Added Unit Tests of the NewProjectMetaDataProvider. Added an abstract…
clrudolphi 2a0853d
reset whitespace changes in AddNewReqnrollProjectDialog.xaml for bett…
gasparnagy 0c20e34
Update DesignData AddNewReqnrollProjectViewModel for Reqnroll.VisualS…
gasparnagy 800b2ab
fix style by replacing TextBlock with Label
gasparnagy 73ee5ab
fix data binding errors
gasparnagy da2018f
Make metadata retrieval async, fix view model design
gasparnagy b949d95
Completed transition to async NewProjectMetaDataProvider by modifying…
clrudolphi 1afe9b8
Simplified NewProjectMetaData data structure by eliminating fields th…
clrudolphi 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
53 changes: 53 additions & 0 deletions
53
Reqnroll.VisualStudio/Resources/TestFrameworkDescriptors.json
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,53 @@ | ||
| { | ||
| "xUnit": { | ||
| "description": "Use xUnit v2 test executor with Reqnroll", | ||
| "dependencies": { | ||
| "Reqnroll_Lib": { | ||
| "name": "Reqnroll.xUnit", | ||
| "version": "2.4.1" | ||
| }, | ||
| "TestFramework_Lib": { | ||
| "name": "xunit", | ||
| "version": "2.8.1" | ||
| }, | ||
| "Adapter_Lib": { | ||
| "name": "xunit.runner.visualstudio", | ||
| "version": "2.8.1" | ||
| } | ||
| } | ||
| }, | ||
| "MsTest": { | ||
| "description": "Use MsTest v3 test executor with Reqnroll", | ||
| "dependencies": { | ||
| "Reqnroll_Lib": { | ||
| "name": "Reqnroll.MsTest", | ||
| "version": "2.4.1" | ||
| }, | ||
| "TestFramework_Lib": { | ||
| "name": "MSTest.TestFramework", | ||
| "version": "3.4.3" | ||
| }, | ||
| "Adapter_Lib": { | ||
| "name": "MSTest.TestAdapter", | ||
| "version": "3.4.3" | ||
| } | ||
| } | ||
| }, | ||
| "NUnit": { | ||
| "description": "Use NUnit v3 test executor with Reqnroll", | ||
| "dependencies": { | ||
| "Reqnroll_Lib": { | ||
| "name": "Reqnroll.NUnit", | ||
| "version": "2.4.1" | ||
| }, | ||
| "TestFramework_Lib": { | ||
| "name": "nunit", | ||
| "version": "3.14.0" | ||
| }, | ||
| "Adapter_Lib": { | ||
| "name": "NUnit3TestAdapter", | ||
| "version": "4.5.0" | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
88 changes: 88 additions & 0 deletions
88
Reqnroll.VisualStudio/Wizards/Infrastructure/NewProjectMetaDataProvider.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,88 @@ | ||
| namespace Reqnroll.VisualStudio.Wizards.Infrastructure; | ||
|
|
||
| public interface INewProjectMetaDataProvider | ||
| { | ||
| IEnumerable<string> TestFrameworks { get; } | ||
| IDictionary<string, NugetPackageDescriptor> DependenciesOf(string testFramework); | ||
| } | ||
| public record NugetPackageDescriptor(string name, string version); | ||
| public record TestFrameworkInfoModel(string description, Dictionary<string, NugetPackageDescriptor> dependencies); | ||
|
|
||
| [Export(typeof(INewProjectMetaDataProvider))] | ||
| public class NewProjectMetaDataProvider : INewProjectMetaDataProvider | ||
| { | ||
| private Dictionary<string, TestFrameworkInfoModel> _testFrameworkDescriptors = new(); | ||
| private Task<Dictionary<string, TestFrameworkInfoModel>> _httpTask; | ||
| private Lazy<Dictionary<string, TestFrameworkInfoModel>> _resolvedTestFrameworkDescriptors; | ||
|
|
||
| [ImportingConstructor] | ||
| public NewProjectMetaDataProvider() | ||
| { | ||
| // read static metadata from a resource file, deserialize the resulting json, storing it in the _testFrameworkDescriptors field | ||
| var resourceName = "Reqnroll.VisualStudio.Resources.TestFrameworkDescriptors.json"; | ||
| using (var stream = typeof(NewProjectMetaDataProvider).Assembly.GetManifestResourceStream(resourceName)) | ||
| using (var reader = new StreamReader(stream)) | ||
| { | ||
| var json = reader.ReadToEnd(); | ||
| var data = JsonSerialization.DeserializeObject<Dictionary<string, TestFrameworkInfoModel>>(json); | ||
| if (data != null) | ||
| _testFrameworkDescriptors = data; | ||
| } | ||
|
|
||
| // launch a task to read metadata from http resource and deserialize the resulting json, save the Task to a field | ||
| _httpTask = Task.Run(async () => | ||
|
Check warning on line 33 in Reqnroll.VisualStudio/Wizards/Infrastructure/NewProjectMetaDataProvider.cs
|
||
| { | ||
| try | ||
| { | ||
| using (var httpClient = new System.Net.Http.HttpClient()) | ||
| { | ||
| var httpJson = await httpClient.GetStringAsync("https://example.com/testframeworks.json").ConfigureAwait(false); | ||
| var httpData = JsonSerialization.DeserializeObject<Dictionary<string, TestFrameworkInfoModel>>(httpJson); | ||
| return httpData; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| return null; | ||
| } | ||
| }); | ||
|
|
||
| _resolvedTestFrameworkDescriptors = new Lazy<Dictionary<string, TestFrameworkInfoModel>>(FinishRetrievalOfTestFrameworkDescriptors); | ||
| } | ||
|
|
||
| public IEnumerable<string> TestFrameworks | ||
| { | ||
| get | ||
| { | ||
| var descriptors = _resolvedTestFrameworkDescriptors.Value; | ||
| return descriptors.Keys; | ||
| } | ||
| } | ||
|
|
||
| public IDictionary<string, NugetPackageDescriptor> DependenciesOf(string testFramework) | ||
| { | ||
| var descriptors = _resolvedTestFrameworkDescriptors.Value; | ||
| return descriptors[testFramework].dependencies; | ||
| } | ||
|
|
||
| private Dictionary<string, TestFrameworkInfoModel> FinishRetrievalOfTestFrameworkDescriptors() | ||
| { | ||
| // Wait for the HTTP task to complete | ||
| if (_httpTask == null) | ||
| return _testFrameworkDescriptors; | ||
|
|
||
| try | ||
| { | ||
| var result = _httpTask.GetAwaiter().GetResult(); | ||
| if (result != null) | ||
| { | ||
| _testFrameworkDescriptors = result; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // Ignore exceptions, keep existing _testFrameworkDescriptors | ||
| } | ||
| return _testFrameworkDescriptors; | ||
| } | ||
| } | ||
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.
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 fear that there will be test frameworks that require more than one dependencies (maybe in some combinations we might need even multiple Reqnroll dependencies too), so I think I would prefer having a general list of dependencies that we just add and not have that categorization.
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 understand your rationale. When allowing for a more flexible set of package references, the wizard code must then generate a
<PackageReference>string for each and the number of them can't be predicted ahead of time. That means the template would have a single substitution token into which all of the package reference strings must go.I've spent all afternoon on this and keep running in to the same problem.
Template substitution works fine when the substitution variable represents a single xml element to be injected into the csproj (or a subsection of an element's textual representation).
When there are multiple items to be injected, each has to have its own substitution variable. Any attempt to include more than one line or more than one xml element causes an error.
I've attempted every way I can think of to join multiple together, but MSBuild keeps complaining that there is invalid xml (specifically 'The element <#text> beneath element
<ItemGroup>is unrecognized'). I've joined the package reference strings withEnvironment.NewLine, with a hard-coded '\n' and with no separation at all. All result in the same error.Have you seen this problem before? (I'm struggling to find reliable docs and information on what is/is-not allowed)
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.
It sounds like the system is rejecting XML fragments. Could you add a complete
<ItemGroup>with all its descendants?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.
It is rejecting multi-line substitution variable values.
I tried the suggestion of substituting the entire
<ItemGroup>element, but ended up with the same error.