Skip to content

Commit

Permalink
Extract Aspire.Hosting.Azure.Tests (#5013)
Browse files Browse the repository at this point in the history
Contributes to #4294

This also allows us to remove the Aspire.Hosting.Tests.SharedShim, now that VolumeNameGenerator is only found in Aspire.Hosting.
  • Loading branch information
eerhardt authored Jul 24, 2024
1 parent df935f4 commit 975a9fc
Show file tree
Hide file tree
Showing 32 changed files with 122 additions and 162 deletions.
14 changes: 7 additions & 7 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qdrant.ApiService", "playgr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.EventHubs", "src\Aspire.Hosting.Azure.EventHubs\Aspire.Hosting.Azure.EventHubs.csproj", "{2580B014-E7FE-48D9-BE40-E90604365F0E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Tests.SharedShim", "tests\Aspire.Hosting.Tests.SharedShim\Aspire.Hosting.Tests.SharedShim.csproj", "{74644A4D-8F61-4314-B6E8-5CE3802CD6C2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.KeyVault", "src\Aspire.Hosting.Azure.KeyVault\Aspire.Hosting.Azure.KeyVault.csproj", "{427F4D7C-8969-4015-AD1A-5EFFE921A184}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Qdrant.Client", "src\Components\Aspire.Qdrant.Client\Aspire.Qdrant.Client.csproj", "{E0E1B557-D3CF-4446-B993-E5CE719234FB}"
Expand Down Expand Up @@ -551,6 +549,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Keycloak.Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Keycloak.Authentication.Tests", "tests\Aspire.Keycloak.Authentication.Tests\Aspire.Keycloak.Authentication.Tests.csproj", "{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.Tests", "tests\Aspire.Hosting.Azure.Tests\Aspire.Hosting.Azure.Tests.csproj", "{8691F993-7B19-496E-B8E1-EF1199ACF2E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1269,10 +1269,6 @@ Global
{2580B014-E7FE-48D9-BE40-E90604365F0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2580B014-E7FE-48D9-BE40-E90604365F0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2580B014-E7FE-48D9-BE40-E90604365F0E}.Release|Any CPU.Build.0 = Release|Any CPU
{74644A4D-8F61-4314-B6E8-5CE3802CD6C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74644A4D-8F61-4314-B6E8-5CE3802CD6C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74644A4D-8F61-4314-B6E8-5CE3802CD6C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74644A4D-8F61-4314-B6E8-5CE3802CD6C2}.Release|Any CPU.Build.0 = Release|Any CPU
{427F4D7C-8969-4015-AD1A-5EFFE921A184}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{427F4D7C-8969-4015-AD1A-5EFFE921A184}.Debug|Any CPU.Build.0 = Debug|Any CPU
{427F4D7C-8969-4015-AD1A-5EFFE921A184}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1457,6 +1453,10 @@ Global
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Release|Any CPU.Build.0 = Release|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1669,7 +1669,6 @@ Global
{F43586B8-FE36-490D-9EFA-82CFFB83A304} = {A4800EE3-F902-4B7B-AF53-01A85514E6B9}
{6B6D3953-E961-4720-B27E-9466A69BED1A} = {A4800EE3-F902-4B7B-AF53-01A85514E6B9}
{2580B014-E7FE-48D9-BE40-E90604365F0E} = {77CFE74A-32EE-400C-8930-5025E8555256}
{74644A4D-8F61-4314-B6E8-5CE3802CD6C2} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{427F4D7C-8969-4015-AD1A-5EFFE921A184} = {77CFE74A-32EE-400C-8930-5025E8555256}
{E0E1B557-D3CF-4446-B993-E5CE719234FB} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{A9CFA376-0C90-4231-9152-FBF14065195A} = {C424395C-1235-41A4-BF55-07880A04368C}
Expand Down Expand Up @@ -1725,6 +1724,7 @@ Global
{C556D61C-7E11-43EC-9098-C8D170FEA905} = {EBC55A17-B0D6-4E0A-9DC2-7D264E96F631}
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7} = {C424395C-1235-41A4-BF55-07880A04368C}
{8691F993-7B19-496E-B8E1-EF1199ACF2E1} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.AppConfiguration" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@
<PackageReference Include="Azure.Provisioning.ApplicationInsights" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.CognitiveServices" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@
<PackageReference Include="Azure.Provisioning.CosmosDB" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Azure.Cosmos;

namespace Aspire.Hosting.Azure;

internal static class AzureCosmosDBEmulatorConnectionString
{
public static string Create(int port) => $"AccountKey={CosmosConstants.EmulatorAccountKey};AccountEndpoint=https://127.0.0.1:{port};DisableServerCertificateValidation=True;";
}
5 changes: 0 additions & 5 deletions src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
using Aspire.Hosting.Azure.Cosmos;

namespace Aspire.Hosting;

Expand Down Expand Up @@ -38,7 +37,3 @@ public class AzureCosmosDBResource(string name, Action<ResourceModuleConstruct>
: ReferenceExpression.Create($"{ConnectionString}");
}

internal static class AzureCosmosDBEmulatorConnectionString
{
public static string Create(int port) => $"AccountKey={CosmosConstants.EmulatorAccountKey};AccountEndpoint=https://127.0.0.1:{port};DisableServerCertificateValidation=True;";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.KeyVault" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.OperationalInsights" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@
<PackageReference Include="Azure.Provisioning.PostgreSql" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@
<PackageReference Include="Azure.Provisioning.Redis" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.Search" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.ServiceBus" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
<PackageReference Include="Azure.Provisioning.SignalR" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions src/Aspire.Hosting.Azure.Sql/Aspire.Hosting.Azure.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@
<PackageReference Include="Azure.Provisioning.Sql" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@
<PackageReference Include="Azure.Provisioning.Storage" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Text;

namespace Aspire.Hosting.Azure;

internal static class AzureStorageEmulatorConnectionString
{
// Use defaults from https://learn.microsoft.com/azure/storage/common/storage-configure-connection-string#connect-to-the-emulator-account-using-the-shortcut
private const string ConnectionStringHeader = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;";
private const string BlobEndpointTemplate = "BlobEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";
private const string QueueEndpointTemplate = "QueueEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";
private const string TableEndpointTemplate = "TableEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";

public static string Create(int? blobPort = null, int? queuePort = null, int? tablePort = null)
{
var builder = new StringBuilder(ConnectionStringHeader);

if (blobPort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, BlobEndpointTemplate, blobPort);
}
if (queuePort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, QueueEndpointTemplate, queuePort);
}
if (tablePort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, TableEndpointTemplate, tablePort);
}

return builder.ToString();
}
}
31 changes: 0 additions & 31 deletions src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Text;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Azure;
Expand Down Expand Up @@ -52,32 +50,3 @@ internal ReferenceExpression GetBlobConnectionString() => IsEmulator
? ReferenceExpression.Create($"{AzureStorageEmulatorConnectionString.Create(blobPort: EmulatorBlobEndpoint.Port)}")
: ReferenceExpression.Create($"{BlobEndpoint}");
}

internal static class AzureStorageEmulatorConnectionString
{
// Use defaults from https://learn.microsoft.com/azure/storage/common/storage-configure-connection-string#connect-to-the-emulator-account-using-the-shortcut
private const string ConnectionStringHeader = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;";
private const string BlobEndpointTemplate = "BlobEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";
private const string QueueEndpointTemplate = "QueueEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";
private const string TableEndpointTemplate = "TableEndpoint=http://127.0.0.1:{0}/devstoreaccount1;";

public static string Create(int? blobPort = null, int? queuePort = null, int? tablePort = null)
{
var builder = new StringBuilder(ConnectionStringHeader);

if (blobPort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, BlobEndpointTemplate, blobPort);
}
if (queuePort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, QueueEndpointTemplate, queuePort);
}
if (tablePort is not null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, TableEndpointTemplate, tablePort);
}

