Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions AzureSearchEmulator.Aspire.DemoAppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var builder = DistributedApplication.CreateBuilder(args);

// For local development and testing, we add an Azure Search Emulator instance based on the project directly
builder.AddProject<Projects.AzureSearchEmulator>("emulator-project")
.WithExternalHttpEndpoints();

// Example container usage via F23.Aspire.Hosting.AzureSearchEmulator
builder.AddAzureSearchEmulator("emulator-container")
.WithIndexesVolume();

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Aspire.AppHost.Sdk/13.0.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>e92d4b6e-a95b-491f-9fe2-8c8ecb4be28f</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AzureSearchEmulator.Aspire\AzureSearchEmulator.Aspire.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\AzureSearchEmulator\AzureSearchEmulator.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17078;http://localhost:15216",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21046",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23199",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22069"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15216",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19291",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18104",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20178"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions AzureSearchEmulator.Aspire.DemoAppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AzureSearchEmulator.Aspire\AzureSearchEmulator.Aspire.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using F23.Aspire.Hosting.AzureSearchEmulator;

namespace AzureSearchEmulator.Aspire.Tests;

public class AzureSearchEmulatorResourceExtensionsTests
{
[Fact]
public async Task AddAzureSearchEmulator_ShouldAddResourceToBuilder()
{
// Arrange
var builder = DistributedApplication.CreateBuilder();
const string resourceName = "my-emulator";

// Act
var resource = builder.AddAzureSearchEmulator(resourceName);

// Assert
Assert.NotNull(resource);
Assert.Equal(resourceName, resource.Resource.Name);
Assert.Contains(resource.Resource, builder.Resources.ToList());

var http = resource.Resource.GetEndpoint("http");
Assert.NotNull(http);
Assert.Equal(AzureSearchEmulatorResource.DefaultHttpPort, http.TargetPort);
Assert.Equal("http", http.Scheme);

var https = resource.Resource.GetEndpoint("https");
Assert.NotNull(https);
Assert.Equal(AzureSearchEmulatorResource.DefaultHttpsPort, https.TargetPort);
Assert.Equal("https", https.Scheme);

var envVars = await resource.Resource.GetEnvironmentVariableValuesAsync();
Assert.True(envVars.ContainsKey("ASPNETCORE_URLS"));
}

[InlineData(false)]
[InlineData(true)]
[Theory]
public void WithIndexesVolume_ShouldAddVolumeToResource(bool isReadOnly)
{
// Arrange
var builder = DistributedApplication.CreateBuilder();
var resourceBuilder = builder.AddAzureSearchEmulator("my-emulator");

// Act
var updatedBuilder = resourceBuilder.WithIndexesVolume(isReadOnly: isReadOnly);

// Assert
Assert.NotNull(updatedBuilder);

if (!updatedBuilder.Resource.TryGetAnnotationsOfType<ContainerMountAnnotation>(out var mountAnnotations))
{
Assert.Fail("No mount annotations found on the resource.");
}

var mount = mountAnnotations.FirstOrDefault(ma => ma.Target == "/app/indexes");
Assert.NotNull(mount);
Assert.Equal(isReadOnly, mount.IsReadOnly);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using F23.Aspire.Hosting.AzureSearchEmulator;

namespace AzureSearchEmulator.Aspire.Tests;

public class AzureSearchEmulatorResourceTests
{
[Fact]
public void Constructor_InitializesResourceProperly()
{
// Arrange
const string name = "my-emulator";

// Act
var resource = new AzureSearchEmulatorResource(name);

// Assert
Assert.Equal(name, resource.Name);
}
}
39 changes: 39 additions & 0 deletions AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>F23.Aspire.Hosting.AzureSearchEmulator</RootNamespace>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>14</LangVersion>
<PackageId>F23.Aspire.Hosting.AzureSearchEmulator</PackageId>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<RepositoryUrl>https://github.com/feature23/azuresearchemulator</RepositoryUrl>
<PackageTags>azure search emulator ai hosting docker</PackageTags>
<Description>Azure Search Emulator hosting support for Aspire.</Description>
<IsPackable>true</IsPackable>
<Version>1.0.0-beta</Version>
<Company>feature[23]</Company>
<Copyright>Copyright (c) feature[23] 2025</Copyright>
<Authors>Paul Irwin</Authors>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="13.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="../logo.png" Pack="true" PackagePath="\" />
<None Include="../README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions AzureSearchEmulator.Aspire/AzureSearchEmulatorResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Aspire.Hosting.ApplicationModel;

namespace F23.Aspire.Hosting.AzureSearchEmulator;

public class AzureSearchEmulatorResource(string name) : ContainerResource(name)
{
public const int DefaultHttpPort = 5100;
public const int DefaultHttpsPort = 5143;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Aspire.Hosting.ApplicationModel;
using F23.Aspire.Hosting.AzureSearchEmulator;

// ReSharper disable once CheckNamespace
namespace Aspire.Hosting;

/// <summary>
/// Extension methods for adding and configuring Azure Search Emulator resources in Aspire.
/// </summary>
public static class AzureSearchEmulatorResourceExtensions
{
extension(IDistributedApplicationBuilder builder)
{
/// <summary>
/// Adds an Azure Search Emulator container resource to the distributed application.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="httpPort">An optional HTTP port. If null, will use a generated port number.</param>
/// <param name="httpsPort">An optional HTTPS port. If null, will use a generated port number.</param>
/// <returns>A resource builder for further configuration.</returns>
/// <remarks>
/// It is recommended to configure a volume for persisting index data using
/// <see cref="WithIndexesVolume"/>.
/// You can also override the default image tag ("latest") by using the returned resource builder's
/// <see cref="ContainerResourceBuilderExtensions.WithImageTag{T}"/> method.
/// </remarks>
public IResourceBuilder<AzureSearchEmulatorResource> AddAzureSearchEmulator(string name,
int? httpPort = null,
int? httpsPort = null)
{
var resource = new AzureSearchEmulatorResource(name);

var resourceBuilder = builder.AddResource(resource)
.WithImage("feature23/azuresearchemulator")
.WithImageTag("latest")
.WithImageRegistry("ghcr.io")
.WithHttpEndpoint(port: httpPort, targetPort: AzureSearchEmulatorResource.DefaultHttpPort, env: "HTTP_PORTS")
.WithHttpsEndpoint(port: httpsPort, targetPort: AzureSearchEmulatorResource.DefaultHttpsPort, env: "HTTPS_PORTS")
.WithEnvironment("ASPNETCORE_URLS", $"https://+:{resource.GetEndpoint("https").Property(EndpointProperty.Port)};http://+:{resource.GetEndpoint("http").Property(EndpointProperty.Port)}")
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", "password")
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", "/app/aspnetapp.pfx");

return resourceBuilder;
}
}

extension(IResourceBuilder<AzureSearchEmulatorResource> builder)
{
/// <summary>
/// Configures a volume for persisting Azure Search index data.
/// </summary>
/// <param name="volumeName">Optional name for the volume. If null, a name will be generated.</param>
/// <param name="isReadOnly">Indicates whether the volume should be mounted as read-only.</param>
/// <returns>The resource builder for further configuration.</returns>
public IResourceBuilder<AzureSearchEmulatorResource> WithIndexesVolume(string? volumeName = null, bool isReadOnly = false)
{
return builder.WithVolume(
name: volumeName ?? VolumeNameGenerator.Generate(builder, "indexes"),
target: "/app/indexes",
isReadOnly: isReadOnly);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<IsTestProject>true</IsTestProject>
<WarningsAsErrors>nullable</WarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions AzureSearchEmulator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureSearchEmulator.Integra
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DebugClient", "DebugClient\DebugClient.csproj", "{787C4AEB-D46D-472F-9BC5-10857FEF2A05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureSearchEmulator.Aspire", "AzureSearchEmulator.Aspire\AzureSearchEmulator.Aspire.csproj", "{D0B85C5F-2B49-4D93-BCDA-7D33E6CC1E05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureSearchEmulator.Aspire.DemoAppHost", "AzureSearchEmulator.Aspire.DemoAppHost\AzureSearchEmulator.Aspire.DemoAppHost.csproj", "{D771EC01-A785-4B7F-AC50-A86D2E281210}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureSearchEmulator.Aspire.Tests", "AzureSearchEmulator.Aspire.Tests\AzureSearchEmulator.Aspire.Tests.csproj", "{EDF10963-768B-426B-B4E2-F2C1DBC2C47C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +33,18 @@ Global
{787C4AEB-D46D-472F-9BC5-10857FEF2A05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{787C4AEB-D46D-472F-9BC5-10857FEF2A05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{787C4AEB-D46D-472F-9BC5-10857FEF2A05}.Release|Any CPU.Build.0 = Release|Any CPU
{D0B85C5F-2B49-4D93-BCDA-7D33E6CC1E05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0B85C5F-2B49-4D93-BCDA-7D33E6CC1E05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0B85C5F-2B49-4D93-BCDA-7D33E6CC1E05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0B85C5F-2B49-4D93-BCDA-7D33E6CC1E05}.Release|Any CPU.Build.0 = Release|Any CPU
{D771EC01-A785-4B7F-AC50-A86D2E281210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D771EC01-A785-4B7F-AC50-A86D2E281210}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D771EC01-A785-4B7F-AC50-A86D2E281210}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D771EC01-A785-4B7F-AC50-A86D2E281210}.Release|Any CPU.Build.0 = Release|Any CPU
{EDF10963-768B-426B-B4E2-F2C1DBC2C47C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDF10963-768B-426B-B4E2-F2C1DBC2C47C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDF10963-768B-426B-B4E2-F2C1DBC2C47C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDF10963-768B-426B-B4E2-F2C1DBC2C47C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions AzureSearchEmulator/AzureSearchEmulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Version>1.0.0-beta</Version>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<LangVersion>14</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 2 additions & 25 deletions AzureSearchEmulator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54359",
"sslPort": 44381
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AzureSearchEmulator": {
"commandName": "Project",
"launchBrowser": true,
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5123"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}
}
1 change: 1 addition & 0 deletions DebugClient/DebugClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading