@echo off
echo Running NavisworksTransport Standalone Unit Tests...
echo =====================================================

cd /d "%~dp0"

echo.
echo [1/3] Building main project...
call compile.bat
if errorlevel 1 (
    echo Main project build failed! Cannot run tests.
    pause
    exit /b 1
)

echo.
echo [2/3] Building test project...
echo.

rem 检查MSBuild路径
set "MSBUILD_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
if not exist "%MSBUILD_PATH%" (
    echo MSBuild not found at expected location: %MSBUILD_PATH%
    echo Please install Visual Studio Build Tools or adjust the path.
    pause
    exit /b 1
)

echo Using MSBuild: "%MSBUILD_PATH%"
echo Building test project...

"%MSBUILD_PATH%" NavisworksTransport.UnitTests.csproj /p:Configuration=Release /p:Platform=x64 /verbosity:minimal

if errorlevel 1 (
    echo Test project build failed!
    pause
    exit /b 1
)

echo Test project build successful!

echo.
echo [3/3] Running Unit Tests...
echo.

rem 检查VSTest路径
set "VSTEST_PATH="
if exist "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" (
    set "VSTEST_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
)

if "%VSTEST_PATH%"=="" (
    echo VSTest not found. Please install Visual Studio Test Platform.
    pause
    exit /b 1
)

echo Using VSTest at: %VSTEST_PATH%
echo.

rem 运行独立测试
echo Running UIStateManager Tests...
"%VSTEST_PATH%" "bin\Debug\NavisworksTransport.UnitTests.dll" /Framework:".NETFramework,Version=v4.8" /TestAdapterPath:"packages\MSTest.TestAdapter.3.0.4\build\net462" /logger:console;verbosity=normal

echo.
echo [Test Summary]
echo =============
echo Standalone unit tests completed.
echo These tests validate the core UI architecture improvements.
echo.
echo Note: These tests run independently of Navisworks environment.
echo For full integration testing, Navisworks 2026 environment is required.

pause