FROM mono:6.12

WORKDIR /build

# Sync Mozilla root certs into Mono trust store — required for NuGet HTTPS on Buster
RUN cert-sync /etc/ssl/certs/ca-certificates.crt

# Copy solution + projects first for layer caching
COPY NcProgramManager.csproj ./
COPY packages.config ./
COPY NcProgramManager.Tests/NcProgramManager.Tests.csproj ./NcProgramManager.Tests/
COPY NcProgramManager.Tests/packages.config ./NcProgramManager.Tests/
COPY NcProgramManager.sln ./

# Restore all packages (sln now includes test project)
RUN nuget restore NcProgramManager.sln -NonInteractive
# Explicit fallback: restore test packages.config directly to same packages dir
RUN nuget restore NcProgramManager.Tests/packages.config \
    -OutputDirectory packages -NonInteractive
# Grab NUnit console runner
RUN nuget install NUnit.ConsoleRunner -Version 3.16.3 -OutputDirectory packages -NonInteractive

# Copy source
COPY . .

# Make libs dir explicit (native Win32 DLLs — needed by csproj Content entries, not executed on Linux)
RUN ls Cnc/Fanuc/libs/ || true

# Build test project (Debug)
RUN msbuild NcProgramManager.Tests/NcProgramManager.Tests.csproj \
    /p:Configuration=Debug /p:Platform=AnyCPU \
    /v:minimal /nologo

# Run tests — skip Fanuc FOCAS tests (marked [Ignore] — need fwlib32.dll)
CMD mono packages/NUnit.ConsoleRunner.3.16.3/tools/nunit3-console.exe \
    NcProgramManager.Tests/bin/Debug/NcProgramManager.Tests.dll \
    --labels=All
