Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tests-out-of-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
radical committed Jul 9, 2024
2 parents 3406514 + f647a66 commit 0741157
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<!-- external dependencies -->
<PackageVersion Include="Confluent.Kafka" Version="2.4.0" />
<PackageVersion Include="Dapper" Version="2.1.44" />
<PackageVersion Include="DnsClient" Version="1.7.0" />
<PackageVersion Include="DnsClient" Version="1.8.0" />
<PackageVersion Include="Google.Protobuf" Version="3.27.1" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.63.0" />
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.63.0" />
Expand All @@ -108,14 +108,14 @@
<PackageVersion Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.4.0" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.3.6" />
<PackageVersion Include="MySqlConnector.Logging.Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageVersion Include="NATS.Net" Version="2.2.3" />
<PackageVersion Include="NATS.Net" Version="2.3.0" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="8.0.3" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageVersion Include="Oracle.EntityFrameworkCore" Version="8.23.40" />
<PackageVersion Include="Polly.Core" Version="8.4.1" />
<PackageVersion Include="Polly.Extensions" Version="8.4.1" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageVersion Include="Qdrant.Client" Version="1.9.0" />
<PackageVersion Include="Qdrant.Client" Version="1.10.0" />
<PackageVersion Include="RabbitMQ.Client" Version="[6.8.1,7.0.0)" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.0" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
Expand All @@ -139,7 +139,7 @@
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.24324.3" />
<!-- unit test dependencies -->
<PackageVersion Include="bUnit" Version="1.28.9" />
<PackageVersion Include="JsonSchema.Net" Version="7.1.1" />
<PackageVersion Include="JsonSchema.Net" Version="7.1.2" />
<PackageVersion Include="Microsoft.DotNet.RemoteExecutor" Version="$(MicrosoftDotNetRemoteExecutorPackageVersion)" />
<PackageVersion Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="$(MicrosoftExtensionsDiagnosticsTestingPackageVersion)" />
Expand Down
3 changes: 3 additions & 0 deletions eng/pipelines/templates/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ steps:
"${{ parameters.buildScript }} -testnobuild -test -configuration ${{ parameters.buildConfig }} /bl:${{ parameters.repoLogPath }}/tests.binlog $(_OfficialBuildIdArgs)"
env:
DOCKER_BUILDKIT: 1
# Disable on Linux - https://github.com/dotnet/aspire/issues/4623
DISABLE_PLAYWRIGHT_TESTS: ${{ ne(parameters.isWindows, 'true') }}

displayName: Run non-helix tests

- script: ${{ parameters.buildScript }}
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
<script src="_framework/blazor.web.js"></script>
<script src="js/app.js"></script>
<script src="js/theme.js" type="module"></script>
<script src="js/plotly-2.26.0.min.js"></script>
<script src="js/plotly-2.32.0.min.js"></script>
</body>
</html>
15 changes: 11 additions & 4 deletions src/Aspire.Dashboard/DashboardWebApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public Func<EndpointInfo> OtlpServiceHttpEndPointAccessor
/// <summary>
/// Create a new instance of the <see cref="DashboardWebApplication"/> class.
/// </summary>
/// <param name="configureBuilder">Configuration the internal app builder. This is for unit testing.</param>
public DashboardWebApplication(Action<WebApplicationBuilder>? configureBuilder = null)
/// <param name="preConfigureBuilder">Configuration for the internal app builder *before* normal dashboard configuration is done. This is for unit testing.</param>
/// <param name="postConfigureBuilder">Configuration for the internal app builder *after* normal dashboard configuration is done. This is for unit testing.</param>
/// <param name="options">Environment configuration for the internal app builder. This is for unit testing</param>
public DashboardWebApplication(
Action<WebApplicationBuilder>? preConfigureBuilder = null,
Action<WebApplicationBuilder>? postConfigureBuilder = null,
WebApplicationOptions? options = null)
{
var builder = WebApplication.CreateBuilder();
var builder = options is not null ? WebApplication.CreateBuilder(options) : WebApplication.CreateBuilder();

configureBuilder?.Invoke(builder);
preConfigureBuilder?.Invoke(builder);

#if !DEBUG
builder.Logging.AddFilter("Default", LogLevel.Information);
Expand Down Expand Up @@ -170,6 +175,8 @@ public DashboardWebApplication(Action<WebApplicationBuilder>? configureBuilder =
options.Cookie.Name = DashboardAntiForgeryCookieName;
});

postConfigureBuilder?.Invoke(builder);

_app = builder.Build();

_dashboardOptionsMonitor = _app.Services.GetRequiredService<IOptionsMonitor<DashboardOptions>>();
Expand Down
4 changes: 4 additions & 0 deletions src/Aspire.Dashboard/ResourceService/DashboardClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ async Task ConnectAndWatchResourcesAsync(CancellationToken cancellationToken)

await WatchResourcesWithRecoveryAsync().ConfigureAwait(false);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
// Ignore. This is likely caused by the dashboard client being disposed. We don't want to log.
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading data from the resource service.");
Expand Down
8 changes: 0 additions & 8 deletions src/Aspire.Dashboard/wwwroot/js/plotly-2.26.0.min.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/Aspire.Dashboard/wwwroot/js/plotly-2.32.0.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="!!REPLACE_WITH_LATEST_VERSION!!" />
<PackageReference Include="MSTest" Version="3.1.1" />
<PackageReference Include="MSTest" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="!!REPLACE_WITH_LATEST_VERSION!!" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit.Analyzers" Version="4.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="!!REPLACE_WITH_LATEST_VERSION!!" />
<PackageReference Include="coverlet.collector" Version="6.0.0" Condition=" $(TestFramework) == 'xUnit.net' " />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" Condition=" $(TestFramework) != 'MSTest' " />
<PackageReference Include="MSTest" Version="3.1.1" Condition=" $(TestFramework) == 'MSTest' " />
<PackageReference Include="NUnit" Version="4.0.1" Condition=" $(TestFramework) == 'NUnit' " />
<PackageReference Include="NUnit.Analyzers" Version="4.0.1" Condition=" $(TestFramework) == 'NUnit' " />
<PackageReference Include="coverlet.collector" Version="6.0.2" Condition=" $(TestFramework) == 'xUnit.net' " />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" Condition=" $(TestFramework) != 'MSTest' " />
<PackageReference Include="MSTest" Version="3.4.3" Condition=" $(TestFramework) == 'MSTest' " />
<PackageReference Include="NUnit" Version="4.1.0" Condition=" $(TestFramework) == 'NUnit' " />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" Condition=" $(TestFramework) == 'NUnit' " />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" Condition=" $(TestFramework) == 'NUnit' " />
<PackageReference Include="xunit" Version="2.5.3" Condition=" $(TestFramework) == 'xUnit.net' " />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" Condition=" $(TestFramework) == 'xUnit.net' " />
<PackageReference Include="xunit" Version="2.9.0" Condition=" $(TestFramework) == 'xUnit.net' " />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" Condition=" $(TestFramework) == 'xUnit.net' " />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="!!REPLACE_WITH_LATEST_VERSION!!" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>

<InstallBrowsersForPlaywright Condition="'$(InstallBrowsersForPlaywright)' == '' and '$(CODESPACES)' == 'true'">true</InstallBrowsersForPlaywright>
<InstallBrowsersForPlaywright Condition="'$(InstallBrowsersForPlaywright)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</InstallBrowsersForPlaywright>
<InstallBrowsersForPlaywright Condition="'$(InstallBrowsersForPlaywright)' == '' and '$(OS)' == 'Windows_NT' and '$(ContinuousIntegrationBuild)' != 'true'">true</InstallBrowsersForPlaywright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Tools" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" />

<ProjectReference Include="..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />

<Compile Include="$(TestsSharedDir)TestCertificateLoader.cs" Link="shared/TestCertificateLoader.cs" />
Expand All @@ -14,4 +20,6 @@

<Content Include="..\..\src\Aspire.Dashboard\wwwroot\**\*.*" LinkBase="wwwroot" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<Import Project="..\Shared\Playwright\Playwright.targets" />
</Project>
51 changes: 51 additions & 0 deletions tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Dashboard.Resources;
using Aspire.Workload.Tests;
using Microsoft.Playwright;
using Xunit;

namespace Aspire.Dashboard.Tests.Integration.Playwright;

[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))]
public class AppBarTests : PlaywrightTestsBase
{
public AppBarTests(DashboardServerFixture dashboardServerFixture, PlaywrightFixture playwrightFixture)
: base(dashboardServerFixture, playwrightFixture)
{
}

[Fact]
public async Task AppBar_Change_Theme()
{
// Arrange
await RunTestAsync(async page =>
{
await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page);

var settingsButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutLaunchSettings });

await settingsButton.ClickAsync();

// Act and Assert

// set to dark
var darkThemeCheckbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(Dialogs.SettingsDialogDarkTheme)).First;
var lightThemeCheckbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(Dialogs.SettingsDialogLightTheme)).First;

await SetAndVerifyTheme(darkThemeCheckbox, "dark");
await SetAndVerifyTheme(lightThemeCheckbox, "light");

return;

