#!/usr/bin/env bash

export MISE_DOTNET_ROOT="$MISE_DATA_DIR/dotnet-root"

assert_contains "mise x dotnet@8.0.408 -- dotnet --version" "8.0.408"

# Test global.json idiomatic file support
mise settings set idiomatic_version_file_enable_tools dotnet

cat <<EOF >global.json
{
  "sdk": {
    "version": "8.0.408"
  }
}
EOF

assert_contains "mise x -- dotnet --version" "8.0.408"

# Prepare and test environment is clean for runtime-only install tests
mise uninstall "dotnet[runtime=dotnet]@8.0.13" 2>/dev/null || true
assert_not_contains "mise x dotnet@8.0.408 -- dotnet --list-runtimes" "Microsoft.NETCore.App 8.0.13"

# Test runtime-only install: version NOT bundled by SDK 8.0.408, `--list-runtimes`
assert_contains "mise x dotnet[runtime=dotnet]@8.0.13 -- dotnet --list-runtimes" "Microsoft.NETCore.App 8.0.13"

# Test runtime uninstall cleans up shared directory
mise uninstall "dotnet[runtime=dotnet]@8.0.13"
assert_not_contains "mise x dotnet@8.0.408 -- dotnet --list-runtimes" "Microsoft.NETCore.App 8.0.13"

# Prepare by removing any stale install and test (uncached) invalid runtime option returns a validation error
mise uninstall "dotnet[runtime=invalid]@8.0.12" 2>/dev/null || mise uninstall "dotnet@8.0.12" 2>/dev/null || true
assert_fail_contains "mise x dotnet[runtime=invalid]@8.0.12 -- true" "Invalid runtime option"
