#!/usr/bin/env bash

set -eo pipefail
source debian/tests/.tests.rc.d/init.sh

ChangeToAutopkgtestTmpFolder

LogInfo "Setup multi framework Project"
cat <<EOF > Project.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>
EOF
cat <<EOF > Program.cs
Console.WriteLine("Hello, World!");
EOF

LogInfo "Building Project"
dotnet build -r linux-x64

LogInfo "Testing if net6.0 build artifact is present"
test -e bin/Debug/net6.0/linux-x64/Project.dll

LogInfo "Testing if net7.0 build artifact is present"
test -e bin/Debug/net7.0/linux-x64/Project.dll

LogInfo "Testing if net8.0 build artifact is present"
test -e bin/Debug/net8.0/linux-x64/Project.dll

LogInfo "Running net6.0 build artifact"
dotnet bin/Debug/net6.0/linux-x64/Project.dll

LogInfo "Running net7.0 build artifact"
dotnet bin/Debug/net7.0/linux-x64/Project.dll

LogInfo "Running net8.0 build artifact"
dotnet bin/Debug/net8.0/linux-x64/Project.dll

LogInfo "Test Ok!"
