diff --git a/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectBuilderExtensions.cs b/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectBuilderExtensions.cs index 120cd513..002d5d23 100644 --- a/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectBuilderExtensions.cs +++ b/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectBuilderExtensions.cs @@ -69,11 +69,11 @@ public static IResourceBuilder PublishTo( this IResourceBuilder builder, IResourceBuilder target) { builder.ApplicationBuilder.Services.TryAddSingleton(); - builder.ApplicationBuilder.Services.TryAddSingleton(); + builder.ApplicationBuilder.Services.TryAddSingleton(); builder.ApplicationBuilder.Eventing.Subscribe(target.Resource, (resourceReady, ct) => { - var service = resourceReady.Services.GetRequiredService(); + var service = resourceReady.Services.GetRequiredService(); return service.PublishSqlProject(builder.Resource, target.Resource, ct); }); diff --git a/src/MSBuild.Sdk.SqlProj.Aspire/PublishSqlProjectLifecycleHook.cs b/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectPublishService.cs similarity index 95% rename from src/MSBuild.Sdk.SqlProj.Aspire/PublishSqlProjectLifecycleHook.cs rename to src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectPublishService.cs index 0a9789d0..1b602064 100644 --- a/src/MSBuild.Sdk.SqlProj.Aspire/PublishSqlProjectLifecycleHook.cs +++ b/src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectPublishService.cs @@ -3,13 +3,13 @@ namespace MSBuild.Sdk.SqlProj.Aspire; -public class SqlProjectPublisher +public class SqlProjectPublishService { private readonly IDacpacDeployer _deployer; private readonly ResourceLoggerService _resourceLoggerService; private readonly ResourceNotificationService _resourceNotificationService; - public SqlProjectPublisher(IDacpacDeployer deployer, ResourceLoggerService resourceLoggerService, + public SqlProjectPublishService(IDacpacDeployer deployer, ResourceLoggerService resourceLoggerService, ResourceNotificationService resourceNotificationService) { _deployer = deployer ?? throw new ArgumentNullException(nameof(deployer)); diff --git a/test/MSBuild.Sdk.SqlProj.Aspire.Tests/AddSqlProjectTests.cs b/test/MSBuild.Sdk.SqlProj.Aspire.Tests/AddSqlProjectTests.cs index f7ac570a..46e48982 100644 --- a/test/MSBuild.Sdk.SqlProj.Aspire.Tests/AddSqlProjectTests.cs +++ b/test/MSBuild.Sdk.SqlProj.Aspire.Tests/AddSqlProjectTests.cs @@ -49,26 +49,7 @@ public void AddSqlProject_WithExplicitPath() } [Fact] - public void PublishTo_AddsAnnotation() - { - // Arrange - var appBuilder = DistributedApplication.CreateBuilder(); - var targetDatabase = appBuilder.AddSqlServer("sql").AddDatabase("test"); - appBuilder.AddSqlProject("MySqlProject") - .PublishTo(targetDatabase); - - // Act - using var app = appBuilder.Build(); - var appModel = app.Services.GetRequiredService(); - - // Assert - var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); - var annotation = Assert.Single(sqlProjectResource.Annotations.OfType()); - Assert.Equal("test", annotation.TargetDatabaseResourceName); - } - - [Fact] - public void PublishTo_AddsLifecycleHook() + public void PublishTo_AddsRequiredServices() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); @@ -80,7 +61,7 @@ public void PublishTo_AddsLifecycleHook() using var app = appBuilder.Build(); // Assert - var lifecycleHooks = app.Services.GetServices(); - Assert.Single(lifecycleHooks.OfType()); + Assert.Single(app.Services.GetServices()); + Assert.Single(app.Services.GetServices()); } } diff --git a/test/MSBuild.Sdk.SqlProj.Aspire.Tests/PublishSqlProjectLifecycleHookTests.cs b/test/MSBuild.Sdk.SqlProj.Aspire.Tests/SqlProjectPublishService.cs similarity index 74% rename from test/MSBuild.Sdk.SqlProj.Aspire.Tests/PublishSqlProjectLifecycleHookTests.cs rename to test/MSBuild.Sdk.SqlProj.Aspire.Tests/SqlProjectPublishService.cs index d35791ba..d1b40324 100644 --- a/test/MSBuild.Sdk.SqlProj.Aspire.Tests/PublishSqlProjectLifecycleHookTests.cs +++ b/test/MSBuild.Sdk.SqlProj.Aspire.Tests/SqlProjectPublishService.cs @@ -5,10 +5,10 @@ namespace MSBuild.Sdk.SqlProj.Aspire.Tests; -public class PublishSqlProjectLifecycleHookTests +public class SqlProjectPublisherServiceTests { [Fact] - public async Task AfterResourcesCreatedAsync_PublishesDacpacToTargetDatabase() + public async Task PublishesDacpacToTargetDatabase() { // Arrange var dacDeployerMock = Substitute.For(); @@ -18,14 +18,14 @@ public async Task AfterResourcesCreatedAsync_PublishesDacpacToTargetDatabase() var targetDatabase = appBuilder.AddSqlServer("sql") .WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 1433)) // Simulated endpoint .AddDatabase("test"); - appBuilder.AddSqlProject("MySqlProject") + var project = appBuilder.AddSqlProject("MySqlProject") .PublishTo(targetDatabase); // Act using var app = appBuilder.Build(); var appModel = app.Services.GetRequiredService(); - var lifecycleHook = Assert.Single(app.Services.GetServices().OfType()); - await lifecycleHook.AfterResourcesCreatedAsync(appModel, CancellationToken.None); + var service = Assert.Single(app.Services.GetServices()); + await service.PublishSqlProject(project.Resource, targetDatabase.Resource, CancellationToken.None); // Assert var expectedPath = Path.GetFullPath(Path.Combine(appBuilder.AppHostDirectory, "../../../../TestProject/bin/Debug/netstandard2.0/TestProject.dacpac"));