async Task SetAndVerifyTheme(ILocator locator, string expected)
{
await locator.ClickAsync();
await Assertions
.Expect(page.Locator("html"))
.ToHaveAttributeAsync("data-theme", expected);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using Aspire.Dashboard.Configuration;
using Aspire.Dashboard.Model;
using Aspire.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Xunit;

namespace Aspire.Dashboard.Tests.Integration.Playwright;

public class DashboardServerFixture : IAsyncLifetime
{
public DashboardWebApplication DashboardApp { get; private set; } = null!;

public Task InitializeAsync()
{
const string aspireDashboardAssemblyName = "Aspire.Dashboard";
var currentAssemblyName = Assembly.GetExecutingAssembly().GetName().Name!;
var currentAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var aspireAssemblyDirectory = currentAssemblyDirectory.Replace(currentAssemblyName, aspireDashboardAssemblyName);

var initialData = new Dictionary<string, string?>
{
[DashboardConfigNames.DashboardFrontendUrlName.ConfigKey] = "http://127.0.0.1:0",
[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0",
[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = nameof(OtlpAuthMode.Unsecured),
[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = nameof(FrontendAuthMode.Unsecured)
};

var config = new ConfigurationManager().AddInMemoryCollection(initialData).Build();

// Add services to the container.
DashboardApp = new DashboardWebApplication(
options: new WebApplicationOptions
{
EnvironmentName = "Development",
ContentRootPath = aspireAssemblyDirectory,
WebRootPath = Path.Combine(aspireAssemblyDirectory, "wwwroot"),
ApplicationName = aspireDashboardAssemblyName,
},
preConfigureBuilder: builder =>
{
builder.Configuration.AddConfiguration(config);
},
postConfigureBuilder: builder =>
{
builder.Services.RemoveAll<IDashboardClient>();
builder.Services.AddSingleton<IDashboardClient, MockDashboardClient>();
});

return DashboardApp.StartAsync();
}

public Task DisposeAsync()
{
return DashboardApp.DisposeAsync().AsTask();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Frozen;
using System.Collections.Immutable;
using Aspire.Dashboard.Model;
using Google.Protobuf.WellKnownTypes;

namespace Aspire.Dashboard.Tests.Integration.Playwright;

public sealed class MockDashboardClient : IDashboardClient
{
public static readonly ResourceViewModel TestResource1 = new()
{
Name = "TestResource",
DisplayName = "TestResource",
Commands = ImmutableArray<CommandViewModel>.Empty,
CreationTimeStamp = DateTime.Now,
Environment = ImmutableArray<EnvironmentVariableViewModel>.Empty,
ResourceType = KnownResourceTypes.Project,
Properties = new []
{
new KeyValuePair<string, Value>(KnownProperties.Project.Path, new Value()
{
StringValue = "C:/MyProjectPath/Project.csproj"
})
}.ToFrozenDictionary(),
State = "Running",
Uid = Guid.NewGuid().ToString(),
StateStyle = null,
Urls = ImmutableArray<UrlViewModel>.Empty,

};

public bool IsEnabled => true;
public Task WhenConnected => Task.CompletedTask;
public string ApplicationName => "IntegrationTestApplication";
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
public Task<ResourceCommandResponseViewModel> ExecuteResourceCommandAsync(string resourceName, string resourceType, CommandViewModel command, CancellationToken cancellationToken) => throw new NotImplementedException();
public IAsyncEnumerable<IReadOnlyList<ResourceLogLine>>? SubscribeConsoleLogs(string resourceName, CancellationToken cancellationToken) => throw new NotImplementedException();

public Task<ResourceViewModelSubscription> SubscribeResourcesAsync(CancellationToken cancellationToken)
{
return Task.FromResult(new ResourceViewModelSubscription(
[TestResource1],
Test()
));
}

private static async IAsyncEnumerable<IReadOnlyList<ResourceViewModelChange>> Test()
{
await Task.CompletedTask;
yield return new List<ResourceViewModelChange> { };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Workload.Tests;
using Microsoft.Playwright;
using Xunit;

namespace Aspire.Dashboard.Tests.Integration.Playwright;

public class PlaywrightFixture : IAsyncLifetime
{
public IBrowser Browser { get; set; } = null!;

public async Task InitializeAsync()
{
PlaywrightProvider.DetectAndSetInstalledPlaywrightDependenciesPath();
Browser = await PlaywrightProvider.CreateBrowserAsync();
}

public async Task DisposeAsync()
{
await Browser.CloseAsync();
}

public async Task GoToHomeAndWaitForDataGridLoad(IPage page)
{
await page.GotoAsync("/");
await Assertions
.Expect(page.GetByText(MockDashboardClient.TestResource1.DisplayName))
.ToBeVisibleAsync();
}
}
Loading

0 comments on commit 0741157

Please sign in to comment.