From 6b1646ff68155a09724d9f03c6ced500f3cc961c Mon Sep 17 00:00:00 2001 From: guptakashish Date: Thu, 24 Oct 2024 12:47:33 +0530 Subject: [PATCH 01/10] fix(playwrighttesting): Using dependency injection instead of BlobClient in TestProcessor --- .../src/Implementation/BlobService.cs | 47 +++++++++++++++++++ .../src/Interface/IBlobService.cs | 18 +++++++ .../src/Processor/TestProcessor.cs | 24 ++++------ 3 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs new file mode 100644 index 000000000000..793f9b94a903 --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface; +using Azure.Storage.Blobs; +using System.Threading.Tasks; + +namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation +{ + internal class BlobService:IBlobService + { + private readonly ILogger _logger; + + public BlobService(ILogger logger) + { + _logger = logger; + } + + public async Task UploadBufferAsync(string uri, string buffer, string fileRelativePath) + { + try + { + string cloudFilePath = GetCloudFilePath(uri, fileRelativePath); + BlobClient blobClient = new(new Uri(cloudFilePath)); + byte[] bufferBytes = Encoding.UTF8.GetBytes(buffer); + await blobClient.UploadAsync(new BinaryData(bufferBytes), overwrite: true).ConfigureAwait(false); + _logger.Info($"Uploaded buffer to {fileRelativePath}"); + } + catch (Exception ex) + { + _logger.Error($"Failed to upload buffer: {ex}"); + } + } + + private static string GetCloudFilePath(string uri, string fileRelativePath) + { + string[] parts = uri.Split(new string[] { ReporterConstants.s_sASUriSeparator }, StringSplitOptions.None); + string containerUri = parts[0]; + string sasToken = parts.Length > 1 ? parts[1] : string.Empty; + + return $"{containerUri}/{fileRelativePath}?{sasToken}"; + } + } +} diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs new file mode 100644 index 000000000000..6e0b317307d4 --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface +{ + internal interface IBlobService + { + /// + /// + /// + /// + /// + /// + /// A representing the result of the asynchronous operation. + Task UploadBufferAsync(string uri, string buffer, string fileRelativePath); + } +} diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs index db8142ca2a40..254ae32edc5c 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text; using System.Text.Json; +using System.Threading.Tasks; using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation; using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface; using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Model; @@ -28,6 +29,7 @@ internal class TestProcessor : ITestProcessor private readonly IConsoleWriter _consoleWriter; private readonly CIInfo _cIInfo; private readonly CloudRunMetadata _cloudRunMetadata; + private readonly IBlobService _blobService; // Test Metadata internal int TotalTestCount { get; set; } = 0; @@ -39,7 +41,7 @@ internal class TestProcessor : ITestProcessor internal bool FatalTestExecution { get; set; } = false; internal TestRunShardDto? _testRunShard; - public TestProcessor(CloudRunMetadata cloudRunMetadata, CIInfo cIInfo, ILogger? logger = null, IDataProcessor? dataProcessor = null, ICloudRunErrorParser? cloudRunErrorParser = null, IServiceClient? serviceClient = null, IConsoleWriter? consoleWriter = null) + public TestProcessor(CloudRunMetadata cloudRunMetadata, CIInfo cIInfo, ILogger? logger = null, IDataProcessor? dataProcessor = null, ICloudRunErrorParser? cloudRunErrorParser = null, IServiceClient? serviceClient = null, IConsoleWriter? consoleWriter = null, IBlobService? blobService = null) { _cloudRunMetadata = cloudRunMetadata; _cIInfo = cIInfo; @@ -48,6 +50,7 @@ public TestProcessor(CloudRunMetadata cloudRunMetadata, CIInfo cIInfo, ILogger? _cloudRunErrorParser = cloudRunErrorParser ?? new CloudRunErrorParser(_logger); _serviceClient = serviceClient ?? new ServiceClient(_cloudRunMetadata, _cloudRunErrorParser); _consoleWriter = consoleWriter ?? new ConsoleWriter(); + _blobService = blobService ?? new BlobService(_logger); } public void TestRunStartHandler(object? sender, TestRunStartEventArgs e) @@ -166,7 +169,7 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) // Upload rawResult to blob storage using sasUri var rawTestResultJson = JsonSerializer.Serialize(rawResult); var filePath = $"{testResult.TestExecutionId}/rawTestResult.json"; - UploadBuffer(sasUri!.Uri!, rawTestResultJson, filePath); + UploadBuffer(sasUri!.Uri!, rawTestResultJson, filePath); } else { @@ -211,22 +214,11 @@ private void EndTestRun(TestRunCompleteEventArgs e) } _cloudRunErrorParser.DisplayMessages(); } - private static string GetCloudFilePath(string uri, string fileRelativePath) + private void UploadBuffer(string uri, string buffer, string fileRelativePath) { - string[] parts = uri.Split(new string[] { ReporterConstants.s_sASUriSeparator }, StringSplitOptions.None); - string containerUri = parts[0]; - string sasToken = parts.Length > 1 ? parts[1] : string.Empty; - - return $"{containerUri}/{fileRelativePath}?{sasToken}"; - } - private void UploadBuffer(string uri, string buffer, string fileRelativePath) - { - string cloudFilePath = GetCloudFilePath(uri, fileRelativePath); - BlobClient blobClient = new(new Uri(cloudFilePath)); - byte[] bufferBytes = Encoding.UTF8.GetBytes(buffer); - blobClient.Upload(new BinaryData(bufferBytes), overwrite: true); - _logger.Info($"Uploaded buffer to {fileRelativePath}"); + _blobService.UploadBufferAsync(uri, buffer, fileRelativePath); } + private TestRunShardDto GetTestRunEndShard(TestRunCompleteEventArgs e) { DateTime testRunEndedOn = DateTime.UtcNow; From 1d07edf3e266c746e431bb1433958d0e6a978dca Mon Sep 17 00:00:00 2001 From: guptakashish Date: Thu, 24 Oct 2024 15:46:55 +0530 Subject: [PATCH 02/10] update --- .../src/Implementation/BlobService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs index 793f9b94a903..1cd2db290152 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -14,9 +14,9 @@ internal class BlobService:IBlobService { private readonly ILogger _logger; - public BlobService(ILogger logger) + public BlobService(ILogger? logger) { - _logger = logger; + _logger = logger ?? new Logger(); } public async Task UploadBufferAsync(string uri, string buffer, string fileRelativePath) From bb7a7324c42129e75bd318335d30df7e6cf05966 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Thu, 24 Oct 2024 15:47:35 +0530 Subject: [PATCH 03/10] update --- ...loper.MicrosoftPlaywrightTesting.NUnit.sln | 11 +++++++ .../tempSample/PlaywrightTests/.runsettings | 12 +++++++ .../PlaywrightTests/PlaywrightServiceSetup.cs | 7 ++++ .../PlaywrightTests/PlaywrightTests.csproj | 29 ++++++++++++++++ .../tempSample/PlaywrightTests/UnitTest1.cs | 33 +++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln index 840be72bea43..9818602134b8 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests", "tests\Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests.csproj", "{081210F2-A9F8-4137-97F4-5D5EF238B553}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tempSample", "tempSample", "{2FB9C819-42B3-4AF3-A77E-A324AEAA5678}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightTests", "tempSample\PlaywrightTests\PlaywrightTests.csproj", "{66C28F1E-A7DB-4B0E-B65C-61380B420026}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +28,12 @@ Global {081210F2-A9F8-4137-97F4-5D5EF238B553}.Debug|Any CPU.Build.0 = Debug|Any CPU {081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.ActiveCfg = Release|Any CPU {081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.Build.0 = Release|Any CPU + {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {66C28F1E-A7DB-4B0E-B65C-61380B420026} = {2FB9C819-42B3-4AF3-A77E-A324AEAA5678} EndGlobalSection EndGlobal diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings new file mode 100644 index 000000000000..6495d0245679 --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs new file mode 100644 index 000000000000..f4a443477ecf --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs @@ -0,0 +1,7 @@ +using Azure.Developer.MicrosoftPlaywrightTesting.NUnit; +using NUnit.Framework; + +namespace PlaywrightTests; + +[SetUpFixture] +public class PlaywrightServiceSetup : PlaywrightServiceNUnit { }; diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj new file mode 100644 index 000000000000..b607657aaa00 --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs new file mode 100644 index 000000000000..3d8041989e5f --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs @@ -0,0 +1,33 @@ +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Microsoft.Playwright; +using Microsoft.Playwright.NUnit; +using NUnit.Framework; + +namespace PlaywrightTests; + +[Parallelizable(ParallelScope.Self)] +[TestFixture] +public class ExampleTest : PageTest +{ + [Test] + public async Task HasTitle() + { + await Page.GotoAsync("https://playwright.dev"); + + // Expect a title "to contain" a substring. + await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); + } + + [Test] + public async Task GetStartedLink() + { + await Page.GotoAsync("https://playwright.dev"); + + // Click the get started link. + await Page.GetByRole(AriaRole.Link, new() { Name = "Get started" }).ClickAsync(); + + // Expects page to have a heading with the name of Installation. + await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Installation" })).ToBeVisibleAsync(); + } +} From 8db369d1fe7cd832fe0a58b7284c033e012e3895 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Thu, 24 Oct 2024 15:54:53 +0530 Subject: [PATCH 04/10] removed previous commit --- ...loper.MicrosoftPlaywrightTesting.NUnit.sln | 11 ------- .../tempSample/PlaywrightTests/.runsettings | 12 ------- .../PlaywrightTests/PlaywrightServiceSetup.cs | 7 ---- .../PlaywrightTests/PlaywrightTests.csproj | 29 ---------------- .../tempSample/PlaywrightTests/UnitTest1.cs | 33 ------------------- 5 files changed, 92 deletions(-) delete mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings delete mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs delete mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj delete mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln index 9818602134b8..840be72bea43 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/Azure.Developer.MicrosoftPlaywrightTesting.NUnit.sln @@ -7,10 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests", "tests\Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests.csproj", "{081210F2-A9F8-4137-97F4-5D5EF238B553}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tempSample", "tempSample", "{2FB9C819-42B3-4AF3-A77E-A324AEAA5678}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightTests", "tempSample\PlaywrightTests\PlaywrightTests.csproj", "{66C28F1E-A7DB-4B0E-B65C-61380B420026}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,12 +24,5 @@ Global {081210F2-A9F8-4137-97F4-5D5EF238B553}.Debug|Any CPU.Build.0 = Debug|Any CPU {081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.ActiveCfg = Release|Any CPU {081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.Build.0 = Release|Any CPU - {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Debug|Any CPU.Build.0 = Debug|Any CPU - {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Release|Any CPU.ActiveCfg = Release|Any CPU - {66C28F1E-A7DB-4B0E-B65C-61380B420026}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {66C28F1E-A7DB-4B0E-B65C-61380B420026} = {2FB9C819-42B3-4AF3-A77E-A324AEAA5678} EndGlobalSection EndGlobal diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings deleted file mode 100644 index 6495d0245679..000000000000 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/.runsettings +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs deleted file mode 100644 index f4a443477ecf..000000000000 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightServiceSetup.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Azure.Developer.MicrosoftPlaywrightTesting.NUnit; -using NUnit.Framework; - -namespace PlaywrightTests; - -[SetUpFixture] -public class PlaywrightServiceSetup : PlaywrightServiceNUnit { }; diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj deleted file mode 100644 index b607657aaa00..000000000000 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/PlaywrightTests.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - net8.0 - enable - enable - - false - true - - - - - - - - - - - - - - - - - - - - diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs deleted file mode 100644 index 3d8041989e5f..000000000000 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/tempSample/PlaywrightTests/UnitTest1.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Microsoft.Playwright; -using Microsoft.Playwright.NUnit; -using NUnit.Framework; - -namespace PlaywrightTests; - -[Parallelizable(ParallelScope.Self)] -[TestFixture] -public class ExampleTest : PageTest -{ - [Test] - public async Task HasTitle() - { - await Page.GotoAsync("https://playwright.dev"); - - // Expect a title "to contain" a substring. - await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); - } - - [Test] - public async Task GetStartedLink() - { - await Page.GotoAsync("https://playwright.dev"); - - // Click the get started link. - await Page.GetByRole(AriaRole.Link, new() { Name = "Get started" }).ClickAsync(); - - // Expects page to have a heading with the name of Installation. - await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Installation" })).ToBeVisibleAsync(); - } -} From f808edad2147361a128eb789dee9e54f94c414ed Mon Sep 17 00:00:00 2001 From: guptakashish Date: Fri, 25 Oct 2024 12:20:59 +0530 Subject: [PATCH 05/10] added test for bobService --- .../src/Implementation/BlobService.cs | 2 +- .../tests/Implementation/BlobServiceTests.cs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs index 1cd2db290152..1deeb646aa25 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -35,7 +35,7 @@ public async Task UploadBufferAsync(string uri, string buffer, string fileRelati } } - private static string GetCloudFilePath(string uri, string fileRelativePath) + public static string GetCloudFilePath(string uri, string fileRelativePath) { string[] parts = uri.Split(new string[] { ReporterConstants.s_sASUriSeparator }, StringSplitOptions.None); string containerUri = parts[0]; diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs new file mode 100644 index 000000000000..6ec72e092dce --- /dev/null +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text; +using System.Threading.Tasks; +using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation; +using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface; +using Moq; +using NUnit.Framework; + +namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Tests.Implementation +{ + [TestFixture] + [Parallelizable(ParallelScope.Self)] + public class BlobServiceTests + { + private Mock? _loggerMock; + private BlobService? _blobService; + + [SetUp] + public void Setup() + { + _loggerMock = new Mock(); + _blobService = new BlobService(_loggerMock.Object); + } + [Test] + public async Task UploadBufferAsync_WithException_LogsError() + { + string uri = "invalid_uri"; + string buffer = "Test buffer"; + string fileRelativePath = "test/path"; + + await _blobService!.UploadBufferAsync(uri, buffer, fileRelativePath); + + _loggerMock!.Verify(logger => logger.Error(It.IsAny()), Times.Once); + } + + [Test] + public void GetCloudFilePath_WithValidParameters_ReturnsCorrectPath() + { + string uri = "https://example.com/container"; + string fileRelativePath = "test/path"; + string expectedPath = "https://example.com/container/test/path?"; + + string result = BlobService.GetCloudFilePath(uri, fileRelativePath); + + Assert.AreEqual(expectedPath, result); + } + + [Test] + public void GetCloudFilePath_WithSasUri_ReturnsCorrectPath() + { + string uri = "https://example.com/container?sasToken"; + string fileRelativePath = "test/path"; + string expectedPath = "https://example.com/container/test/path?sasToken"; + + string result = BlobService.GetCloudFilePath(uri, fileRelativePath); + + Assert.AreEqual(expectedPath, result); + } + } +} From 847171340248bc875a9272d86205db3333cd7d70 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Fri, 25 Oct 2024 12:58:25 +0530 Subject: [PATCH 06/10] update --- .../src/Interface/IBlobService.cs | 1 + .../src/Processor/TestProcessor.cs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs index 6e0b317307d4..fcaddd57390f 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs @@ -14,5 +14,6 @@ internal interface IBlobService /// /// A representing the result of the asynchronous operation. Task UploadBufferAsync(string uri, string buffer, string fileRelativePath); + string GetCloudFilePath(string uri, string fileRelativePath); } } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs index 5ba1a9f51ded..dbd1a10dc298 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs @@ -278,10 +278,9 @@ private void UploadBuffer(string uri, string buffer, string fileRelativePath) _blobService.UploadBufferAsync(uri, buffer, fileRelativePath); } - private void UploadBlobFile(string uri, string fileRelativePath, string filePath) { - string cloudFilePath = GetCloudFilePath(uri, fileRelativePath); + string cloudFilePath = _blobService.GetCloudFilePath(uri, fileRelativePath); BlobClient blobClient = new(new Uri(cloudFilePath)); // Upload filePath to Blob blobClient.Upload(filePath, overwrite: true); From 16d266b30d7e4019f28d0d0587ffd64344102ce7 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Fri, 25 Oct 2024 13:17:58 +0530 Subject: [PATCH 07/10] update test --- .../src/Implementation/BlobService.cs | 2 +- .../src/Interface/IBlobService.cs | 2 +- .../tests/Implementation/BlobServiceTests.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs index 1deeb646aa25..382b9bb4f2df 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -35,7 +35,7 @@ public async Task UploadBufferAsync(string uri, string buffer, string fileRelati } } - public static string GetCloudFilePath(string uri, string fileRelativePath) + public string GetCloudFilePath(string uri, string fileRelativePath) { string[] parts = uri.Split(new string[] { ReporterConstants.s_sASUriSeparator }, StringSplitOptions.None); string containerUri = parts[0]; diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs index fcaddd57390f..11a68da55e66 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs @@ -14,6 +14,6 @@ internal interface IBlobService /// /// A representing the result of the asynchronous operation. Task UploadBufferAsync(string uri, string buffer, string fileRelativePath); - string GetCloudFilePath(string uri, string fileRelativePath); + string GetCloudFilePath(string uri, string fileRelativePath); } } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs index 6ec72e092dce..eaa6006b8459 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs @@ -42,7 +42,7 @@ public void GetCloudFilePath_WithValidParameters_ReturnsCorrectPath() string fileRelativePath = "test/path"; string expectedPath = "https://example.com/container/test/path?"; - string result = BlobService.GetCloudFilePath(uri, fileRelativePath); + string? result = _blobService?.GetCloudFilePath(uri, fileRelativePath); Assert.AreEqual(expectedPath, result); } @@ -54,7 +54,7 @@ public void GetCloudFilePath_WithSasUri_ReturnsCorrectPath() string fileRelativePath = "test/path"; string expectedPath = "https://example.com/container/test/path?sasToken"; - string result = BlobService.GetCloudFilePath(uri, fileRelativePath); + string? result = _blobService?.GetCloudFilePath(uri, fileRelativePath); Assert.AreEqual(expectedPath, result); } From f5a8805cd482d41eb52805c950832396afd65b0a Mon Sep 17 00:00:00 2001 From: guptakashish Date: Mon, 28 Oct 2024 11:08:46 +0530 Subject: [PATCH 08/10] added test for sas uri. --- .../src/Processor/TestProcessor.cs | 2 +- .../tests/Processor/TestProcessorTests.cs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs index dbd1a10dc298..2df80a5d111f 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs @@ -240,7 +240,7 @@ private void UploadAttachment(TestResultEventArgs e, string testExecutionId) } } - private TestResultsUri? CheckAndRenewSasUri() + public TestResultsUri? CheckAndRenewSasUri() { var reporterUtils = new ReporterUtils(); if (_testResultsSasUri == null || !reporterUtils.IsTimeGreaterThanCurrentPlus10Minutes(_testResultsSasUri.Uri)) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/TestProcessorTests.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/TestProcessorTests.cs index 652f73195b3e..2778c673da27 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/TestProcessorTests.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/TestProcessorTests.cs @@ -580,5 +580,38 @@ public void TestRunCompleteHandler_EnableResultPublishSetToFalse_DisplaysMessage serviceClientMock.Verify(c => c.PostTestRunShardInfo(It.IsAny()), Times.Never); cloudRunErrorParserMock.Verify(c => c.DisplayMessages(), Times.Exactly(1)); } + [Test] + public void CheckAndRenewSasUri_WhenUriExpired_FetchesNewSasUri() + { + var loggerMock = new Mock(); + var dataProcessorMock = new Mock(); + var consoleWriterMock = new Mock(); + var cloudRunErrorParserMock = new Mock(); + var serviceClientMock = new Mock(); + var testProcessor = new TestProcessor(_cloudRunMetadata, _cIInfo, loggerMock.Object, dataProcessorMock.Object, cloudRunErrorParserMock.Object, serviceClientMock.Object, consoleWriterMock.Object); + var expiredTestResultsSasUri = new TestResultsUri { Uri = "http://example.com", ExpiresAt = DateTime.UtcNow.AddMinutes(-5).ToString(), AccessLevel = AccessLevel.Read }; + var newTestResultsSasUri = new TestResultsUri { Uri = "http://newexample.com", ExpiresAt = DateTime.UtcNow.AddHours(1).ToString(), AccessLevel = AccessLevel.Read }; + testProcessor._testResultsSasUri = expiredTestResultsSasUri; + serviceClientMock.Setup(sc => sc.GetTestRunResultsUri()).Returns(newTestResultsSasUri); + TestResultsUri? result = testProcessor.CheckAndRenewSasUri(); + Assert.AreEqual(newTestResultsSasUri, result); + loggerMock.Verify(l => l.Info(It.IsAny()), Times.AtLeastOnce); + } + [Test] + public void CheckAndRenewSasUri_WhenUriNotExpired_DoesNotFetchNewSasUri() + { + var loggerMock = new Mock(); + var dataProcessorMock = new Mock(); + var consoleWriterMock = new Mock(); + var cloudRunErrorParserMock = new Mock(); + var serviceClientMock = new Mock(); + var testProcessor = new TestProcessor(_cloudRunMetadata, _cIInfo, loggerMock.Object, dataProcessorMock.Object, cloudRunErrorParserMock.Object, serviceClientMock.Object, consoleWriterMock.Object); + var validTestResultsSasUri = new TestResultsUri { Uri = "http://example.com?se=" + DateTime.UtcNow.AddMinutes(15).ToString("o"), ExpiresAt = DateTime.UtcNow.AddMinutes(15).ToString(), AccessLevel = AccessLevel.Read }; + testProcessor._testResultsSasUri = validTestResultsSasUri; + TestResultsUri? result = testProcessor.CheckAndRenewSasUri(); + Assert.AreEqual(validTestResultsSasUri, result); + serviceClientMock.Verify(sc => sc.GetTestRunResultsUri(), Times.Never); + loggerMock.Verify(l => l.Info(It.IsAny()), Times.Never); + } } } From eb4ab12b17379b034e6299a9cb23eb152cfa2ae5 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Mon, 28 Oct 2024 12:34:00 +0530 Subject: [PATCH 09/10] updated UploadBlobFile --- .../src/Implementation/BlobService.cs | 8 +++++++- .../src/Interface/IBlobService.cs | 1 + .../src/Processor/TestProcessor.cs | 5 +---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs index 382b9bb4f2df..10dc12c110bb 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -34,7 +34,13 @@ public async Task UploadBufferAsync(string uri, string buffer, string fileRelati _logger.Error($"Failed to upload buffer: {ex}"); } } - + public void UploadBlobFile(string uri, string fileRelativePath, string filePath) + { + string cloudFilePath = GetCloudFilePath(uri, fileRelativePath); + BlobClient blobClient = new(new Uri(cloudFilePath)); + blobClient.Upload(filePath, overwrite: true); + _logger.Info($"Uploaded file {filePath} to {fileRelativePath}"); + } public string GetCloudFilePath(string uri, string fileRelativePath) { string[] parts = uri.Split(new string[] { ReporterConstants.s_sASUriSeparator }, StringSplitOptions.None); diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs index 11a68da55e66..7aab86554719 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs @@ -15,5 +15,6 @@ internal interface IBlobService /// A representing the result of the asynchronous operation. Task UploadBufferAsync(string uri, string buffer, string fileRelativePath); string GetCloudFilePath(string uri, string fileRelativePath); + void UploadBlobFile(string uri, string fileRelativePath, string filePath); } } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs index 2df80a5d111f..30336b81b140 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs @@ -280,10 +280,7 @@ private void UploadBuffer(string uri, string buffer, string fileRelativePath) private void UploadBlobFile(string uri, string fileRelativePath, string filePath) { - string cloudFilePath = _blobService.GetCloudFilePath(uri, fileRelativePath); - BlobClient blobClient = new(new Uri(cloudFilePath)); - // Upload filePath to Blob - blobClient.Upload(filePath, overwrite: true); + _blobService.UploadBlobFile(uri, fileRelativePath, filePath); _logger.Info($"Uploaded file {filePath} to {fileRelativePath}"); } From 53990b7b2b30c02028a3f8c37d0c5f344c9b3002 Mon Sep 17 00:00:00 2001 From: guptakashish Date: Wed, 30 Oct 2024 17:27:22 +0530 Subject: [PATCH 10/10] update --- .../src/Implementation/BlobService.cs | 10 ++++++++++ .../src/Interface/IBlobService.cs | 1 + .../src/Processor/TestProcessor.cs | 18 ++++-------------- .../src/Utility/ReporterUtils.cs | 9 --------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs index 10dc12c110bb..6b436c45f9ff 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs @@ -7,6 +7,7 @@ using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface; using Azure.Storage.Blobs; using System.Threading.Tasks; +using System.IO; namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation { @@ -49,5 +50,14 @@ public string GetCloudFilePath(string uri, string fileRelativePath) return $"{containerUri}/{fileRelativePath}?{sasToken}"; } + public string? GetCloudFileName(string filePath, string testExecutionId) + { + var fileName = Path.GetFileName(filePath); + if (fileName == null) + { + return null; + } + return $"{testExecutionId}/{fileName}"; // TODO check if we need to add {Guid.NewGuid()} for file with same name + } } } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs index 7aab86554719..587903f1418f 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs @@ -16,5 +16,6 @@ internal interface IBlobService Task UploadBufferAsync(string uri, string buffer, string fileRelativePath); string GetCloudFilePath(string uri, string fileRelativePath); void UploadBlobFile(string uri, string fileRelativePath, string filePath); + public string? GetCloudFileName(string filePath, string testExecutionId); } } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs index 30336b81b140..6bf1c260b2a1 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs @@ -174,7 +174,7 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) // Upload rawResult to blob storage using sasUri var rawTestResultJson = JsonSerializer.Serialize(rawResult); var filePath = $"{testResult.TestExecutionId}/rawTestResult.json"; - UploadBuffer(sasUri!.Uri!, rawTestResultJson, filePath); + _blobService.UploadBufferAsync(sasUri!.Uri!, rawTestResultJson, filePath); } else { @@ -218,9 +218,9 @@ private void UploadAttachment(TestResultEventArgs e, string testExecutionId) { // get file size var fileSize = new FileInfo(filePath).Length; - var cloudFileName = ReporterUtils.GetCloudFileName(filePath, testExecutionId); + var cloudFileName = _blobService.GetCloudFileName(filePath, testExecutionId); if (cloudFileName != null) { - UploadBlobFile(_testResultsSasUri!.Uri!, cloudFileName, filePath); + _blobService.UploadBlobFile(_testResultsSasUri!.Uri!, cloudFileName, filePath); TotalArtifactCount++; TotalArtifactSizeInBytes = TotalArtifactSizeInBytes + (int)fileSize; } @@ -240,7 +240,7 @@ private void UploadAttachment(TestResultEventArgs e, string testExecutionId) } } - public TestResultsUri? CheckAndRenewSasUri() + internal TestResultsUri? CheckAndRenewSasUri() { var reporterUtils = new ReporterUtils(); if (_testResultsSasUri == null || !reporterUtils.IsTimeGreaterThanCurrentPlus10Minutes(_testResultsSasUri.Uri)) @@ -273,16 +273,6 @@ private void EndTestRun(TestRunCompleteEventArgs e) } _cloudRunErrorParser.DisplayMessages(); } - private void UploadBuffer(string uri, string buffer, string fileRelativePath) - { - _blobService.UploadBufferAsync(uri, buffer, fileRelativePath); - } - - private void UploadBlobFile(string uri, string fileRelativePath, string filePath) - { - _blobService.UploadBlobFile(uri, fileRelativePath, filePath); - _logger.Info($"Uploaded file {filePath} to {fileRelativePath}"); - } private TestRunShardDto GetTestRunEndShard(TestRunCompleteEventArgs e) { diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Utility/ReporterUtils.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Utility/ReporterUtils.cs index d17aa019b488..40390871d682 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Utility/ReporterUtils.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Utility/ReporterUtils.cs @@ -115,15 +115,6 @@ internal static string GetCurrentOS() else return OSConstants.s_wINDOWS; } - internal static string? GetCloudFileName(string filePath, string testExecutionId) - { - var fileName = Path.GetFileName(filePath); - if (fileName == null) - { - return null; - } - return $"{testExecutionId}/{fileName}"; // TODO check if we need to add {Guid.NewGuid()} for file with same name - } internal TokenDetails ParseWorkspaceIdFromAccessToken(JsonWebTokenHandler? jsonWebTokenHandler, string? accessToken) {