Skip to content

Commit 849ba3b

Browse files
committed
test with a .slnx file
1 parent 604fc9d commit 849ba3b

File tree

4 files changed

+96
-60
lines changed

4 files changed

+96
-60
lines changed

src/Ionide.ProjInfo/InspectSln.fs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ module InspectSln =
111111
// for anything else, just use a generic item
112112
match p with
113113
| :? Model.SolutionFolderModel as childFolder -> Some(parseFolder childFolder)
114-
| :? Model.SolutionProjectModel as childProject -> Some(parseProject childProject)
114+
| :? Model.SolutionProjectModel as childProject ->
115+
if
116+
projectsWeCareAbout
117+
|> Seq.exists (
118+
_.Id
119+
>> (=) childProject.Id
120+
)
121+
then
122+
Some(parseProject childProject)
123+
else
124+
None
115125
| _ -> Some(parseItem p)
116126
)
117127
|> List.ofSeq,

test/Ionide.ProjInfo.Tests/TestAssets.fs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,19 @@ let ``sample 15 nuget analyzers`` = {
378378
}
379379

380380
/// A test for a solution with projects
381-
let ``sample 16 solution folders`` = {
381+
let ``sample 16 solution folders (.sln)`` = {
382382
ProjDir = "sample16-solution-with-solution-folders"
383383
AssemblyName = ""
384384
ProjectFile = "sample16-solution-with-solution-folders.sln"
385385
TargetFrameworks = Map.empty
386386
ProjectReferences = []
387387
}
388+
389+
/// and the same with a slnc format solution
390+
let ``sample 16 solution folders (.slnx)`` = {
391+
ProjDir = "sample16-solution-with-solution-folders"
392+
AssemblyName = ""
393+
ProjectFile = "sample16-solution-with-solution-folders.slnx"
394+
TargetFrameworks = Map.empty
395+
ProjectReferences = []
396+
}

test/Ionide.ProjInfo.Tests/Tests.fs

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,66 +2397,71 @@ let sample15NugetAnalyzers toolsPath loaderType workspaceFactory =
23972397

23982398
)
23992399

