# 测试项目用 SDK 镜像即可（dotnet test 需要 SDK，而不是 runtime）
# 注意：这里不写 `# syntax=docker/dockerfile:1`，避免额外拉取 dockerfile 前端镜像
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS test
WORKDIR /src

ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \
    DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 \
    DOTNET_NOLOGO=1

# 1) 先只复制 csproj 做 restore，充分利用 Docker 层缓存
COPY TySpace.Ttc.RegressionSuite.csproj ./
RUN dotnet restore TySpace.Ttc.RegressionSuite.csproj

# 2) 再复制源码并预编译，让编译错误在 build 阶段就暴露
COPY . .
RUN dotnet build TySpace.Ttc.RegressionSuite.csproj -c Release --no-restore

# 3) 容器启动即跑测试；结果写到 /src/TestResults，可挂载出来
ENTRYPOINT ["dotnet", "test", "TySpace.Ttc.RegressionSuite.csproj", \
            "-c", "Release", "--no-build", "--no-restore", \
            "--logger", "trx;LogFileName=test-results.trx", \
            "--results-directory", "/src/TestResults"]
