diff --git a/Directory.Packages.props b/Directory.Packages.props index 6a2cd8a..e062d9e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -53,7 +53,7 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj index abc9119..9c25b95 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj @@ -12,7 +12,7 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs index f8437fb..27b6722 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs @@ -6,8 +6,7 @@ builder.AddSqlProject("sdk-project") .WithReference(server); -builder.AddSqlPackage("dacpac-project") - .WithDacpac("tools/master.dacpac") +builder.AddSqlPackage("chinook") .WithReference(server); builder.Build().Run(); diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets index 81793f2..4e6dca3 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets @@ -13,7 +13,7 @@ DependsOnTargets="_CreateAspireProjectResources"> - $([System.Text.RegularExpressions.Regex]::Replace($([System.IO.Path]::GetFileNameWithoutExtension(%(_AspirePackageResource.Identity))), $(_GeneratedClassNameFixupRegex), '_')) + $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.Identity), $(_GeneratedClassNameFixupRegex), '_')) $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.Version)').ToLower()) diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs index b4d0530..22426b1 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs @@ -9,7 +9,7 @@ public void AddSqlPackage_WithPackageMetadata() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); - appBuilder.AddSqlPackage("master"); + appBuilder.AddSqlPackage("chinook"); // Act using var app = appBuilder.Build(); @@ -17,11 +17,12 @@ public void AddSqlPackage_WithPackageMetadata() // Assert var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); - Assert.Equal("master", sqlProjectResource.Name); + Assert.Equal("chinook", sqlProjectResource.Name); var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); - Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3", "tools", "Microsoft.SqlServer.Dacpacs.Master.dacpac"), dacpacPath); + Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0", "tools", "ErikEJ.Dacpac.Chinook.dacpac"), dacpacPath); + Assert.True(File.Exists(dacpacPath)); } [Fact] @@ -29,7 +30,7 @@ public void AddSqlPackage_WithExplicitRelativePath() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); - appBuilder.AddSqlPackage("master").WithDacpac("tools/master.dacpac"); + appBuilder.AddSqlPackage("chinook").WithDacpac("tools/ErikEJ.Dacpac.Chinook2.dacpac"); // Act using var app = appBuilder.Build(); @@ -37,10 +38,10 @@ public void AddSqlPackage_WithExplicitRelativePath() // Assert var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); - Assert.Equal("master", sqlProjectResource.Name); + Assert.Equal("chinook", sqlProjectResource.Name); var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); - Assert.True(File.Exists(dacpacPath)); + Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0", "tools", "ErikEJ.Dacpac.Chinook2.dacpac"), dacpacPath); } } \ No newline at end of file diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs index f5a8813..297e67c 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs @@ -8,7 +8,7 @@ namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; public class AppHostTests(AspireIntegrationTestFixture fixture) : IClassFixture> { [Fact] - public async Task ResourceStartsAndRespondsOk() + public async Task ProjectBasedResourceStartsAndRespondsOk() { string resourceName = "sdk-project"; await fixture.ResourceNotificationService.WaitForResourceAsync(resourceName, KnownResourceStates.Finished).WaitAsync(TimeSpan.FromMinutes(5)); @@ -29,4 +29,27 @@ public async Task ResourceStartsAndRespondsOk() var result = await command.ExecuteScalarAsync(); Assert.Equal(1, result); } + + [Fact] + public async Task PackageBasedResourceStartsAndRespondsOk() + { + string resourceName = "chinook"; + await fixture.ResourceNotificationService.WaitForResourceAsync(resourceName, KnownResourceStates.Finished).WaitAsync(TimeSpan.FromMinutes(5)); + + string? connectionString = await fixture.GetConnectionString("TargetDatabase"); + Assert.NotNull(connectionString); + + using var connection = new SqlConnection(connectionString); + await connection.OpenAsync(); + + using var command = connection.CreateCommand(); + command.CommandText = + "SELECT COUNT(1) " + + "FROM INFORMATION_SCHEMA.TABLES " + + "WHERE TABLE_SCHEMA = 'dbo' " + + "AND TABLE_NAME = 'InvoiceLine'"; + + var result = await command.ExecuteScalarAsync(); + Assert.Equal(1, result); + } } \ No newline at end of file diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs index 4e38a4b..ce74b78 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs @@ -6,9 +6,9 @@ internal class TestPackage : IPackageMetadata { public static readonly string NuGetPackageCache = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? Environment.GetEnvironmentVariable("USERPROFILE") ?? string.Empty, ".nuget", "packages"); - public string PackageId { get; } = "Microsoft.SqlServer.Dacpacs.Master"; + public string PackageId { get; } = "ErikEJ.Dacpac.Chinook"; - public Version PackageVersion { get; } = new Version(160, 2, 3); + public Version PackageVersion { get; } = new Version(1, 0, 0); - public string PackagePath { get; } = Path.Combine(NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3"); + public string PackagePath { get; } = Path.Combine(NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0"); } \ No newline at end of file