return builder.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,4 @@
<PackageReference Include="Azure.Provisioning.WebPubSub" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Aspire.Hosting.Azure/Aspire.Hosting.Azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
<InternalsVisibleTo Include="Aspire.Hosting.Azure.Tests" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Aspire.Hosting.Azure/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace Aspire.Hosting.Azure;

internal class AzureCliNotOnPathException : DistributedApplicationException
internal sealed class AzureCliNotOnPathException : DistributedApplicationException
{
public AzureCliNotOnPathException() { }
public AzureCliNotOnPathException(string message) : base(message) { }
public AzureCliNotOnPathException(string message, Exception inner) : base(message, inner) { }
}

internal class FailedToApplyEnvironmentException : DistributedApplicationException
internal sealed class FailedToApplyEnvironmentException : DistributedApplicationException
{
public FailedToApplyEnvironmentException() { }
public FailedToApplyEnvironmentException(string message) : base(message) { }
Expand Down
31 changes: 31 additions & 0 deletions tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.Redis\Aspire.Hosting.Azure.Redis.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.KeyVault\Aspire.Hosting.Azure.KeyVault.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.CognitiveServices\Aspire.Hosting.Azure.CognitiveServices.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.PostgreSQL\Aspire.Hosting.Azure.PostgreSQL.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.CosmosDB\Aspire.Hosting.Azure.CosmosDB.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.EventHubs\Aspire.Hosting.Azure.EventHubs.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.Storage\Aspire.Hosting.Azure.Storage.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.ServiceBus\Aspire.Hosting.Azure.ServiceBus.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.WebPubSub\Aspire.Hosting.Azure.WebPubSub.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.Sql\Aspire.Hosting.Azure.Sql.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.SignalR\Aspire.Hosting.Azure.SignalR.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.Search\Aspire.Hosting.Azure.Search.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.OperationalInsights\Aspire.Hosting.Azure.OperationalInsights.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.ApplicationInsights\Aspire.Hosting.Azure.ApplicationInsights.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure.AppConfiguration\Aspire.Hosting.Azure.AppConfiguration.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />

<Compile Include="$(RepoRoot)src\Aspire.Hosting.Azure.CosmosDB\AzureCosmosDBEmulatorConnectionString.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Azure.EventHubs\EventHubsEmulatorContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Azure.Storage\AzureStorageEmulatorConnectionString.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Nodes;
using Aspire.Hosting.Azure;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure.Provisioning;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Configuration;
using Xunit;

namespace Aspire.Hosting.Tests.Azure;
namespace Aspire.Hosting.Azure.Tests;

public class AzureBicepProvisionerTests
{
Expand All @@ -32,10 +32,12 @@ public async Task SetParametersTranslatesCompatibleParameterTypes()
{
using var builder = TestDistributedApplicationBuilder.Create();

builder.Configuration["Parameters:param"] = "paramValue";

var connectionStringResource = builder.CreateResourceBuilder(
new ResourceWithConnectionString("A", "connection string"));

var param = builder.AddParameter("param", _ => "paramValue");
var param = builder.AddParameter("param");

var bicep0 = builder.AddBicepTemplateString("bicep0", "param name string")
.WithParameter("name", "john")
Expand Down
Loading

0 comments on commit 975a9fc

Please sign in to comment.