diff --git a/DotNetTry.sln b/DotNetTry.sln index da58bc3c7..3fd5c8c9d 100644 --- a/DotNetTry.sln +++ b/DotNetTry.sln @@ -1,5 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28803.352 MinimumVisualStudioVersion = 10.0.40219.1 @@ -55,6 +54,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ProjectTem EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharpWorkspaceShim", "FSharpWorkspaceShim\FSharpWorkspaceShim.fsproj", "{9128FCED-2A19-4502-BCEE-BE1BAB6882EB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotIntegrationTests", "NotIntegrationTests\NotIntegrationTests.csproj", "{EA6DDD48-941D-43C6-BAC1-07CF24F4C792}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.Rendering", "Microsoft.DotNet.Interactive.Rendering\Microsoft.DotNet.Interactive.Rendering.csproj", "{FBEA5F71-23F5-4412-A936-9B8E6E228968}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.Rendering.Tests", "Microsoft.DotNet.Interactive.Rendering.Tests\Microsoft.DotNet.Interactive.Rendering.Tests.csproj", "{B4B9DC70-6BA2-4BC1-A780-7FCEBDB1D218}" @@ -161,6 +161,10 @@ Global {9128FCED-2A19-4502-BCEE-BE1BAB6882EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {9128FCED-2A19-4502-BCEE-BE1BAB6882EB}.Release|Any CPU.ActiveCfg = Release|Any CPU {9128FCED-2A19-4502-BCEE-BE1BAB6882EB}.Release|Any CPU.Build.0 = Release|Any CPU + {EA6DDD48-941D-43C6-BAC1-07CF24F4C792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA6DDD48-941D-43C6-BAC1-07CF24F4C792}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA6DDD48-941D-43C6-BAC1-07CF24F4C792}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA6DDD48-941D-43C6-BAC1-07CF24F4C792}.Release|Any CPU.Build.0 = Release|Any CPU {FBEA5F71-23F5-4412-A936-9B8E6E228968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FBEA5F71-23F5-4412-A936-9B8E6E228968}.Debug|Any CPU.Build.0 = Debug|Any CPU {FBEA5F71-23F5-4412-A936-9B8E6E228968}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -198,7 +202,7 @@ Global {1F1A7554-1E88-4514-8602-EC00899E0C49} = {8192FEAD-BCE6-4E62-97E5-2E9EA884BD71} {E047D81A-7A18-4A1A-98E8-EDBB51EBB7DB} = {6EE8F484-DFA2-4F0F-939F-400CE78DFAC2} {9128FCED-2A19-4502-BCEE-BE1BAB6882EB} = {6EE8F484-DFA2-4F0F-939F-400CE78DFAC2} - {FBEA5F71-23F5-4412-A936-9B8E6E228968} = {6EE8F484-DFA2-4F0F-939F-400CE78DFAC2} + {EA6DDD48-941D-43C6-BAC1-07CF24F4C792} = {8192FEAD-BCE6-4E62-97E5-2E9EA884BD71} {B4B9DC70-6BA2-4BC1-A780-7FCEBDB1D218} = {8192FEAD-BCE6-4E62-97E5-2E9EA884BD71} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/NotIntegrationTests/DotnetTry.cs b/NotIntegrationTests/DotnetTry.cs new file mode 100644 index 000000000..f99c91125 --- /dev/null +++ b/NotIntegrationTests/DotnetTry.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using MLS.Agent; +using MLS.Agent.Tools; +using WorkspaceServer; + +namespace NotIntegrationTests +{ + public class DotnetTryFixture : IDisposable + { + private DisposableDirectory _disposableDirectory; + private Process _process; + private HttpClient _client; + private AsyncLazy _lazyReady; + + public DotnetTryFixture() + { + _disposableDirectory = DisposableDirectory.Create(); + _lazyReady = new AsyncLazy(ReadyAsync); + } + + public void Dispose() + { + _process?.Kill(); + _disposableDirectory.Dispose(); + } + + private async Task ReadyAsync() + { + var dotnet = new Dotnet(); + var installResult = await dotnet.ToolInstall("dotnet-try", _disposableDirectory.Directory, version: "1.0.44142.42", addSource: GetPackageSource()); + installResult.ThrowOnFailure(); + + await Start(); + return true; + } + + private async Task Start() + { + var tcs = new TaskCompletionSource(); + var dotnetTry = _disposableDirectory.Directory.GetFiles("dotnet-try*").First().FullName; + _process = CommandLine.StartProcess(dotnetTry, "--port 7891 hosted", _disposableDirectory.Directory, + output => + { + if (output.Contains("Now listening on")) + { + tcs.SetResult(true); + } + }, + error => + { + if (!string.IsNullOrWhiteSpace(error)) + { + tcs.TrySetException(new Exception(error)); + Console.Write(error); + } + }); + + _client = new HttpClient(); + _client.BaseAddress = new Uri("http://localhost:7891"); + await tcs.Task; + } + + private PackageSource GetPackageSource([CallerFilePath] string callerFile = "") + { + var dotnetTryPackageSource = Environment.GetEnvironmentVariable("PACKAGESOURCE"); + + var directory = !string.IsNullOrWhiteSpace(dotnetTryPackageSource) + ? new DirectoryInfo(dotnetTryPackageSource) + : new DirectoryInfo(Path.Combine(Path.GetDirectoryName(callerFile), "../artifacts/packages/Debug/Shipping")); + + if (!directory.Exists) + { + throw new Exception($"Expected packages directory {directory.FullName} to exist but it does not"); + } + + return new PackageSource(directory.FullName); + } + + public async Task GetAsync(string requestUri) + { + await _lazyReady.ValueAsync(); + return await _client.GetAsync(requestUri); + } + } +} diff --git a/NotIntegrationTests/IntegrationTests.cs b/NotIntegrationTests/IntegrationTests.cs new file mode 100644 index 000000000..21fb57538 --- /dev/null +++ b/NotIntegrationTests/IntegrationTests.cs @@ -0,0 +1,54 @@ +using System; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace NotIntegrationTests +{ + public class UnitTest1 : IClassFixture + { + private readonly DotnetTryFixture _fixture; + + public UnitTest1(DotnetTryFixture fixture) + { + _fixture = fixture; + } + + [Fact(Skip = "This doesn't work yet")] + public async Task Can_serve_blazor_console_code_runner() + { + var response = await _fixture.GetAsync(@"/LocalCodeRunner/blazor-console"); + + response.StatusCode.Should().Be(200); + var result = await response.Content.ReadAsStringAsync(); + result.Should().Contain("Loading..."); + } + + [Fact] + public async Task Can_serve_bundleCss() + { + var response = await _fixture.GetAsync(@"/client/bundle.css"); + response.StatusCode.Should().Be(200); + var content = await response.Content.ReadAsStringAsync(); + content.Should().NotBeNullOrEmpty(); + } + + [Fact] + public async Task Can_serve_bundlejs() + { + var response = await _fixture.GetAsync(@"/client/2.bundle.js"); + response.StatusCode.Should().Be(200); + var content = await response.Content.ReadAsStringAsync(); + content.Should().NotBeNullOrEmpty(); + } + + [Fact] + public async Task Can_serve_clientapi() + { + var response = await _fixture.GetAsync(@"/api/trydotnet.min.js"); + response.StatusCode.Should().Be(200); + var content = await response.Content.ReadAsStringAsync(); + content.Should().NotBeNullOrEmpty(); + } + } +} diff --git a/NotIntegrationTests/NotIntegrationTests.csproj b/NotIntegrationTests/NotIntegrationTests.csproj new file mode 100644 index 000000000..fa7d9bbd9 --- /dev/null +++ b/NotIntegrationTests/NotIntegrationTests.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.0 + + true + + + + + + + + + + + + + + + + + diff --git a/WorkspaceServer/Dotnet.cs b/WorkspaceServer/Dotnet.cs index 8c4d09b1d..8d5e4188e 100644 --- a/WorkspaceServer/Dotnet.cs +++ b/WorkspaceServer/Dotnet.cs @@ -60,6 +60,14 @@ public Task Execute(string args, Budget budget = null) => _workingDirectory, budget); + public Process StartProcess(string args, Action output = null, Action error = null) => + CommandLine.StartProcess( + Path.FullName, + args, + _workingDirectory, + output, + error); + public Task Publish(string args, Budget budget = null) => Execute("publish".AppendArgs(args), budget); @@ -104,9 +112,11 @@ public Task ToolInstall( string packageName, DirectoryInfo toolPath, PackageSource addSource = null, - Budget budget = null) + Budget budget = null, + string version = null) { - var args = $@"{packageName} --tool-path ""{RemoveTrailingSlash(toolPath.FullName)}"" --version 1.0.0"; + var versionArg = version != null ? $"--version {version}" : ""; + var args = $@"{packageName} --tool-path ""{RemoveTrailingSlash(toolPath.FullName)}"" {versionArg}"; if (addSource != null) { args += $@" --add-source ""{addSource}"""; diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 61dcca5ab..83767a72f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -108,13 +108,19 @@ jobs: continueOnError: true condition: always() - - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - - task: PublishBuildArtifacts@1 - displayName: Publish packages to artifacts container - inputs: - pathToPublish: $(Build.SourcesDirectory)\artifacts\packages\$(_BuildConfig) - artifactName: packages - artifactType: container + - task: PublishBuildArtifacts@1 + displayName: Publish packages to artifacts container + inputs: + pathToPublish: $(Build.SourcesDirectory)\artifacts\packages\$(_BuildConfig) + artifactName: packages + artifactType: container + + - task: PublishBuildArtifacts@1 + displayName: Publish integration tests dll + inputs: + pathToPublish: $(Build.SourcesDirectory)\artifacts\bin\NotIntegrationTests\$(_BuildConfig) + artifactName: integrationTests + artifactType: container - template: /eng/common/templates/jobs/jobs.yml parameters: @@ -126,6 +132,52 @@ jobs: enableTelemetry: true helixRepo: dotnet/try jobs: + - job: IntegrationTest + dependsOn: Windows_NT + condition: succeeded() + pool: + vmImage: ubuntu-16.04 + variables: + - name: PACKAGESOURCE + value: $(System.DefaultWorkingDirectory)/packages/Shipping + - name: TryDotNetPackagesPath + value: $(Build.SourcesDirectory)/.trydotnet/packages + steps: + - checkout: none #skip checking out the default repository resource + - task: UseDotNet@2 + displayName: Add dotnet + inputs: + packageType: sdk + version: $(DotNetSdkVersion) + installationPath: $(Agent.ToolsDirectory)/dotnet + + - script: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::$(BlazorTemplateVersion) + displayName: Install Blazor templates + + - task: DownloadBuildArtifacts@0 + displayName: 'Download built packages' + inputs: + artifactName: packages + downloadPath: $(System.DefaultWorkingDirectory) + + - task: DownloadBuildArtifacts@0 + displayName: 'Download built integrationtests' + inputs: + artifactName: integrationTests + downloadPath: $(System.DefaultWorkingDirectory) + + - script: dotnet vstest $(System.DefaultWorkingDirectory)/integrationTests/netcoreapp3.0/NotIntegrationTests.dll --ResultsDirectory:$(System.DefaultWorkingDirectory)/testResults | tee $(Build.SourcesDirectory)\artifacts\log\$(_BuildConfig)\log.txt + displayName: Run integration tests + + - task: PublishTestResults@2 + displayName: Publish NPM Test Results + inputs: + testResultsFormat: 'VSTest' + testResultsFiles: '*.trx' + searchFolder: '$(SystemWorkingDirectory)/testResults' + continueOnError: true + condition: always() + - job: Linux pool: vmImage: ubuntu-16.04