FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS sdk

ENV JUSTMOCK_BINARY_PATH /justmock
ENV TELERIK_LICENSE=<your_license_key>

# copy JustMock
COPY JustMock/Telerik.JustMock.dll /justmock/
COPY JustMock/CodeWeaver/32/Telerik.CodeWeaver.Profiler.dll /justmock/codewaver/32/
COPY JustMock/CodeWeaver/64/Telerik.CodeWeaver.Profiler.dll /justmock/codewaver/64/
COPY JustMock/Telerik.JustMock.Console.exe /justmock/

# copy csproj and restore as distinct layers
WORKDIR /build
COPY *.sln .
COPY MyClassLibrary/*.csproj ./MyClassLibrary/
COPY MyClassLibrary.Test/*.csproj ./MyClassLibrary.Test/
WORKDIR /build
RUN dotnet restore

# copy everything else and build library and tests
WORKDIR /build
COPY . .
RUN dotnet build

# run tests
WORKDIR /build
RUN ["/justmock/Telerik.JustMock.Console.exe", "runadvanced",\
 "--profiler-path-32", "/justmock/codewaver/32/Telerik.CodeWeaver.Profiler.dll",\
 "--profiler-path-64", "/justmock/codewaver/64/Telerik.CodeWeaver.Profiler.dll",\
 "--command", "dotnet",\
 "--command-args", "test --logger:\"console;verbosity=detailed\""]

FROM sdk AS testrunner
WORKDIR /build
ENTRYPOINT ["/justmock/Telerik.JustMock.Console.exe", "runadvanced",\
 "--profiler-path-32", "/justmock/codewaver/32/Telerik.CodeWeaver.Profiler.dll",\
 "--profiler-path-64", "/justmock/codewaver/64/Telerik.CodeWeaver.Profiler.dll",\
 "--command", "dotnet",\
 "--command-args", "test /logger:trx ./MyClassLibrary.Test/bin/Debug/net472/MyClassLibrary.Test.dll"]

