Skip to content

Commit

Permalink
refactor: replace xunit with nunit
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Oct 14, 2024
1 parent 88c5e38 commit 777b479
Show file tree
Hide file tree
Showing 64 changed files with 2,038 additions and 2,430 deletions.
5 changes: 2 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#tool dotnet:?package=NuGetKeyVaultSignTool&version=3.2.3
#tool dotnet:?package=AzureSignTool&version=4.0.1
#tool dotnet:?package=GitReleaseManager.Tool&version=0.15.0
#tool dotnet:?package=XamlStyler.Console&version=3.2206.4

#tool dotnet:?package=XamlStyler.Console&version=3.2404.2
#tool nuget:?package=GitVersion.CommandLine&version=5.12.0
#tool nuget:?package=xunit.runner.console&version=2.9.2
#tool nuget:?package=NUnit.ConsoleRunner&version=3.18.3

#addin nuget:?package=Cake.Figlet&version=2.0.1

Expand Down
9 changes: 4 additions & 5 deletions src/Directory.packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
<PackageVersion Include="WpfAnalyzers" Version="4.1.1" />
</ItemGroup>
<ItemGroup Label="Test">
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.runner.console" Version="2.9.2" />
<PackageVersion Include="xunit.analyzers" Version="1.16.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.3.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions src/MahApps.Metro.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28711.60
# Visual Studio Version 17
VisualStudioVersion = 17.11.35312.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MahApps.Metro", "MahApps.Metro\MahApps.Metro.csproj", "{F6432F90-04C2-42B9-992B-CD828729976B}"
EndProject
Expand All @@ -14,6 +14,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EC5373FC-2098-4D7B-8990-B15E9C631AE8}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
..\build.cake = ..\build.cake
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.packages.props = Directory.packages.props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,27 @@ static MultiSelectionComboBox()

public MultiSelectionComboBox()
{
this.SetValue(SelectedItemsPropertyKey, new ObservableCollection<object>());
var collection = new ObservableCollection<object>();
this.SetValue(SelectedItemsPropertyKey, collection);
}

/// <summary>
/// Raise the SelectionChanged event.
/// </summary>
private void InvokeSelectionChanged(IList removedItems, IList addedItems)
{
var selectionChanged = new SelectionChangedEventArgs(
Selector.SelectionChangedEvent,
removedItems,
addedItems)
{
Source = this
};

base.OnSelectionChanged(selectionChanged);

this.UpdateDisplaySelectedItems();
this.UpdateEditableText();
}

#endregion
Expand Down Expand Up @@ -842,7 +862,7 @@ private void UpdateDisplaySelectedItems(SelectedItemsOrderType selectedItemsOrde

private void SelectItemsFromText(int millisecondsToWait)
{
if (!this.isUserdefinedTextInputPending || this.isTextChanging)
if (!this.IsEditable || !this.isUserdefinedTextInputPending || this.isTextChanging)
{
return;
}
Expand Down Expand Up @@ -1114,7 +1134,7 @@ private static void ExecutedClearContentCommand(object sender, ExecutedRoutedEve
}
}

multiSelectionCombo.ResetEditableText(true);
//multiSelectionCombo.ResetEditableText(true);
}
}

Expand Down Expand Up @@ -1186,14 +1206,16 @@ public override void OnApplyTemplate()

if (this.PART_PopupListBox is not null)
{
this.BeginInvoke(() =>
{
this.PART_PopupListBox.SelectionChanged += this.PART_PopupListBox_SelectionChanged;

this.SyncSelectedItems(this.SelectedItems, this.PART_PopupListBox.SelectedItems, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

this.PART_PopupListBox.SelectionChanged -= this.PART_PopupListBox_SelectionChanged;
}, DispatcherPriority.DataBind);
this.PART_PopupListBox.SelectionChanged += this.PART_PopupListBox_SelectionChanged;
this.SyncSelectedItems(this.SelectedItems, this.PART_PopupListBox.SelectedItems, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
this.PART_PopupListBox.SelectionChanged -= this.PART_PopupListBox_SelectionChanged;

//this.BeginInvoke(() =>
// {
// this.PART_PopupListBox.SelectionChanged += this.PART_PopupListBox_SelectionChanged;
// this.SyncSelectedItems(this.SelectedItems, this.PART_PopupListBox.SelectedItems, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
// this.PART_PopupListBox.SelectionChanged -= this.PART_PopupListBox_SelectionChanged;
// }, DispatcherPriority.DataBind);
}

// Do update the text and selection
Expand Down Expand Up @@ -1837,6 +1859,34 @@ private void SelectedItemsImpl_CollectionChanged(object sender, NotifyCollection
#endif
{
this.SyncSelectedItems(sender as IList, this.PART_PopupListBox?.SelectedItems, e);

switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
if (e.NewItems is not null)
{
this.InvokeSelectionChanged(new List<object>(), e.NewItems.Cast<object>().ToList());
}

break;
case NotifyCollectionChangedAction.Remove:
if (e.OldItems is not null)
{
this.InvokeSelectionChanged(e.OldItems.Cast<object>().ToList(), new List<object>());
}

break;
case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Replace:
if (e.NewItems is not null && e.OldItems is not null)
{
this.InvokeSelectionChanged(e.OldItems.Cast<object>().ToList(), e.NewItems.Cast<object>().ToList());
}

break;
case NotifyCollectionChangedAction.Move:
break; // order within SelectedItems doesn't matter
}
}

private void SyncSelectedItems(IList? sourceCollection, IList? targetCollection, NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -1953,6 +2003,7 @@ private void PART_SelectedItemsPresenter_MouseLeftButtonUp(object sender, MouseB
{
// If we have a ScrollViewer (ListBox has) we need to handle this event here as it will not be forwarded to the ToggleButton
this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.Box(!this.IsDropDownOpen));
e.Handled = true;
}

private void PART_SelectedItemsPresenter_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
26 changes: 26 additions & 0 deletions src/Mahapps.Metro.Tests/AssemblySetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading;
using System.Windows;
using System.Windows.Threading;
using NUnit.Framework;

namespace MahApps.Metro.Tests
{
[SetUpFixture]
public class AssemblySetup
{
[OneTimeSetUp]
public void Setup()
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());

var app = new TestApp { ShutdownMode = ShutdownMode.OnExplicitShutdown };
app.InitializeComponent();
}

[OneTimeTearDown]
public void TearDown()
{
Dispatcher.CurrentDispatcher.InvokeShutdown();
}
}
}
10 changes: 6 additions & 4 deletions src/Mahapps.Metro.Tests/MahApps.Metro.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
<PackageReference Include="xunit.runner.console" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
<PackageReference Include="xunit.analyzers" PrivateAssets="all" IncludeAssets="build; analyzers" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="NUnit.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Mahapps.Metro.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: NUnit.Framework.Apartment(System.Threading.ApartmentState.STA)]
1 change: 0 additions & 1 deletion src/Mahapps.Metro.Tests/TestApp.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Themes/Generic.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
33 changes: 0 additions & 33 deletions src/Mahapps.Metro.Tests/TestHelpers/ApplicationFixture.cs

This file was deleted.

49 changes: 0 additions & 49 deletions src/Mahapps.Metro.Tests/TestHelpers/AutomationTestBase.cs

This file was deleted.

20 changes: 0 additions & 20 deletions src/Mahapps.Metro.Tests/TestHelpers/AutomationTestFixtureBase.cs

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 777b479

Please sign in to comment.