Skip to content

Commit 02d5dc0

Browse files
committed
Added building sample to test
1 parent 2e29cf0 commit 02d5dc0

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"AzureAd": {
33
"Instance": "https://login.microsoftonline.com/",
44
"Domain": "[Enter the domain of your tenant, e.g. contoso.onmicrosoft.com]",

UiTests/AnyOrgOrPersonalUiTest/AnyOrgOrPersonalTest.cs

+5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public class AnyOrgOrPersonalTest : IClassFixture<InstallPlaywrightBrowserFixtur
2424
private const uint ClientPort = 44321;
2525
private const string TraceFileClassName = "OpenIDConnect";
2626
private const uint NumProcessRetries = 3;
27+
private const string SampleSlnFileName = "1-3-AnyOrgOrPersonal.sln";
2728
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
2829
private readonly string _sampleAppPath = "1-WebApp-OIDC" + Path.DirectorySeparatorChar + "1-3-AnyOrgOrPersonal" + Path.DirectorySeparatorChar.ToString();
30+
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "AnyOrgOrPersonalUiTest" + Path.DirectorySeparatorChar.ToString() + TC.AppSetttingsDotJson;
2931
private readonly string _testAssemblyLocation = typeof(AnyOrgOrPersonalTest).Assembly.Location;
3032
private readonly ITestOutputHelper _output;
3133

@@ -58,6 +60,9 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
5860

5961
try
6062
{
63+
// Build the sample app with correct appsettings file.
64+
UiTestHelpers.BuildSampleWithTestAppsettings(_testAssemblyLocation, _sampleAppPath, _testAppsettingsPath, SampleSlnFileName);
65+
6166
// Start the web app and api processes.
6267
// The delay before starting client prevents transient devbox issue where the client fails to load the first time after rebuilding
6368
var clientProcessOptions = new ProcessStartOptions(_testAssemblyLocation, _sampleAppPath, TC.s_oidcWebAppExe, clientEnvVars);

UiTests/AnyOrgOrPersonalUiTest/AnyOrgOrPersonalUiTest.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
<ItemGroup>
2828
<ProjectReference Include="..\Common\Common.csproj" />
29-
<ProjectReference Include="..\..\1-WebApp-OIDC\1-3-AnyOrgOrPersonal\WebApp-OpenIDConnect-DotNet.csproj" />
3029
</ItemGroup>
3130

3231
</Project>

UiTests/Common/UiTestHelpers.cs

+23-21
Original file line numberDiff line numberDiff line change
@@ -454,37 +454,32 @@ public static string GetRunningProcessAsString(Dictionary<string, Process>? proc
454454
/// </summary>
455455
/// <param name="path1">The path of the first file to swap</param>
456456
/// <param name="path2">The path of the file to swap it with</param>
457-
public static void SwapFiles(string path1, string path2)
457+
private static void SwapFiles(string path1, string path2)
458458
{
459-
string tempFile = Path.GetTempFileName();
460-
string file1Name = Path.GetFileName(path1);
461-
string file2Name = Path.GetFileName(path2);
462-
string file1Dir = Path.GetDirectoryName(path1);
463-
string file2Dir = Path.GetDirectoryName(path2);
459+
// Read the contents of both files
460+
string file1Contents = File.ReadAllText(path1);
461+
string file2Contents = File.ReadAllText(path2);
464462

465-
// Move file1 to tempFile
466-
File.Move(path1, tempFile);
463+
// Write the contents of file2 to file1
464+
File.WriteAllText(path1, file2Contents);
467465

468-
// Move file2 to file1's original location and rename it to file1's name
469-
File.Move(path2, Path.Combine(file1Dir, file1Name));
466+
// Write the contents of file1 to file2
467+
File.WriteAllText(path2, file1Contents);
470468

471-
// Move tempFile (original file1) to file2's original location and rename it to file2's name
472-
File.Move(tempFile, Path.Combine(file2Dir, file2Name));
473-
474-
Console.WriteLine("Files swapped and renamed successfully.");
469+
Console.WriteLine("File contents swapped successfully.");
475470
}
476471

477472

478-
public static void RebuildSolution(string solutionPath)
473+
private static void RebuildSolution(string solutionPath)
479474
{
480475
ProcessStartInfo startInfo = new ProcessStartInfo
481476
{
482477
FileName = "dotnet",
483-
Arguments = $"build {solutionPath} --no-incremental",
478+
Arguments = $"build {solutionPath}",
484479
RedirectStandardOutput = true,
485480
RedirectStandardError = true,
486481
UseShellExecute = false,
487-
CreateNoWindow = true
482+
CreateNoWindow = false
488483
};
489484

490485
using (Process process = new Process())
@@ -502,15 +497,22 @@ public static void RebuildSolution(string solutionPath)
502497
Console.WriteLine("Solution rebuild initiated.");
503498
}
504499

505-
public static void BuildSampleWithTestAppsettings(string testAssemblyLocation, string appLocation, string testAppsettingsName)
500+
public static void BuildSampleWithTestAppsettings(
501+
string testAssemblyLocation,
502+
string appLocation,
503+
string testAppsettingsPathFromRepoRoot,
504+
string solutionFileName
505+
)
506506
{
507507
string appsettingsDirectory = GetAppsettingsDirectory(testAssemblyLocation, appLocation);
508508
string appsettingsPath = Path.Combine(appsettingsDirectory, TestConstants.AppSetttingsDotJson);
509-
string testAppsettingsPath = Path.Combine(appsettingsDirectory, testAppsettingsName);
510-
SwapFiles(appsettingsPath, testAppsettingsPath);
511-
RebuildSolution(appsettingsDirectory);
509+
string testAppsettingsPath = GetAppsettingsDirectory(testAssemblyLocation, testAppsettingsPathFromRepoRoot);
510+
512511
SwapFiles(appsettingsPath, testAppsettingsPath);
513512

513+
try { RebuildSolution(appsettingsDirectory + solutionFileName); }
514+
catch (Exception) { throw; }
515+
finally { SwapFiles(appsettingsPath, testAppsettingsPath); }
514516
}
515517
}
516518

0 commit comments

Comments
 (0)