-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPackageNugetTest.cs
More file actions
87 lines (77 loc) · 3.6 KB
/
Copy pathPackageNugetTest.cs
File metadata and controls
87 lines (77 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ----------------------------------------------------------------------
// <copyright file="PackageNugetTest.cs" company="Xavier Solau">
// Copyright © 2021-2026 Xavier Solau.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
// </copyright>
// ----------------------------------------------------------------------
using Shouldly;
using SoloX.CodeQuality.Test.Helpers;
using SoloX.CodeQuality.Test.Helpers.Solution;
namespace SoloX.CodeQuality.Playwright.E2ETest.Package
{
public class PackageNugetTest
{
[Fact]
public void IsShouldDeployNugetPackageAndRunTestWithEmbeddedWebHost()
{
var configurationName = ProbConfiguration();
var root = new RandomGenerator().RandomString(4);
// Let's create a solution in the random root folder.
var solution = new SolutionBuilder(root, "TestSolution")
// Set up the nuget.config to use a dedicated nuget cache and to specify where to get the nuget
// packages we want to test (generated in the same solution).
.WithNugetConfig(@"PkgCache", configuration =>
{
// We want to use the package generated by the projects SoloX.CodeQuality.WebHost and SoloX.CodeQuality.Playwright.
configuration
.UsePackageSources(src =>
{
src.Clear()
.Add(@$"../../../../../../libs/SoloX.CodeQuality.WebHost/bin/{configurationName}")
.Add(@$"../../../../../../libs/SoloX.CodeQuality.Playwright/bin/{configurationName}")
.AddNugetOrg();
});
})
// Set up a xunit project to use the nugets.
.WithProject("TestProject", "xunit", "net10.0", configuration =>
{
configuration
// Configure the package reference on the package to test. In this case SoloX.CodeQuality.Playwright.
.UsePackageReference("SoloX.CodeQuality.Playwright")
.UsePackageReference("Shouldly")
// Add a global using
.UseGlobalUsing("SoloX.CodeQuality.Playwright")
// Create the files
.UseFiles(files =>
{
files
.Remove("UnitTest1.cs")
.Add(
@"../PlaywrightTestBuilderLocalTest.cs",
"PlaywrightTestBuilderLocalTest.cs",
[("SoloX.CodeQuality.Playwright.E2ETest", "TestProject")])
.AddContent(@"../home.html", "home.html", "PreserveNewest");
});
})
// Finally create the solution.
.Build();
try
{
var actBuild = () => solution.Build();
Should.NotThrow(actBuild);
var actTest = () => solution.Test();
Should.NotThrow(actTest);
}
finally
{
Directory.Delete(root, true);
}
}
private static string ProbConfiguration()
{
var location = Path.GetDirectoryName(typeof(PackageNugetTest).Assembly.Location);
return Path.GetFileName(Path.GetDirectoryName(location)!);
}
}
}