pool:
    name: ads-build-1es-hosted-pool
    demands: 
    - ImageOverride -equals ADS-Linux_Image

steps:

  - task: DockerInstaller@0
    displayName: Installing Docker
    inputs:
      secureFile: 'testsettings.json'
      dockerVersion: 17.09.0-ce
      releaseType: stable

  - script: docker pull mcr.microsoft.com/mssql/server:2019-latest
    displayName: Pull MSSQL Docker Image  

  - bash: echo "##vso[task.setvariable variable=defaultSql2019_password;issecret=true]Test-$(Build.BuildNumber)-$(Get-Date -format yyyyMMdd-Hmmss)"
    displayName: Generate password for test server

  - script: 'docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$(defaultSql2019_password)"
    -e "MSSQL_AGENT_ENABLED=True"
    -p 1433:1433 --name sql1 -h sql1
    -d mcr.microsoft.com/mssql/server:2019-latest'
    displayName: Starting Server in Docker Container

  - task: UseDotNet@2
    displayName: Use .NET Core SDK
    inputs:
      useGlobalJson: true

  - task: Bash@3
    displayName: Creating Loc Directories Expected By Dotnet Build
    inputs:
      filePath: ./azure-pipelines/createBuildDirectories.sh

  - task: NuGetAuthenticate@0

  - task: DotNetCoreCLI@2
    displayName: Building Test Environment
    inputs:
      projects: '**/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj'

  - task: DownloadSecureFile@1
    displayName: Download Test Environment Configuration
    name: testEnvironmentPath
    inputs:
      secureFile: 'SQLConnectionInstances.xml'

  - task: DotNetCoreCLI@2
    displayName: Setting Up Test Environment
    inputs:
      command: run
      projects: '**/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj'
      arguments: $(testEnvironmentPath.secureFilePath)
      testRunTitle: 'Setting tests'
    env:
      defaultSql2019_password: '$(defaultSql2019_password)'

  - task: DotNetCoreCLI@2
    displayName: Building Integration Tests
    inputs:
      projects: '**/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj'
      arguments: '/p:CodeCoverageBuild=true'

  - task: DotNetCoreCLI@2
    displayName: Running Integration Tests
    inputs:
      command: test
      projects: '**/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj'
      arguments: '--no-build'
      testRunTitle: 'SqlToolsService Integration Tests'
