Skip to content

Commit

Permalink
Add eventing to test builder. (#6682)
Browse files Browse the repository at this point in the history
* Add eventing to test builder.

* Add test case to detect drift.

* Add suppression for eventing property on test builder.

* Disable eventhubs test.
  • Loading branch information
mitchdenny authored Nov 21, 2024
1 parent b81e1c6 commit b0d7319
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Aspire.Hosting.Testing/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>P:Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder.Eventing</Target>
<Left>lib/net8.0/Aspire.Hosting.Testing.dll</Left>
<Right>lib/net8.0/Aspire.Hosting.Testing.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>P:Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder.Eventing</Target>
<Left>lib/net9.0/Aspire.Hosting.Testing.dll</Left>
<Right>lib/net9.0/Aspire.Hosting.Testing.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Reflection;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Eventing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -170,6 +171,8 @@ private sealed class Builder(SuspendingDistributedApplicationFactory factory, Di

public IResourceCollection Resources => innerBuilder.Resources;

public IDistributedApplicationEventing Eventing => innerBuilder.Eventing;

public IResourceBuilder<T> AddResource<T>(T resource) where T : IResource => innerBuilder.AddResource(resource);

public async Task<DistributedApplication> BuildAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -261,6 +264,11 @@ public interface IDistributedApplicationTestingBuilder
/// </summary>
DistributedApplicationExecutionContext ExecutionContext { get; }

/// <summary>
/// Eventing infrastructure for AppHost lifecycle.
/// </summary>
IDistributedApplicationEventing Eventing { get; }

/// <summary>
/// Gets the collection of resources for the distributed application.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting.Testing/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
Aspire.Hosting.Testing.DistributedApplicationFactory.DistributedApplicationFactory(System.Type! entryPoint, string![]! args) -> void
Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder.AppHostAssembly.get -> System.Reflection.Assembly?
Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder.Eventing.get -> Aspire.Hosting.Eventing.IDistributedApplicationEventing!
static Aspire.Hosting.Testing.DistributedApplicationTestingBuilder.CreateAsync(System.Type! entryPoint, string![]! args, System.Action<Aspire.Hosting.DistributedApplicationOptions!, Microsoft.Extensions.Hosting.HostApplicationBuilderSettings!>! configureBuilder, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder!>!
static Aspire.Hosting.Testing.DistributedApplicationTestingBuilder.CreateAsync(System.Type! entryPoint, string![]! args, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder!>!
static Aspire.Hosting.Testing.DistributedApplicationTestingBuilder.CreateAsync<TEntryPoint>(string![]! args, System.Action<Aspire.Hosting.DistributedApplicationOptions!, Microsoft.Extensions.Hosting.HostApplicationBuilderSettings!>! configureBuilder, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Aspire.Hosting.Testing.IDistributedApplicationTestingBuilder!>!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task VerifyWaitForOnEventHubsEmulatorBlocksDependentResources()

[Fact]
[RequiresDocker]
[ActiveIssue("https://github.com/dotnet/aspire/issues/6751")]
public async Task VerifyAzureEventHubsEmulatorResource()
{
using var builder = TestDistributedApplicationBuilder.Create().WithTestAndResourceLogging(testOutputHelper);
Expand Down
9 changes: 9 additions & 0 deletions tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace Aspire.Hosting.Testing.Tests;

public class TestingBuilderTests
{
[Fact]
public void TestingBuilderHasAllPropertiesFromRealBuilder()
{
var realBuilderProperties = typeof(IDistributedApplicationBuilder).GetProperties().Select(p => p.Name).ToList();
var testBuilderProperties = typeof(IDistributedApplicationTestingBuilder).GetProperties().Select(p => p.Name).ToList();
var missingProperties = realBuilderProperties.Except(testBuilderProperties).ToList();
Assert.Empty(missingProperties);
}

[Fact]
[RequiresDocker]
public async Task CanLoadFromDirectoryOutsideOfAppContextBaseDirectory()
Expand Down

0 comments on commit b0d7319

Please sign in to comment.