Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<GlobalLangVersion>preview</GlobalLangVersion>

<MSTestVersion>3.11.0</MSTestVersion>

<!--
This version is the minimum supported version by LiveCharts,
currently only used by Avalonia, if you need to downgrade any view package,
Expand Down
83 changes: 83 additions & 0 deletions LiveCharts.Tests.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<Solution>
<Configurations>
<BuildType Name="Ad-Hoc" />
<BuildType Name="AppStore" />
<BuildType Name="Debug" />
<BuildType Name="Release" />
<Platform Name="Any CPU" />
<Platform Name="ARM" />
<Platform Name="ARM64" />
<Platform Name="iPhone" />
<Platform Name="iPhoneSimulator" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Folder Name="/Generators/">
<Project Path="generators/LiveChartsGenerators/LiveChartsGenerators.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
</Folder>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path="Directory.Build.props" />
<File Path="global.json" />
</Folder>
<Folder Name="/Solution Items/RenderingSettings/">
<File Path="build/RenderSettings.Build.props" />
</Folder>
<Folder Name="/Tests/">
<Project Path="tests/LiveChartsCore.UnitTesting/LiveChartsCore.UnitTesting.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="tests/Test.WPF/Test.WPF.csproj" Id="9a7da9ad-2572-45ca-a563-8f8da83518ad">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
</Folder>
<Project Path="src/LiveChartsCore/LiveChartsCore.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Debug" />
<BuildType Solution="AppStore|*" Project="Debug" />
</Project>
<Project Path="src/skiasharp/_Shared.WinUI/_Shared.WinUI.shproj" Id="e98bb79a-300e-4556-ac59-47a9aaf1d5f1" />
<Project Path="src/skiasharp/_Shared.Xaml/_Shared.Xaml.shproj" />
<Project Path="src/skiasharp/_Shared/_Shared.shproj" />
<Project Path="src/_Shared.Native/_Shared.Native.shproj" Id="ebf70b6d-1416-4cc6-a540-f4ebf2371819" />
</Solution>
4 changes: 4 additions & 0 deletions LiveCharts.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
<Project Path="tests/Test.WPF/Test.WPF.csproj" Id="9a7da9ad-2572-45ca-a563-8f8da83518ad">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
<BuildType Solution="AppStore|*" Project="Release" />
</Project>
</Folder>
<Project Path="src/LiveChartsCore/LiveChartsCore.csproj">
<BuildType Solution="Ad-Hoc|*" Project="Release" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// The MIT License(MIT)
//
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using LiveChartsCore.Drawing;
using LiveChartsCore.Geo;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.Motion;
using LiveChartsCore.Vortice;
using Vortice;
using Vortice.Direct2D1;

namespace LiveChartsGeneratedCode;

