Fix category shadow foreign keys and .NET 10 Docker build context
Build MoneyMap image / build-and-push (push) Failing after 7s

This commit is contained in:
aj
2026-09-12 17:38:38 -04:00
parent 08e54a4d31
commit df09dd8d53
6 changed files with 133 additions and 4 deletions
+68
View File
@@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore;
using MoneyMap.Data;
using MoneyMap.Models;
namespace MoneyMap.Tests.Data;
public class CategoryModelTests
{
// Model/query compilation only: never opens a connection or reads application configuration.
private static MoneyMapContext CreateContext() => new(
new DbContextOptionsBuilder<MoneyMapContext>()
.UseSqlServer("Server=localhost;Database=ModelOnly;Integrated Security=true;TrustServerCertificate=true")
.Options);
[Theory]
[InlineData(typeof(Transaction))]
[InlineData(typeof(CategoryMapping))]
public void StringCategoryEntities_DoNotHaveCategoryForeignKeys(Type entityType)
{
using var context = CreateContext();
var entity = context.Model.FindEntityType(entityType)!;
Assert.Null(entity.FindProperty("CategoryId"));
Assert.DoesNotContain(entity.GetProperties(), p => p.IsShadowProperty());
Assert.Equal(typeof(string), entity.FindProperty("Category")!.ClrType);
Assert.DoesNotContain(entity.GetForeignKeys(), fk => fk.PrincipalEntityType.ClrType == typeof(Category));
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void ReceiptDuplicateQueries_DoNotSelectCategoryId(bool matchHash)
{
using var context = CreateContext();
var query = context.Receipts.Include(r => r.Transaction);
var sql = (matchHash
? query.Where(r => r.FileHashSha256 == "test-hash")
: query.Where(r => r.FileName == "receipt.png" && r.FileSizeBytes == 8))
.ToQueryString();
Assert.Contains("LEFT JOIN [Transactions]", sql);
Assert.Contains("[Category]", sql);
Assert.DoesNotContain("[CategoryId]", sql);
}
[Fact]
public void CategoryMappingQuery_DoesNotSelectCategoryId()
{
using var context = CreateContext();
var sql = context.CategoryMappings.ToQueryString();
Assert.Contains("[Category]", sql);
Assert.DoesNotContain("[CategoryId]", sql);
}
[Fact]
public void IntendedCategoryRelationships_ArePreserved()
{
using var context = CreateContext();
var recurringPlace = context.Model.FindEntityType(typeof(RecurringPlace))!;
Assert.Contains(recurringPlace.GetForeignKeys(), fk =>
fk.PrincipalEntityType.ClrType == typeof(Category) &&
fk.Properties.Single().Name == "CategoryId" && !fk.Properties.Single().IsShadowProperty());
var category = context.Model.FindEntityType(typeof(Category))!;
Assert.Contains(category.GetForeignKeys(), fk =>
fk.PrincipalEntityType.ClrType == typeof(Category) &&
fk.Properties.Single().Name == "ParentCategoryId");
}
}