2400-
/// A test that we can load a solution that contains projects inside solution folders, and get the expected structure
2401-
let sample16SolutionFoldersTest toolsPath loaderType workspaceFactory =
2402-
testCase
2403-
$"Can load sample16 solution folders test - {loaderType}"
2404-
(fun () ->
2405-
2406-
let projPath = pathForProject ``sample 16 solution folders``
2407-
let slnDir = Path.GetDirectoryName projPath
2408-
2409-
let solutionContents =
2410-
InspectSln.tryParseSln projPath
2411-
|> getResult
2400+
/// Common code for sample16SolutionFoldersSlnTest/sample16SolutionFoldersSlnxTest - they are the same test, but for both /sln/slnx files
2401+
let sample16SolutionFoldersTest testAsset =
2402+
2403+
let projPath = pathForProject testAsset
2404+
let slnDir = Path.GetDirectoryName projPath
2405+
2406+
let solutionContents =
2407+
InspectSln.tryParseSln projPath
2408+
|> getResult
2409+
2410+
let solutionData = solutionContents
2411+
2412+
// There should be 3 items at the solution level - build.fsproj, a 'src' folder and a 'tests' folder
2413+
Expect.equal solutionData.Items.Length 3 "There should be 3 items in the solution"
2414+
2415+
// The first item should be "build.fsproj
2416+
let firstItem = solutionData.Items[0]
2417+
let expectedBuildProjectPath = Path.Combine(slnDir, "build.fsproj")
2418+
Expect.equal firstItem.Name expectedBuildProjectPath "Should have the expected build project path"
2419+
2420+
match firstItem.Kind with
2421+
| InspectSln.MSBuildFormat items -> Expect.isEmpty items "we don't currently store anything here"
2422+
| unexpected -> failtestf "Expected a project, but got %A" unexpected
2423+
2424+
// The second item should be the 'src' folder, which should contain proj1.fsproj
2425+
let secondItem = solutionData.Items[1]
2426+
Expect.equal secondItem.Name "src" "Should have the src folder"
2427+
2428+
match secondItem.Kind with
2429+
| InspectSln.Folder(solutionItems, _) ->
2430+
match solutionItems with
2431+
| [ {
2432+
Name = folderName
2433+
Kind = InspectSln.MSBuildFormat []
2434+
} ] ->
2435+
let expectedProjectPath = Path.Combine(slnDir, "src", "proj1", "proj1.fsproj")
2436+
Expect.equal folderName expectedProjectPath "Should have the expected project path"
2437+
| _ -> failtestf "Expected one folder item, but got %A" solutionItems
2438+
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
2439+
2440+
// The third item should be the 'src' folder, which should contain proj1.fsproj
2441+
let thirdItem = solutionData.Items[2]
2442+
Expect.equal thirdItem.Name "tests" "Should have the tests folder"
2443+
2444+
match thirdItem.Kind with
2445+
| InspectSln.Folder(solutionItems, _) ->
2446+
match solutionItems with
2447+
| [ {
2448+
Name = folderName
2449+
Kind = InspectSln.MSBuildFormat []
2450+
} ] ->
2451+
let expectedProjectPath = Path.Combine(slnDir, "test", "proj1.tests", "proj1.tests.fsproj")
2452+
Expect.equal folderName expectedProjectPath "Should have the expected test project path"
2453+
| _ -> failtestf "Expected one folder item, but got %A" solutionItems
2454+
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
24122455

2413-
let solutionData = solutionContents
2456+
/// A test that we can load a solution that contains projects inside solution folders, and get the expected structure
2457+
let sample16SolutionFoldersSlnTest toolsPath loaderType workspaceFactory =
24142458

2415-
// There should be 3 items at the solution level - build.fsproj, a 'src' folder and a 'tests' folder
2416-
Expect.equal solutionData.Items.Length 3 "There should be 3 items in the solution"
2459+
testCase $"Can load sample16 solution folders test (.sln) - {loaderType}" (fun () -> sample16SolutionFoldersTest ``sample 16 solution folders (.sln)``)
24172460

2418-
// The first item should be "build.fsproj
2419-
let firstItem = solutionData.Items[0]
2420-
let expectedBuildProjectPath = Path.Combine(slnDir, "build.fsproj")
2421-
Expect.equal firstItem.Name expectedBuildProjectPath "Should have the expected build project path"
2422-
2423-
match firstItem.Kind with
2424-
| InspectSln.MSBuildFormat items -> Expect.isEmpty items "we don't currently store anything here"
2425-
| unexpected -> failtestf "Expected a project, but got %A" unexpected
2426-
2427-
// The second item should be the 'src' folder, which should contain proj1.fsproj
2428-
let secondItem = solutionData.Items[1]
2429-
Expect.equal secondItem.Name "src" "Should have the src folder"
2430-
2431-
match secondItem.Kind with
2432-
| InspectSln.Folder(solutionItems, _) ->
2433-
match solutionItems with
2434-
| [ {
2435-
Name = folderName
2436-
Kind = InspectSln.MSBuildFormat []
2437-
} ] ->
2438-
let expectedProjectPath = Path.Combine(slnDir, "src", "proj1", "proj1.fsproj")
2439-
Expect.equal folderName expectedProjectPath "Should have the expected project path"
2440-
| _ -> failtestf "Expected one folder item, but got %A" solutionItems
2441-
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
2442-
2443-
// The third item should be the 'src' folder, which should contain proj1.fsproj
2444-
let thirdItem = solutionData.Items[2]
2445-
Expect.equal thirdItem.Name "tests" "Should have the tests folder"
2446-
2447-
match thirdItem.Kind with
2448-
| InspectSln.Folder(solutionItems, _) ->
2449-
match solutionItems with
2450-
| [ {
2451-
Name = folderName
2452-
Kind = InspectSln.MSBuildFormat []
2453-
} ] ->
2454-
let expectedProjectPath = Path.Combine(slnDir, "test", "proj1.tests", "proj1.tests.fsproj")
2455-
Expect.equal folderName expectedProjectPath "Should have the expected test project path"
2456-
| _ -> failtestf "Expected one folder item, but got %A" solutionItems
2457-
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
2458-
)
2461+
/// As above, but for a .slnx format solution
2462+
let sample16SolutionFoldersSlnxTest toolsPath loaderType workspaceFactory =
24592463

2464+
testCase $"Can load sample16 solution folders test (.slnx) - {loaderType}" (fun () -> sample16SolutionFoldersTest ``sample 16 solution folders (.slnx)``)
24602465

24612466
let tests toolsPath =
24622467
let testSample3WorkspaceLoaderExpected = [
@@ -2600,6 +2605,9 @@ let tests toolsPath =
26002605
sample15NugetAnalyzers toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
26012606
sample15NugetAnalyzers toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
26022607

2603-
sample16SolutionFoldersTest toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
2604-
sample16SolutionFoldersTest toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
2608+
sample16SolutionFoldersSlnTest toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
2609+
sample16SolutionFoldersSlnTest toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
2610+
2611+
sample16SolutionFoldersSlnxTest toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
2612+
sample16SolutionFoldersSlnxTest toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
26052613
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Solution>
2+
<Folder Name="/src/">
3+
<Project Path="src/proj1/proj1.fsproj" />
4+
</Folder>
5+
<Folder Name="/tests/">
6+
<Project Path="test/proj1.tests/proj1.tests.fsproj" />
7+
</Folder>
8+
<Project Path="build.fsproj" />
9+
</Solution>

0 commit comments

Comments
 (0)