/// <inheritdoc cref="IGeoMapView" />
public partial class SourceGenMapChart : IMyUIFrameworkControl
{
public IMyUIFrameworkControl[] Children { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="SourceGenMapChart"/> class.
/// </summary>
public SourceGenMapChart()
{
var motionCanvas = new MotionCanvas();
Children = [motionCanvas];

InitializeChartControl();
}

/// <inheritdoc cref="IDrawnView.CoreCanvas"/>
public CoreMotionCanvas CoreCanvas => ((MotionCanvas)Children[0]).CanvasCore;
public bool DesignerMode => false;
public LvcSize ControlSize => new()
{
Width = Application.Current!.MainWindow!.Bounds.Width,
Height = Application.Current.MainWindow.Bounds.Height
};

public void InvokeOnUIThread(Action action) =>
action();

public void DrawFrame(ID2D1HwndRenderTarget renderTarget)
{
foreach (var control in Children)
control.DrawFrame(renderTarget);
}

public void Measure() =>
CoreChart.Measure();
}
2 changes: 1 addition & 1 deletion src/skiasharp/_Shared.WinUI/GeoMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.Geo;

namespace LiveChartsCore.SkiaSharpView.WinUI;

Expand Down
1 change: 0 additions & 1 deletion src/skiasharp/_Shared/SourceGenMapChart.sgp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using System;
using LiveChartsCore.Painting;
using System.Collections.Generic;
using SkiaSharp;
using LiveChartsCore.Drawing;

#if SKIA_IMAGE_LVC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>

Expand Down
135 changes: 135 additions & 0 deletions tests/Test.WPF/CartesianChartTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System.Windows.Controls;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.WPF;

namespace Test.WPF;

[TestClass]
public sealed class CartesianChartTests
{
public TestContext TestContext { get; set; }

[TestMethod]
public void Loads()
{
TestApp.Run(
() => new WPFSample.General.FirstChart.View(),
async ctx =>
{
// wait for loading and animations to complete
await Task.Delay(2000, TestContext.CancellationToken);

var view = (WPFSample.General.FirstChart.View)ctx.SUT;
var chart = (CartesianChart)view.Content;
var series = chart.Series.First();

if (!chart.CoreChart.IsLoaded)
ctx.Throw("Chart is not loaded");

var points = series.Fetch(chart.CoreChart).ToArray();

var hasValidRects = points.Length > 0 &&
points.All(x =>
{
// this only validates that rectangles have a size and position
// but the proper scale and position is tested in other tests

var v = x.Context.Visual;
return v is not null && v.X > 0 && v.Y > 0;
});

if (!hasValidRects)
ctx.Throw("The series does not have valid rectangles.");

ctx.EndTest();
});
}

[TestMethod]
public void Rehydrates()
{
Grid grid = null!;
UserControl sample = null!;

TestApp.Run(
() =>
{
grid = new Grid();
sample = new WPFSample.Bars.Basic.View();

return grid;
},
async ctx =>
{
var loads = 0;
var unloads = 0;

sample.Loaded += (_, _) => loads++;
sample.Unloaded += (_, _) => unloads++;

_ = grid.Children.Add(sample);
await Task.Delay(2000, TestContext.CancellationToken);

grid.Children.Remove(sample);
await Task.Delay(500, TestContext.CancellationToken);

_ = grid.Children.Add(sample);
await Task.Delay(2000, TestContext.CancellationToken);

grid.Children.Remove(sample);
await Task.Delay(500, TestContext.CancellationToken);

if (loads != 2 || unloads != 2)
ctx.Throw($"Expected 2 load and 2 unload events, got {loads} load and {unloads} unload events.");

ctx.EndTest();
});
}

[TestMethod]
public void Tabbed()
{
TabControl tabs = null!;
CartesianChart chart = null!;
ColumnSeries<int> series = null!;

TestApp.Run(
() =>
{
var firstTab = new TabItem
{
Header = "Tab 1",
Content = chart = new CartesianChart
{
Series = [series = new ColumnSeries<int>([1, 5, 1, 5])]
}
};

var secondTab = new TabItem
{
Header = "Tab 2",
Content = new TextBlock { Text = "Hello World" }
};

tabs = new TabControl();

_ = tabs.Items.Add(firstTab);
_ = tabs.Items.Add(secondTab);

return tabs;
},
async ctx =>
{
await Task.Delay(1000, TestContext.CancellationToken);
tabs.SelectedIndex = 1;
await Task.Delay(1000, TestContext.CancellationToken);
tabs.SelectedIndex = 0;
await Task.Delay(1000, TestContext.CancellationToken);
tabs.SelectedIndex = 1;
await Task.Delay(1000, TestContext.CancellationToken);

ctx.EndTest();
});
}
}
1 change: 1 addition & 0 deletions tests/Test.WPF/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: DoNotParallelize]
27 changes: 27 additions & 0 deletions tests/Test.WPF/Test.WPF.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<LangVersion>$(GlobalLangVersion)</LangVersion>
<TargetFramework>net8.0-windows10.0.19041</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\samples\WPFSample\WPFSample.csproj" />
<ProjectReference Include="..\..\src\skiasharp\LiveChartsCore.SkiaSharp.WPF\LiveChartsCore.SkiaSharpView.WPF.csproj" />
</ItemGroup>

</Project>
Loading
Loading