diff --git a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj index b41e8e066..ac49b78d3 100644 --- a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj +++ b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj @@ -53,7 +53,6 @@ - diff --git a/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs b/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs new file mode 100644 index 000000000..ef477aac0 --- /dev/null +++ b/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs @@ -0,0 +1,68 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) lanedirt. All rights reserved. +// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. +// +//----------------------------------------------------------------------- + +namespace AliasVault.E2ETests.Common; + +using System.IO; +using System.Reflection; +using System.Threading.Tasks; + +/// +/// Utility for reading strings from project embedded resources used in tests. +/// +public static class ResourceReaderUtility +{ + /// + /// Reads string from embedded resource. + /// + /// Name of the embedded resource. + /// Contents of embedded resource as string. + /// Thrown when resource is not found with that name. + public static async Task ReadEmbeddedResourceStringAsync(string resourceName) + { + var assembly = Assembly.GetExecutingAssembly(); + + using var stream = assembly.GetManifestResourceStream(resourceName); + if (stream == null) + { + throw new InvalidOperationException($"Resource {resourceName} not found in {assembly.FullName}"); + } + + using var reader = new StreamReader(stream); + return await reader.ReadToEndAsync(); + } + + /// + /// Reads byte array from embedded resource. + /// + /// Name of the embedded resource. + /// Contents of embedded resource as byte array. + /// Thrown when resource is not found with that name. + public static async Task ReadEmbeddedResourceBytesAsync(string resourceName) + { + var assembly = Assembly.GetExecutingAssembly(); + + using var stream = assembly.GetManifestResourceStream(resourceName); + if (stream == null) + { + throw new InvalidOperationException($"Resource {resourceName} not found in {assembly.FullName}"); + } + + using var memoryStream = new MemoryStream(); + await stream.CopyToAsync(memoryStream); + return memoryStream.ToArray(); + } + + /// + /// Get all embedded resource names in current assembly. + /// + /// Array of resource names. + public static string[] GetEmbeddedResourceNames() + { + return Assembly.GetExecutingAssembly().GetManifestResourceNames(); + } +} diff --git a/src/Tests/AliasVault.E2ETests/GlobalUsings.cs b/src/Tests/AliasVault.E2ETests/GlobalUsings.cs index daf329076..b1edd5b09 100644 --- a/src/Tests/AliasVault.E2ETests/GlobalUsings.cs +++ b/src/Tests/AliasVault.E2ETests/GlobalUsings.cs @@ -9,6 +9,5 @@ global using System.Threading.Tasks; global using AliasVault.E2ETests.Infrastructure; global using AliasVault.E2ETests.Common; -global using AliasVault.UnitTests.Common; global using NUnit.Framework; global using Microsoft.Playwright;