-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Asp.Net Core folder search (#137)
Support for lookup of Asp.Net Core shared folder without exact version number match
- Loading branch information
Showing
19 changed files
with
170 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,43 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using DryGen.Core; | ||
|
||
namespace DryGen; | ||
|
||
public class AspNetCoreSharedFolderResolver(string dotNetRuntimeDirectory) | ||
{ | ||
public string DotNetRuntimeDirectory => dotNetRuntimeDirectory.AsLinuxPath().TrimEnd('/'); | ||
|
||
public AspNetCoreSharedFolderResolver() : this(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()) | ||
{ | ||
} | ||
|
||
public string? Resolve() | ||
{ | ||
var result = DotNetRuntimeDirectory.Replace("Microsoft.NETCore.App", "Microsoft.AspNetCore.App"); | ||
if (Directory.Exists(result)) | ||
{ | ||
return result.AsLinuxPath(); | ||
} | ||
var dotNetRuntimeVersion = new DirectoryInfo(result).Name; | ||
var baseAspNetDirectory = new DirectoryInfo(result[..result.LastIndexOf('/')]).AsNonNull(); | ||
var bestCandidate = baseAspNetDirectory.GetDirectories().Where(x => IsCandidate(x.Name, dotNetRuntimeVersion)).OrderByDescending(x => x.Name).FirstOrDefault(); | ||
return bestCandidate?.FullName.AsLinuxPath(); | ||
} | ||
|
||
private static bool IsCandidate(string aspNetCoreVersion, string dotNetRuntimeVersion) | ||
{ | ||
var dotNetRuntimeVersionParts = dotNetRuntimeVersion.Split(".").AsNonNull(); | ||
var aspNetCoreVersionParts = aspNetCoreVersion.Split(".").AsNonNull(); | ||
for (var i = 0; i < dotNetRuntimeVersionParts.Length; i++) | ||
{ | ||
if (i >= aspNetCoreVersionParts.Length) { | ||
continue; | ||
} | ||
if (aspNetCoreVersionParts[i] == dotNetRuntimeVersionParts[i]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains 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 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 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,4 +1,5 @@ | ||
using System.IO; | ||
using DryGen.Core; | ||
|
||
namespace DryGen.Docs; | ||
|
||
|
This file contains 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 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 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,5 +1,6 @@ | ||
using System; | ||
using System.IO; | ||
using DryGen.Core; | ||
|
||
namespace DryGen.Docs; | ||
|
||
|
This file contains 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 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
20 changes: 20 additions & 0 deletions
20
src/develop/DryGen.UTests/Features/DotNetSharedFolders.feature
This file contains 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,20 @@ | ||
Feature: .Net shared folders | ||
To be able to use dry-gen with assemblies located in the .Net shared folders | ||
As a dry-gen user | ||
I should get the Asp.Net Core shared folder name resolved by the .Net shared folder | ||
|
||
Scenario: Resolve Asp.Net Core shared folders from .Net version | ||
Given the base .Net shared folder is 'Microsoft.NETCore.App' | ||
Given these .Net shared folder paths | ||
| Base folder | Sub folder | | ||
| Microsoft.NETCore.App | <.Net version> | | ||
| Microsoft.AspNetCore.App | <Asp.Net Core version 1> | | ||
| Microsoft.AspNetCore.App | <Asp.Net Core version 2> | | ||
When I resolve the Asp.Net Core shared folder with .Net version '<.Net version>' | ||
Then I should get the folder Asp.Net Core shared folder 'Microsoft.AspNetCore.App/<Asp.Net Core version found>' | ||
|
||
Examples: | ||
| .Net version | Asp.Net Core version 1 | Asp.Net Core version 2 | Asp.Net Core version found | | ||
| 8.0.10 | 6.0.30 | 8.0.10 | 8.0.10 | | ||
| 9.0.0-rc.2.24473.5 | 8.0.10 | 9.0.0-rc.2.24474.3 | 9.0.0-rc.2.24474.3 | | ||
| 9.0.0-rc.2.24473.5/ | 8.0.10 | 9.0.0-rc.2.24474.3 | 9.0.0-rc.2.24474.3 | |
49 changes: 49 additions & 0 deletions
49
src/develop/DryGen.UTests/Steps/DotNetSharedFoldersSteps.cs
This file contains 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,49 @@ | ||
using System.IO; | ||
using DryGen.Core; | ||
using DryGen.DevUtils.Helpers; | ||
using FluentAssertions; | ||
using Reqnroll; | ||
|
||
namespace DryGen.UTests.Steps; | ||
|
||
[Binding] | ||
public sealed class DotNetSharedFoldersSteps | ||
{ | ||
private readonly RootDirectoryContext rootDirectoryContext; | ||
private string? aspNetSharedFolder; | ||
private string? dotNetSharedFolder; | ||
|
||
public DotNetSharedFoldersSteps(RootDirectoryContext rootDirectoryContext) | ||
{ | ||
this.rootDirectoryContext = rootDirectoryContext; | ||
} | ||
|
||
[Given(@"the base .Net shared folder is '([^']*)'")] | ||
public void GivenTheBaseDotNetShareFolderIs(string dotNetSharedFolder) | ||
{ | ||
this.dotNetSharedFolder = dotNetSharedFolder; | ||
} | ||
|
||
[Given(@"these .Net shared folder paths")] | ||
public void GivenTheseDotNetSharedFolders(Table table) | ||
{ | ||
table.Header.Count.Should().Be(2); | ||
foreach(var row in table.Rows) { | ||
rootDirectoryContext.BuldSubDirectory(rootDirectory => Path.Combine(rootDirectory, Path.Combine(row[0], row[1]))); | ||
} | ||
} | ||
|
||
[When(@"I resolve the Asp.Net Core shared folder with .Net version '([^']*)'")] | ||
public void WhenIResolveTheAspDotNetCoreSharedFolderWithDotNetVersion(string dotNetVersion) | ||
{ | ||
var dotNetRuntimeDirectory = Path.Combine(rootDirectoryContext.RootDirectory, Path.Combine(dotNetSharedFolder.AsNonNull(), dotNetVersion)); | ||
aspNetSharedFolder = new AspNetCoreSharedFolderResolver(dotNetRuntimeDirectory).Resolve(); | ||
} | ||
|
||
[Then(@"I should get the folder Asp.Net Core shared folder '([^']*)'")] | ||
public void ThenIShouldGetTheFolderAspDotNetCoreSharedFolder(string expected) | ||
{ | ||
expected = expected.AsLinuxPath(); | ||
aspNetSharedFolder.Should().EndWith(expected); | ||
} | ||
} |
This file contains 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 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