Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 04cd23e

Browse files
committedOct 8, 2024·
Added sample build logic to test
1 parent 9490e6e commit 04cd23e

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed
 

‎UiTests/AnyOrgOrPersonalUiTest/AnyOrgOrPersonalTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
6161
try
6262
{
6363
// Build the sample app with correct appsettings file.
64-
UiTestHelpers.BuildSampleWithTestAppsettings(_testAssemblyLocation, _sampleAppPath, _testAppsettingsPath, SampleSlnFileName);
64+
UiTestHelpers.BuildSampleUsingTestAppsettings(_testAssemblyLocation, _sampleAppPath, _testAppsettingsPath, SampleSlnFileName);
6565

6666
// Start the web app and api processes.
6767
// The delay before starting client prevents transient devbox issue where the client fails to load the first time after rebuilding

‎UiTests/B2CUiTest/B2CUiTest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ public class B2CUiTest : IClassFixture<InstallPlaywrightBrowserFixture>
2424
private const string KeyvaultClientSecretName = "IdWeb-B2C-Client-ClientSecret";
2525
private const string NameOfUser = "unknown";
2626
private const uint ProcessStartupRetryNum = 3;
27+
private const string SampleSolutionFileName = "4-2-B2C-Secured-API.sln";
2728
private const uint TodoListClientPort = 5000;
2829
private const uint TodoListServicePort = 44332;
2930
private const string TraceClassName = "B2C-Login";
31+
3032
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
31-
private readonly string _sampleClientAppPath = Path.Join("4-WebApp-your-API", "4-2-B2C", TC.s_todoListClientPath);
32-
private readonly string _sampleServiceAppPath = Path.Join("4-WebApp-your-API", "4-2-B2C", TC.s_todoListServicePath);
33+
private readonly string _sampleClientAppPath;
34+
private readonly string _samplePath = Path.Join("4-WebApp-your-API", "4-2-B2C");
35+
private readonly string _sampleServiceAppPath;
3336
private readonly Uri _keyvaultUri = new("https://webappsapistests.vault.azure.net");
3437
private readonly ITestOutputHelper _output;
3538
private readonly string _testAssemblyLocation = typeof(B2CUiTest).Assembly.Location;
3639

3740
public B2CUiTest(ITestOutputHelper output)
3841
{
3942
_output = output;
43+
_sampleClientAppPath = Path.Join(_samplePath, TC.s_todoListClientPath);
44+
_sampleServiceAppPath = Path.Join(_samplePath, TC.s_todoListServicePath);
4045
}
4146

4247
[Fact]
@@ -72,6 +77,8 @@ public async Task B2C_ValidCreds_LoginLogout()
7277

7378
try
7479
{
80+
UiTestHelpers.BuildSampleUsingSampleAppsettings(_testAssemblyLocation, _samplePath, SampleSolutionFileName);
81+
7582
// Start the web app and api processes.
7683
// The delay before starting client prevents transient devbox issue where the client fails to load the first time after rebuilding.
7784
var clientProcessOptions = new ProcessStartOptions(_testAssemblyLocation, _sampleClientAppPath, TC.s_todoListClientExe, clientEnvVars); // probs need to add client specific path

‎UiTests/Common/UiTestHelpers.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private static string GetApplicationWorkingDirectory(string testAssemblyLocation
235235
/// <param name="testAssemblyLocation">The path to the test's directory</param>
236236
/// <param name="appLocation">The path to the processes directory</param>
237237
/// <returns>The path to the directory for the given app</returns>
238-
private static string GetAppsettingsDirectory(string testAssemblyLocation, string appLocation)
238+
private static string GetAbsoluteAppDirectory(string testAssemblyLocation, string appLocation)
239239
{
240240
string testedAppLocation = Path.GetDirectoryName(testAssemblyLocation)!;
241241
// e.g. microsoft-identity-web\tests\E2E Tests\WebAppUiTests\bin\Debug\net6.0
@@ -528,7 +528,7 @@ private static void BuildSolution(string solutionPath)
528528
process.WaitForExit();
529529
}
530530

531-
Console.WriteLine("Solution rebuild initiated.");
531+
Console.WriteLine("Solution build initiated.");
532532
}
533533

534534
/// <summary>
@@ -538,23 +538,29 @@ private static void BuildSolution(string solutionPath)
538538
/// <param name="sampleRelPath">Relative path to the sample app to build starting at the repo's root, does not include appsettings filename</param>
539539
/// <param name="testAppsettingsRelPath">Relative path to the test appsettings file starting at the repo's root, includes appsettings filename</param>
540540
/// <param name="solutionFileName">Filename for the sln file to build</param>
541-
public static void BuildSampleWithTestAppsettings(
541+
public static void BuildSampleUsingTestAppsettings(
542542
string testAssemblyLocation,
543543
string sampleRelPath,
544544
string testAppsettingsRelPath,
545545
string solutionFileName
546546
)
547547
{
548-
string appsettingsDirectory = GetAppsettingsDirectory(testAssemblyLocation, sampleRelPath);
548+
string appsettingsDirectory = GetAbsoluteAppDirectory(testAssemblyLocation, sampleRelPath);
549549
string appsettingsAbsPath = Path.Combine(appsettingsDirectory, TestConstants.AppSetttingsDotJson);
550-
string testAppsettingsAbsPath = GetAppsettingsDirectory(testAssemblyLocation, testAppsettingsRelPath);
550+
string testAppsettingsAbsPath = GetAbsoluteAppDirectory(testAssemblyLocation, testAppsettingsRelPath);
551551

552552
SwapFiles(appsettingsAbsPath, testAppsettingsAbsPath);
553553

554-
try { BuildSolution(appsettingsDirectory + solutionFileName); }
554+
try { BuildSolution(Path.Combine(appsettingsDirectory, solutionFileName)); }
555555
catch (Exception) { throw; }
556556
finally { SwapFiles(appsettingsAbsPath, testAppsettingsAbsPath); }
557557
}
558+
559+
public static void BuildSampleUsingSampleAppsettings(string testAssemblyLocation, string sampleRelPath, string solutionFileName)
560+
{
561+
string appsDirectory = GetAbsoluteAppDirectory(testAssemblyLocation, sampleRelPath);
562+
BuildSolution(Path.Combine(appsDirectory, solutionFileName));
563+
}
558564
}
559565

560566
/// <summary>

0 commit comments

Comments
 (0)
Please sign in to comment.