Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add separate ResourceReaderUtility to E2E project because of namespace(#542)

Leendert de Borst1dca845731af
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 @@
<ProjectReference Include="..\..\Databases\AliasServerDb\AliasServerDb.csproj" />
<ProjectReference Include="..\..\Utilities\AliasVault.TotpGenerator\AliasVault.TotpGenerator.csproj" />
<ProjectReference Include="..\AliasVault.IntegrationTests\AliasVault.IntegrationTests.csproj" />
- <ProjectReference Include="..\AliasVault.UnitTests\AliasVault.UnitTests.csproj" />
<ProjectReference Include="..\Server\AliasVault.E2ETests.Client.Server\AliasVault.E2ETests.Client.Server.csproj" />
</ItemGroup>
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 file="ResourceReaderUtility.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.E2ETests.Common;
+
+using System.IO;
+using System.Reflection;
+using System.Threading.Tasks;
+
+/// <summary>
+/// Utility for reading strings from project embedded resources used in tests.
+/// </summary>
+public static class ResourceReaderUtility
+{
+ /// <summary>
+ /// Reads string from embedded resource.
+ /// </summary>
+ /// <param name="resourceName">Name of the embedded resource.</param>
+ /// <returns>Contents of embedded resource as string.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when resource is not found with that name.</exception>
+ public static async Task<string> 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();
+ }
+
+ /// <summary>
+ /// Reads byte array from embedded resource.
+ /// </summary>
+ /// <param name="resourceName">Name of the embedded resource.</param>
+ /// <returns>Contents of embedded resource as byte array.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when resource is not found with that name.</exception>
+ public static async Task<byte[]> 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();
+ }
+
+ /// <summary>
+ /// Get all embedded resource names in current assembly.
+ /// </summary>
+ /// <returns>Array of resource names.</returns>
+ 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;