项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,61 @@
namespace Fluent.Tests.Adorners
{
using System.Windows.Controls;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class KeyTipAdornerTests
{
[Test]
public void Adorner_Should_Properly_Grab_Keys_From_KeyTipInformationProvider()
{
{
var splitButton = new SplitButton();
var panel = new Grid();
panel.Children.Add(splitButton);
using (var window = new TestRibbonWindow(panel))
{
var adorner = new KeyTipAdorner(splitButton, panel, null);
Assert.That(adorner.KeyTipInformations, Has.Count.EqualTo(0));
}
}
{
var splitButton = new SplitButton
{
KeyTip = "A"
};
var panel = new Grid();
panel.Children.Add(splitButton);
using (var window = new TestRibbonWindow(panel))
{
var adorner = new KeyTipAdorner(splitButton, panel, null);
Assert.That(adorner.KeyTipInformations, Has.Count.EqualTo(2));
Assert.That(adorner.KeyTipInformations[0].Keys, Is.EqualTo("AA"));
Assert.That(adorner.KeyTipInformations[1].Keys, Is.EqualTo("AB"));
}
}
{
var splitButton = new SplitButton
{
SecondaryKeyTip = "B"
};
var panel = new Grid();
panel.Children.Add(splitButton);
using (var window = new TestRibbonWindow(panel))
{
var adorner = new KeyTipAdorner(splitButton, panel, null);
Assert.That(adorner.KeyTipInformations, Has.Count.EqualTo(1));
Assert.That(adorner.KeyTipInformations[0].Keys, Is.EqualTo("B"));
}
}
}
}
}

View File

@@ -0,0 +1,28 @@
namespace Fluent.Tests
{
using System;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
using NUnit.Framework;
[SetUpFixture]
public class AssemblySetup
{
[OneTimeSetUp]
public void Setup()
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
app.Resources.MergedDictionaries.Add((ResourceDictionary)Application.LoadComponent(new Uri("/Fluent;component/Themes/Generic.xaml", UriKind.Relative)));
}
[OneTimeTearDown]
public void TearDown()
{
Dispatcher.CurrentDispatcher.InvokeShutdown();
}
}
}

View File

@@ -0,0 +1,66 @@
namespace Fluent.Tests.Collections
{
using System.Collections.ObjectModel;
using Fluent.Collections;
using NUnit.Framework;
[TestFixture]
public class CollectionSyncHelperTests
{
[Test]
public void NewInstanceShouldCopyItems()
{
var source = new ObservableCollection<string> { "One", "Two" };
var target = new ObservableCollection<string>();
Assert.That(target, Is.Not.EquivalentTo(source));
var sync = new CollectionSyncHelper<string>(source, target);
Assert.That(target, Is.EquivalentTo(source));
}
[Test]
public void CollectionActionShouldSync()
{
var source = new ObservableCollection<string>();
var target = new ObservableCollection<string>();
Assert.That(target, Is.EquivalentTo(source));
var sync = new CollectionSyncHelper<string>(source, target);
Assert.That(target, Is.EquivalentTo(source));
{
source.Add("One");
Assert.That(target, Is.EquivalentTo(source));
}
{
source.RemoveAt(0);
Assert.That(target, Is.EquivalentTo(source));
}
{
source.Add("One");
Assert.That(target, Is.EquivalentTo(source));
}
{
source[0] = "Two";
Assert.That(target, Is.EquivalentTo(source));
}
{
source.Clear();
Assert.That(target, Is.EquivalentTo(source));
}
}
}
}

View File

@@ -0,0 +1,269 @@
namespace Fluent.Tests.Collections
{
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using Fluent.Collections;
using NUnit.Framework;
[TestFixture]
public class ItemCollectionWithLogicalTreeSupportTests
{
[Test]
public void EmptyCollection()
{
var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
Assert.That(collection.IsOwningItems, Is.True);
Assert.That(collection, Is.Empty);
}
[Test]
public void AddRemoveNullDoesNotThrow()
{
var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
Assert.That(() => collection.Remove(null), Throws.Nothing);
Assert.That(() => collection.Add(null), Throws.Nothing);
}
[Test]
public void AquireAndReleaseDoesNotThrowOnEmptyCollection()
{
var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
Assert.That(() => collection.AquireLogicalOwnership(), Throws.Nothing);
Assert.That(() => collection.ReleaseLogicalOwnership(), Throws.Nothing);
}
[Test]
public void CollectionOperationsWorkAsExpected()
{
var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
var item1 = "Item_1";
var item2 = "Item_2";
var item3 = "Item_3";
// add items
{
collection.Add(item1);
collection.Add(item2);
collection.Add(item3);
}
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
collection.Clear();
Assert.That(collection, Is.Empty);
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
// add items
{
collection.Add(item1);
collection.Add(item2);
collection.Add(item3);
}
collection.RemoveAt(1);
Assert.That(collection, Is.EquivalentTo(new[] { item1, item3 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
collection[1] = item2;
Assert.That(collection, Is.EquivalentTo(new[] { item1, item2 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
collection.Insert(0, item3);
Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
collection.ReleaseLogicalOwnership();
Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
Assert.That(collection.GetLogicalChildren(), Is.Empty);
Assert.That(() => collection.ReleaseLogicalOwnership(), Throws.Nothing);
Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
Assert.That(collection.GetLogicalChildren(), Is.Empty);
var item4 = "Item_4";
collection.Add(item4);
Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2, item4 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
Assert.That(collection.GetLogicalChildren(), Is.Empty);
collection.AquireLogicalOwnership();
Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2, item4 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
Assert.That(() => collection.AquireLogicalOwnership(), Throws.Nothing);
Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));
collection.ReleaseLogicalOwnership();
collection.Remove(item4);
Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
Assert.That(collection.GetLogicalChildren(), Is.Empty);
}
[Test]
public void AddRemoveWorksAsExpectedWithNoFEParent()
{
var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
var objItem = new object();
{
collection.Add(objItem);
Assert.That(collection, Does.Contain(objItem));
Assert.That(logicalChildSupportStub.LogicalChildren, Does.Contain(objItem));
Assert.That(collection.GetLogicalChildren(), Does.Contain(objItem));
}
var frameworkElement = new FrameworkElement();
{
collection.Add(frameworkElement);
Assert.That(collection, Does.Contain(frameworkElement));
Assert.That(logicalChildSupportStub.LogicalChildren, Does.Contain(frameworkElement));
Assert.That(collection.GetLogicalChildren(), Does.Contain(frameworkElement));
}
var frameworkContentElement = new FrameworkContentElement();
{
collection.Add(frameworkContentElement);
Assert.That(collection, Does.Contain(frameworkContentElement));
Assert.That(logicalChildSupportStub.LogicalChildren, Does.Contain(frameworkContentElement));
Assert.That(collection.GetLogicalChildren(), Does.Contain(frameworkContentElement));
}
// Remove
{
collection.Remove(frameworkElement);
Assert.That(collection, Does.Not.Contain(frameworkElement));
Assert.That(logicalChildSupportStub.LogicalChildren, Does.Not.Contain(frameworkElement));
Assert.That(collection.GetLogicalChildren(), Does.Not.Contain(frameworkElement));
}
}
[Test]
public void AddRemoveWorksAsExpectedWithFEParent()
{
var logicalChildSupportStub = new LogicalChildSupportFEStub();
var collection = new ItemCollectionWithLogicalTreeSupport<object>(logicalChildSupportStub);
var objItem = new object();
{
collection.Add(objItem);
Assert.That(collection, Does.Contain(objItem));
Assert.That(LogicalTreeHelper.GetChildren(logicalChildSupportStub), Does.Contain(objItem));
Assert.That(collection.GetLogicalChildren(), Does.Contain(objItem));
}
var frameworkElement = new FrameworkElement();
{
collection.Add(frameworkElement);
Assert.That(collection, Does.Contain(frameworkElement));
Assert.That(LogicalTreeHelper.GetChildren(logicalChildSupportStub), Does.Contain(frameworkElement));
Assert.That(collection.GetLogicalChildren(), Does.Contain(frameworkElement));
}
var frameworkContentElement = new FrameworkContentElement();
{
collection.Add(frameworkContentElement);
Assert.That(collection, Does.Contain(frameworkContentElement));
Assert.That(LogicalTreeHelper.GetChildren(logicalChildSupportStub), Does.Contain(frameworkContentElement));
Assert.That(collection.GetLogicalChildren(), Does.Contain(frameworkContentElement));
}
// Remove
{
collection.Remove(frameworkElement);
Assert.That(collection, Does.Not.Contain(frameworkElement));
Assert.That(LogicalTreeHelper.GetChildren(logicalChildSupportStub), Does.Not.Contain(frameworkElement));
Assert.That(collection.GetLogicalChildren(), Does.Not.Contain(frameworkElement));
}
}
private class LogicalChildSupportNoFEStub : ILogicalChildSupport
{
public List<object> LogicalChildren { get; } = new List<object>();
/// <inheritdoc />
void ILogicalChildSupport.AddLogicalChild(object child)
{
this.LogicalChildren.Add(child);
}
/// <inheritdoc />
void ILogicalChildSupport.RemoveLogicalChild(object child)
{
this.LogicalChildren.Remove(child);
}
}
private class LogicalChildSupportFEStub : FrameworkElement, ILogicalChildSupport
{
private List<object> MyLogicalChildren { get; } = new List<object>();
/// <inheritdoc />
void ILogicalChildSupport.AddLogicalChild(object child)
{
this.MyLogicalChildren.Add(child);
this.AddLogicalChild(child);
}
/// <inheritdoc />
void ILogicalChildSupport.RemoveLogicalChild(object child)
{
this.MyLogicalChildren.Remove(child);
this.RemoveLogicalChild(child);
}
/// <inheritdoc />
protected override IEnumerator LogicalChildren => this.MyLogicalChildren.GetEnumerator();
}
}
}

View File

@@ -0,0 +1,43 @@
namespace Fluent.Tests.Controls
{
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class BackstageTests
{
/// <summary>
/// This test ensures that the <see cref="BackstageAdorner"/> is destroyed as soon as the <see cref="Backstage"/> is unloaded.
/// </summary>
[Test]
public void Adorner_should_be_destroyed_on_unload()
{
var backstage = new Backstage
{
Content = new Button()
};
using (var window = new TestRibbonWindow(backstage))
{
Assert.That(backstage.IsLoaded, Is.True);
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Null);
backstage.IsOpen = true;
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Not.Null);
backstage.IsOpen = false;
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Not.Null);
window.Content = null;
UIHelper.DoEvents();
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Null);
}
}
}
}

View File

@@ -0,0 +1,24 @@
namespace Fluent.Tests.Controls
{
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class InRibbonGalleryTests
{
[Test]
public void Opening_DropDown_Should_Not_Throw_When_GalleryPanel_Has_No_Width()
{
var control = new InRibbonGallery
{
Width = 10,
Height = 30
};
using (new TestRibbonWindow(control))
{
Assert.That(() => control.IsDropDownOpen = true, Throws.Nothing);
}
}
}
}

View File

@@ -0,0 +1,71 @@
namespace Fluent.Tests.Controls
{
using System.Globalization;
using System.Linq;
using System.Windows;
using NUnit.Framework;
[TestFixture]
public class QuickAccessToolBarTests
{
[Test]
public void TestDefaultKeyTips()
{
var toolbar = new QuickAccessToolBar();
for (var i = 0; i < 30; i++)
{
toolbar.Items.Add(new UIElement());
}
TestDefaultKeyTips(toolbar);
}
private static void TestDefaultKeyTips(QuickAccessToolBar toolbar)
{
var keyTips = toolbar.Items.Select(KeyTip.GetKeys);
var expectedKeyTips = new[]
{
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"09", "08", "07", "06", "05", "04", "03", "02", "01",
"0A", "0B", "0C", "0D", "0E", "0F", "0G", "0H", "0I", "0J", "0K", "0L"
};
Assert.That(keyTips, Is.EquivalentTo(expectedKeyTips));
}
[Test]
public void TestCustomKeyTips()
{
var toolbar = new QuickAccessToolBar
{
UpdateKeyTipsAction = quickAccessToolBar =>
{
for (var i = 0; i < quickAccessToolBar.Items.Count; i++)
{
KeyTip.SetKeys(quickAccessToolBar.Items[i], (i + 1).ToString("00", CultureInfo.InvariantCulture));
}
}
};
for (var i = 0; i < 30; i++)
{
toolbar.Items.Add(new UIElement());
}
var keyTips = toolbar.Items.Select(KeyTip.GetKeys);
var expectedKeyTips = new[]
{
"01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"
};
Assert.That(keyTips, Is.EquivalentTo(expectedKeyTips));
toolbar.UpdateKeyTipsAction = null;
TestDefaultKeyTips(toolbar);
}
}
}

View File

@@ -0,0 +1,115 @@
namespace Fluent.Tests.Controls
{
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class RibbonGroupBoxTests
{
[Test]
public void Size_Should_Change_On_Group_State_Change_When_Items_Are_Bound()
{
var items = new List<ItemViewModel>
{
new ItemViewModel()
};
var ribbonGroupBox = new RibbonGroupBox
{
ItemsSource = items,
ItemTemplate = CreateDataTemplateForItemViewModel()
};
using (new TestRibbonWindow(ribbonGroupBox))
{
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Small;
UIHelper.DoEvents();
}
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Small));
}
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Middle;
UIHelper.DoEvents();
}
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Middle));
}
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Large;
UIHelper.DoEvents();
}
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Large));
}
}
}
[Test]
public void Size_Should_Change_On_Group_State_Change_When_Items_Are_Ribbon_Controls()
{
var ribbonGroupBox = new RibbonGroupBox();
ribbonGroupBox.Items.Add(new Fluent.Button());
using (new TestRibbonWindow(ribbonGroupBox))
{
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Small;
UIHelper.DoEvents();
}
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Small));
}
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Middle;
UIHelper.DoEvents();
}
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Middle));
}
{
{
ribbonGroupBox.State = RibbonGroupBoxState.Large;
UIHelper.DoEvents();
}
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Large));
}
}
}
private static DataTemplate CreateDataTemplateForItemViewModel()
{
var dataTemplate = new DataTemplate(typeof(ItemViewModel));
var factory = new FrameworkElementFactory(typeof(Fluent.Button));
factory.SetBinding(RibbonProperties.SizeProperty, new Binding(nameof(ItemViewModel.ControlSize)) { Mode = BindingMode.TwoWay });
//set the visual tree of the data template
dataTemplate.VisualTree = factory;
return dataTemplate;
}
}
public class ItemViewModel
{
public RibbonControlSize ControlSize { get; set; }
}
}

View File

@@ -0,0 +1,309 @@
namespace Fluent.Tests.Controls
{
using System.Collections;
using System.Linq;
using System.Windows.Controls;
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
using ComboBox = Fluent.ComboBox;
using TextBox = Fluent.TextBox;
[TestFixture]
public class RibbonGroupBoxWrapPanelTests
{
private static RibbonGroupBox CreateRibbonGroupBox(bool isSharedSizeScope)
{
var ribbonGroupBox = new RibbonGroupBox
{
Header = "Test-Header",
Height = 94
};
Grid.SetIsSharedSizeScope(ribbonGroupBox, isSharedSizeScope);
AddControls(ribbonGroupBox.Items);
return ribbonGroupBox;
}
private static void AddControls(IList items)
{
items.Add(new TextBox
{
Header = "First Column (1)"
});
items.Add(new ComboBox
{
Header = "First Column (2)"
});
items.Add(new Spinner
{
Header = "First Column Long"
});
items.Add(new ComboBox
{
Header = "Second Column (1)"
});
items.Add(new ComboBox
{
Header = "Second Column (2) Long Long"
});
items.Add(new Spinner
{
Header = "Second Column"
});
}
private static TextBlock GetHeaderTextBlock(Control control)
{
return (TextBlock)control.Template.FindName("headerTextBlock", control);
}
[Test]
public void SharedSizeGroupName_Should_Be_Possible_To_Opt_Out()
{
var ribbonGroupBox = CreateRibbonGroupBox(true);
using (new TestRibbonWindow(ribbonGroupBox))
{
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
RibbonGroupBoxWrapPanel.SetExcludeFromSharedSize(controls[1], true);
RibbonGroupBoxWrapPanel.SetExcludeFromSharedSize(controls[5], true);
UIHelper.DoEvents();
// First column
{
var columnControls = controls.Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
{
"SharedSizeGroup_Column_1",
null,
"SharedSizeGroup_Column_1"
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
96,
84,
96
}));
}
// Second column
{
var columnControls = controls.Skip(3).Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
{
"SharedSizeGroup_Column_2",
"SharedSizeGroup_Column_2",
null
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
160,
160,
84
}));
}
}
}
[Test]
public void SharedSizeGroupName_Should_Be_Set_If_RibbonGroupBox_Is_SharedSizeScope()
{
var ribbonGroupBox = CreateRibbonGroupBox(true);
using (new TestRibbonWindow(ribbonGroupBox))
{
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
// First column
{
var columnControls = controls.Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
{
"SharedSizeGroup_Column_1",
"SharedSizeGroup_Column_1",
"SharedSizeGroup_Column_1"
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
96,
96,
96
}));
}
// Second column
{
var columnControls = controls.Skip(3).Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
{
"SharedSizeGroup_Column_2",
"SharedSizeGroup_Column_2",
"SharedSizeGroup_Column_2"
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
160,
160,
160
}));
}
}
}
[Test]
public void SharedSizeGroupName_Should_Not_Be_Set_If_RibbonGroupBox_Is_Not_SharedSizeScope()
{
var ribbonGroupBox = CreateRibbonGroupBox(false);
using (new TestRibbonWindow(ribbonGroupBox))
{
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
// First column
{
var columnControls = controls.Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
{
null,
null,
null
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
84,
84,
96
}));
}
// Second column
{
var columnControls = controls.Skip(3).Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
{
null,
null,
null
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
101,
160,
84
}));
}
}
}
/// <summary>
/// Test for not working because we have to test for <see cref="Grid.IsSharedSizeScopeProperty" /> on parent
/// <see cref="RibbonGroupBox" />.
/// </summary>
[Test]
public void SharedSizeGroupName_Should_Not_Work_Without_RibbonGroupBox()
{
var ribbonGroupBoxWrapPanel = new RibbonGroupBoxWrapPanel
{
Height = 94
};
AddControls(ribbonGroupBoxWrapPanel.Children);
using (new TestRibbonWindow(ribbonGroupBoxWrapPanel))
{
var controls = ribbonGroupBoxWrapPanel.Children.Cast<Control>().ToList();
// First column
{
var columnControls = controls.Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
{
null,
null,
null
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
84,
84,
96
}));
}
// Second column
{
var columnControls = controls.Skip(3).Take(3).ToList();
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
{
null,
null,
null
}));
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
{
101,
160,
84
}));
}
}
}
}
}

View File

@@ -0,0 +1,162 @@
namespace Fluent.Tests.Controls
{
using System.Linq;
using System.Windows;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class RibbonTabsContainerTests
{
//private static readonly Size zeroSize = default;
private const double ReferenceWidth = 300;
private static readonly double ReferenceHeight = 26;
[Test]
public void Empty()
{
var container = new RibbonTabsContainer();
using (new TestRibbonWindow(container))
{
Assert.That(container.DesiredSize, Is.EqualTo(new Size(0, 0)));
}
}
[Test]
public void With_One_Tab()
{
var container = new RibbonTabsContainer();
var tabItem = new RibbonTabItem();
container.Children.Add(tabItem);
using (new TestRibbonWindow(container) { Width = ReferenceWidth })
{
Assert.That(container.DesiredSize, Is.EqualTo(new Size(16, ReferenceHeight)));
tabItem.Header = "ABC";
container.UpdateLayout();
Assert.That(container.DesiredSize, Is.EqualTo(new Size(38, ReferenceHeight)));
}
//await Task.Yield();
}
[Test]
public void With_Many_Tab()
{
var container = new RibbonTabsContainer();
var longestTab = new RibbonTabItem { Header = "Longest header text" };
var secondLongestTab = new RibbonTabItem { Header = "Header text" };
var middleTab = new RibbonTabItem { Header = "Header" };
var smallTab = new RibbonTabItem { Header = "Text" };
container.Children.Add(longestTab);
container.Children.Add(secondLongestTab);
container.Children.Add(middleTab);
container.Children.Add(smallTab);
var childrenWidths = new[]
{
longestTab,
secondLongestTab,
middleTab,
smallTab
}.Select(x => x.DesiredSize.Width);
using (var testWindow = new TestRibbonWindow(container) { Width = ReferenceWidth })
{
Assert.That(container.DesiredSize, Is.EqualTo(new Size(290, ReferenceHeight)));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
121,
78,
54,
37
}));
container.Measure(new Size(290, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(290, ReferenceHeight)));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
121,
78,
54,
37
}));
container.Measure(new Size(289, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(283, ReferenceHeight)));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
114,
78,
54,
37
}));
container.Measure(new Size(230, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(229, ReferenceHeight)));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
67,
71,
54,
37
}));
container.Measure(new Size(150, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(147, ReferenceHeight)));
Assert.That(container.ExtentWidth, Is.EqualTo(container.ViewportWidth));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
37,
33,
40,
37
}));
container.Measure(new Size(130, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(126, ReferenceHeight)));
Assert.That(container.ExtentWidth, Is.EqualTo(container.ViewportWidth));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
30,
33,
33,
30
}));
container.Measure(new Size(120, ReferenceHeight));
Assert.That(container.DesiredSize, Is.EqualTo(new Size(120, ReferenceHeight)));
Assert.That(container.ExtentWidth, Is.EqualTo(121));
Assert.That(childrenWidths, Is.EquivalentTo(new[]
{
30,
30,
30,
30
}));
}
//await Task.Yield();
}
}
}

View File

@@ -0,0 +1,213 @@
namespace Fluent.Tests.Controls
{
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class RibbonTests
{
[Test]
public void DependencyProperties_and_DataContext_should_be_inherited_from_window()
{
var ribbon = new Ribbon
{
Menu = new Backstage(),
StartScreen = new StartScreen()
};
var enUs = XmlLanguage.GetLanguage("en-US");
var deDe = XmlLanguage.GetLanguage("de-DE");
using (var window = new TestRibbonWindow(ribbon)
{
Language = deDe,
DataContext = deDe
})
{
ribbon.ApplyTemplate();
var elemens = new Dictionary<FrameworkElement, string>
{
{ ribbon, "Ribbon" },
{ ribbon.Menu, "Menu" },
{ ribbon.StartScreen, "StartScreen" },
{ ribbon.QuickAccessToolBar, "QuickAccessToolBar" },
{ ribbon.TabControl, "TabControl" },
{ (FrameworkElement)ribbon.Template.FindName("PART_LayoutRoot", ribbon), "PART_LayoutRoot" },
};
{
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
}
{
window.Language = enUs;
window.DataContext = window.Language;
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
}
{
window.Language = deDe;
window.DataContext = window.Language;
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
}
{
window.Language = enUs;
window.DataContext = window.Language;
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
}
}
}
[Test]
public void DependencyProperties_and_DataContext_should_be_inherited_from_ribbon()
{
var ribbon = new Ribbon
{
Menu = new Backstage(),
StartScreen = new StartScreen()
};
var enUs = XmlLanguage.GetLanguage("en-US");
var deDe = XmlLanguage.GetLanguage("de-DE");
using (var window = new TestRibbonWindow(ribbon)
{
Language = deDe,
DataContext = deDe
})
{
ribbon.ApplyTemplate();
var elemens = new Dictionary<FrameworkElement, string>
{
{ ribbon, "Ribbon" },
{ ribbon.Menu, "Menu" },
{ ribbon.StartScreen, "StartScreen" },
{ ribbon.QuickAccessToolBar, "QuickAccessToolBar" },
{ ribbon.TabControl, "TabControl" },
{ (FrameworkElement)ribbon.Template.FindName("PART_LayoutRoot", ribbon), "PART_LayoutRoot" },
};
{
Assert.That(ribbon.Language, Is.EqualTo(window.Language), "Language on Window should match.");
Assert.That(ribbon.DataContext, Is.EqualTo(window.DataContext), "DataContext on Window should match.");
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
}
{
ribbon.Language = enUs;
ribbon.DataContext = ribbon.Language;
Assert.That(ribbon.Language, Is.Not.EqualTo(window.Language), "Language on Ribbon should not match Window.");
Assert.That(ribbon.DataContext, Is.Not.EqualTo(window.DataContext), "DataContext on Ribbon should not match Window.");
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
}
{
ribbon.Language = deDe;
ribbon.DataContext = ribbon.Language;
Assert.That(ribbon.Language, Is.EqualTo(window.Language), "Language on Ribbon should match Window.");
Assert.That(ribbon.DataContext, Is.EqualTo(window.DataContext), "DataContext on Ribbon should match Window.");
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
}
{
ribbon.Language = enUs;
ribbon.DataContext = ribbon.Language;
Assert.That(ribbon.Language, Is.Not.EqualTo(window.Language), "Language on Ribbon should not match Window.");
Assert.That(ribbon.DataContext, Is.Not.EqualTo(window.DataContext), "DataContext on Ribbon should not match Window.");
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
}
}
}
private static void CheckIfAllElementsHaveSameValue(Dictionary<FrameworkElement, string> elements, DependencyProperty property, FrameworkElement expectedValueSource)
{
var expectedValue = expectedValueSource.GetValue(property);
foreach (var element in elements)
{
Assert.That(element.Key.GetValue(property), Is.EqualTo(expectedValue), $"{property.Name} on {element.Value} should match.");
}
}
[Test]
public void TitleBar_properties_synchronised_with_ribbon()
{
var ribbon = new Ribbon { ContextualGroups = { new RibbonContextualTabGroup() } };
using (new TestRibbonWindow(ribbon))
{
ribbon.ApplyTemplate();
Assert.IsNotNull(ribbon.QuickAccessToolBar);
var oldTitleBar = ribbon.TitleBar = new RibbonTitleBar();
Assert.AreEqual(1, oldTitleBar.Items.Count);
Assert.AreSame(ribbon.QuickAccessToolBar, oldTitleBar.QuickAccessToolBar);
var newTitleBar = new RibbonTitleBar();
Assert.AreEqual(0, newTitleBar.Items.Count);
Assert.IsNull(newTitleBar.QuickAccessToolBar);
// assign a new title bar, the contextual groups and quick access are transferred across
ribbon.TitleBar = newTitleBar;
Assert.AreEqual(0, oldTitleBar.Items.Count);
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
Assert.AreEqual(1, newTitleBar.Items.Count);
Assert.AreSame(ribbon.QuickAccessToolBar, newTitleBar.QuickAccessToolBar);
// remove the title bar
ribbon.TitleBar = null;
Assert.AreEqual(0, oldTitleBar.Items.Count);
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
Assert.AreEqual(0, newTitleBar.Items.Count);
Assert.IsNull(newTitleBar.QuickAccessToolBar);
}
}
[Test]
public void Test_KeyTipKeys()
{
var ribbon = new Ribbon();
var keyTipService = ribbon.GetFieldValue<KeyTipService>("keyTipService");
Assert.That(ribbon.KeyTipKeys, Is.Empty);
Assert.That(keyTipService.KeyTipKeys, Is.EquivalentTo(KeyTipService.DefaultKeyTipKeys));
ribbon.KeyTipKeys.Add(Key.A);
Assert.That(ribbon.KeyTipKeys, Is.EquivalentTo(new[]
{
Key.A
}));
Assert.That(keyTipService.KeyTipKeys, Is.EquivalentTo(new[]
{
Key.A
}));
}
}
}

View File

@@ -0,0 +1,190 @@
namespace Fluent.Tests.Controls
{
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class RibbonTitleBarTests
{
[TestFixture]
public class MeasureTests
{
private static readonly Size zeroSize = default;
private const double ReferenceWidth = 1024;
private static readonly double ReferenceHeight = SystemParameters.WindowCaptionHeight;
private static readonly Size referenceSize = new Size(ReferenceWidth, SystemParameters.WindowCaptionHeight);
private const string QuickaccessToolbarRect = "quickAccessToolbarRect";
private const string HeaderRect = "headerRect";
private const string ItemsRect = "itemsRect";
private static readonly double DefaultTitleBarHeight = SystemParameters.WindowCaptionHeight;
[Test]
public void Without_Parts()
{
var titlebar = new RibbonTitleBar();
titlebar.Measure(referenceSize);
Assert.That(titlebar.DesiredSize, Is.EqualTo(zeroSize));
}
[Test]
public void Empty()
{
var titlebar = new RibbonTitleBar();
using (new TestRibbonWindow(titlebar))
{
titlebar.Measure(referenceSize);
Assert.That(titlebar.DesiredSize, Is.EqualTo(new Size(2, DefaultTitleBarHeight)));
}
}
[Test]
public void Collapsed()
{
var titlebar = new RibbonTitleBar
{
IsCollapsed = true
};
using (new TestRibbonWindow(titlebar))
{
titlebar.Measure(referenceSize);
Assert.That(titlebar.DesiredSize, Is.EqualTo(new Size(2, DefaultTitleBarHeight)));
}
}
[Test]
[TestCaseSource(nameof(With_Header_TestData))]
public void With_Header(RibbonTitleBarSizeData testdata)
{
var titlebar = CreateNewTitlebar();
using (new TestRibbonWindow(titlebar))
{
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
Assert.That(resultData, Is.EqualTo(testdata));
}
}
private static IEnumerable<RibbonTitleBarSizeData> With_Header_TestData()
{
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(89, DefaultTitleBarHeight), zeroSize, new Size(89, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(100, new Size(89, DefaultTitleBarHeight), zeroSize, new Size(89, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), zeroSize, new Size(54, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
}
[Test]
[TestCaseSource(nameof(With_Parts_And_Wide_Header_TestData))]
public void With_Wide_Header(RibbonTitleBarSizeData testdata)
{
var titlebar = CreateNewTitlebar();
titlebar.Header = "This is a really wide header which needs some more space";
using (new TestRibbonWindow(titlebar))
{
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
Assert.That(resultData, Is.EqualTo(testdata));
}
}
private static IEnumerable<RibbonTitleBarSizeData> With_Parts_And_Wide_Header_TestData()
{
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(309, DefaultTitleBarHeight), zeroSize, new Size(309, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(100, new Size(100, DefaultTitleBarHeight), zeroSize, new Size(102, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), zeroSize, new Size(54, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
}
[Test]
[TestCaseSource(nameof(With_Header_And_QuickAccessItems_TestData))]
public void With_Header_And_QuickAccessItems(RibbonTitleBarSizeData testdata)
{
var titlebar = CreateNewTitlebar();
var quickAccessToolBar = (QuickAccessToolBar)(titlebar.QuickAccessToolBar = new QuickAccessToolBar());
using (new TestRibbonWindow(titlebar))
{
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
Assert.That(resultData, Is.EqualTo(testdata));
}
}
private static IEnumerable<RibbonTitleBarSizeData> With_Header_And_QuickAccessItems_TestData()
{
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(169, DefaultTitleBarHeight), new Size(80, DefaultTitleBarHeight - 1), new Size(89, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(100, new Size(100, DefaultTitleBarHeight), new Size(36, DefaultTitleBarHeight - 1), new Size(66, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), new Size(2, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), new Size(0, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), new Size(0, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
}
public struct RibbonTitleBarSizeData
{
public RibbonTitleBarSizeData(double constraintWidth, Size desiredSize, Size quickAccessRectSize, Size headerRectSize, Size itemsRectSize)
{
this.ConstraintWidth = constraintWidth;
this.DesiredSize = desiredSize;
this.QuickAccessRectSize = quickAccessRectSize;
this.HeaderRectSize = headerRectSize;
this.ItemsRectSize = itemsRectSize;
}
public RibbonTitleBarSizeData(double constraintWidth, RibbonTitleBar ribbonTitleBar)
: this(
constraintWidth,
ribbonTitleBar.DesiredSize,
ribbonTitleBar.GetFieldValue<Rect>(QuickaccessToolbarRect).Size,
ribbonTitleBar.GetFieldValue<Rect>(HeaderRect).Size,
ribbonTitleBar.GetFieldValue<Rect>(ItemsRect).Size)
{
}
public double ConstraintWidth { get; }
public Size DesiredSize { get; }
public Size QuickAccessRectSize { get; }
public Size HeaderRectSize { get; }
public Size ItemsRectSize { get; }
public override string ToString()
{
return $"[{this.ConstraintWidth}=>{this.DesiredSize}]#{this.QuickAccessRectSize}#{this.HeaderRectSize}#{this.ItemsRectSize}";
}
}
private static RibbonTitleBar CreateNewTitlebar()
{
return new RibbonTitleBar
{
Header = "This is just a test",
UseLayoutRounding = true,
SnapsToDevicePixels = true
};
}
}
}
}

View File

@@ -0,0 +1,141 @@
namespace Fluent.Tests.Controls
{
using System.Linq;
using Fluent.Tests.TestClasses;
using FluentTest.Commanding;
using NUnit.Framework;
[TestFixture]
public class SplitButtonTests
{
[Test]
public void Command_Should_Not_Disable_Control()
{
var splitButton = new SplitButton
{
Command = new RelayCommand(null, () => false)
};
using (new TestRibbonWindow(splitButton))
{
splitButton.ApplyTemplate();
Assert.That(splitButton.IsEnabled, Is.True);
var partButton = splitButton.Template.FindName("PART_Button", splitButton) as ToggleButton;
Assert.That(partButton, Is.Not.Null);
Assert.That(partButton.IsEnabled, Is.False);
splitButton.Command = new RelayCommand(null, () => true);
Assert.That(splitButton.IsEnabled, Is.True);
Assert.That(partButton.IsEnabled, Is.True);
}
}
[Test]
public void Disabling_Control_Should_Disable_Popup()
{
var splitButton = new SplitButton
{
Command = new RelayCommand(null, () => false)
};
using (new TestRibbonWindow(splitButton))
{
splitButton.ApplyTemplate();
Assert.That(splitButton.IsEnabled, Is.True);
var dummyButton = new Button();
splitButton.Items.Add(dummyButton);
Assert.That(dummyButton.IsEnabled, Is.True);
splitButton.IsDropDownOpen = true;
splitButton.IsEnabled = false;
Assert.That(splitButton.IsEnabled, Is.False);
Assert.That(dummyButton.IsEnabled, Is.False);
splitButton.IsDropDownOpen = false;
Assert.That(splitButton.IsEnabled, Is.False);
Assert.That(dummyButton.IsEnabled, Is.False);
}
}
[Test]
public void KeyTips_Should_Have_Postfix()
{
{
var splitButton = new SplitButton
{
KeyTip = "Z"
};
using (new TestRibbonWindow(splitButton))
{
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("ZA"));
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("ZB"));
}
}
{
var splitButton = new SplitButton
{
KeyTip = "Z",
PrimaryActionKeyTipPostfix = "X",
SecondaryActionKeyTipPostfix = "Y"
};
using (new TestRibbonWindow(splitButton))
{
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("ZX"));
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("ZY"));
}
}
}
[Test]
public void KeyTips_Should_Work_With_Secondary_KeyTip()
{
{
var splitButton = new SplitButton
{
SecondaryKeyTip = "Z"
};
using (new TestRibbonWindow(splitButton))
{
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
Assert.That(keyTipInformations, Has.Count.EqualTo(1));
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("Z"));
}
}
{
var splitButton = new SplitButton
{
KeyTip = "X",
SecondaryKeyTip = "Z"
};
using (new TestRibbonWindow(splitButton))
{
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("X"));
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("Z"));
}
}
}
}
}

View File

@@ -0,0 +1,45 @@
namespace Fluent.Tests.Converters
{
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using Fluent.Converters;
using NUnit.Framework;
[TestFixture]
public class ObjectToImageConverterTests
{
[Test]
public void TestDynamicResource()
{
var fluentRibbonImagesApplicationmenuResourceKey = (object)"Fluent.Ribbon.Images.ApplicationMenu";
var expressionType = typeof(ResourceReferenceExpressionConverter).Assembly.GetType("System.Windows.ResourceReferenceExpression");
var expression = Activator.CreateInstance(expressionType, fluentRibbonImagesApplicationmenuResourceKey);
var convertedValue = StaticConverters.ObjectToImageConverter.Convert(new object[]
{
expression, // value to convert
new ApplicationMenu() // target visual
}, null, null, null);
Assert.That(convertedValue, Is.Not.Null);
Assert.That(convertedValue, Is.InstanceOf<Image>());
var convertedImageValue = (Image)convertedValue;
Assert.That(convertedImageValue.Source, Is.InstanceOf<DrawingImage>());
var drawingImage = (DrawingImage)convertedImageValue.Source;
Assert.That(drawingImage.Drawing, Is.InstanceOf<DrawingGroup>());
var drawingGroup = (DrawingGroup)drawingImage.Drawing;
Assert.That(drawingGroup.Children.Cast<GeometryDrawing>().Select(x => x.Geometry.ToString()),
Is.EquivalentTo(((DrawingGroup)((DrawingImage)Application.Current.FindResource(fluentRibbonImagesApplicationmenuResourceKey)).Drawing).Children.Cast<GeometryDrawing>().Select(x => x.Geometry.ToString())));
}
}
}

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462;net472</TargetFrameworks>
<RootNamespace>Fluent.Tests</RootNamespace>
<AssemblyName>Fluent.Tests</AssemblyName>
<IsTestProject>true</IsTestProject>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>$(NoWarn);SA0001</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Fluent.Ribbon.Showcase\Commanding\IRelayCommand.cs">
<Link>Commanding\IRelayCommand.cs</Link>
</Compile>
<Compile Include="..\Fluent.Ribbon.Showcase\Commanding\RelayCommand.cs">
<Link>Commanding\RelayCommand.cs</Link>
</Compile>
<Compile Include="..\Fluent.Ribbon.Showcase\Helpers\ThemeHelper.cs" Link="Helper\ThemeHelper.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="WpfAnalyzers" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fluent.Ribbon\Fluent.Ribbon.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1652:Enable XML documentation output", Justification = "No xml documentation is needed for test projects.")]

View File

@@ -0,0 +1,18 @@
namespace Fluent.Tests.Helper
{
using System;
using System.Reflection;
public static class ReflectionHelper
{
public static T GetFieldValue<T>(this object obj, string fieldName)
{
return (T)GetPrivateFieldInfo(obj.GetType(), fieldName).GetValue(obj);
}
private static FieldInfo GetPrivateFieldInfo(Type type, string fieldName)
{
return type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
}
}
}

View File

@@ -0,0 +1,18 @@
namespace Fluent.Tests.Helper
{
using System;
using System.Windows.Threading;
public static class UIHelper
{
public static void DoEvents()
{
Dispatcher.CurrentDispatcher.DoEvents();
}
public static void DoEvents(this Dispatcher dispatcher)
{
dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { }));
}
}
}

View File

@@ -0,0 +1,342 @@
namespace Fluent.Tests.Integration
{
using System.Windows.Media;
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class InRibbonGalleryIntegrationTests
{
[Test]
public void Opening_And_Closing_DropDown_Should_Not_Change_Size_For_Fixed_Item_Width()
{
var ribbonGroupsContainer = new RibbonGroupsContainer
{
Height = RibbonTabControl.DefaultContentHeight,
ReduceOrder = "(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup)"
};
var groupBox = new RibbonGroupBox
{
Name = "MyGroup",
BorderBrush = Brushes.Red
};
ribbonGroupsContainer.Children.Add(groupBox);
var firstInRibbonGallery = new InRibbonGallery
{
MinItemsInRow = 1,
MaxItemsInRow = 5,
ItemWidth = 50,
ItemHeight = 18,
GroupBy = "Group",
ResizeMode = ContextMenuResizeMode.Both,
ItemsSource = this.sampleDataItemsForFixedWidth
};
groupBox.Items.Add(firstInRibbonGallery);
var secondInRibbonGallery = new InRibbonGallery
{
MinItemsInRow = 1,
MaxItemsInRow = 5,
ItemWidth = 50,
ItemHeight = 18,
GroupBy = "Group",
ResizeMode = ContextMenuResizeMode.Both,
ItemsSource = this.sampleDataItemsForFixedWidth
};
groupBox.Items.Add(secondInRibbonGallery);
using (new TestRibbonWindow(ribbonGroupsContainer))
{
UIHelper.DoEvents();
ribbonGroupsContainer.Width = 520;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
for (var i = 0; i < 5; i++)
{
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
// open and close first
{
firstInRibbonGallery.IsDropDownOpen = true;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
firstInRibbonGallery.IsDropDownOpen = false;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
}
// open and close second
{
secondInRibbonGallery.IsDropDownOpen = true;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
secondInRibbonGallery.IsDropDownOpen = false;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
}
++ribbonGroupsContainer.Width;
}
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(219));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(456));
ribbonGroupsContainer.Width = 560;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(269));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(269));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5));
Assert.That(groupBox.ActualWidth, Is.EqualTo(556));
}
}
[Test]
public void Opening_And_Closing_DropDown_Should_Not_Change_Size_For_Dynamic_Item_Width()
{
var ribbonGroupsContainer = new RibbonGroupsContainer
{
Height = RibbonTabControl.DefaultContentHeight,
ReduceOrder = "(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup)"
};
var groupBox = new RibbonGroupBox
{
Name = "MyGroup",
BorderBrush = Brushes.Red
};
ribbonGroupsContainer.Children.Add(groupBox);
var firstInRibbonGallery = new InRibbonGallery
{
MinItemsInRow = 1,
MaxItemsInRow = 5,
ItemHeight = 18,
GroupBy = "Group",
ResizeMode = ContextMenuResizeMode.Both,
ItemsSource = this.sampleDataItemsForDynamicWidth
};
groupBox.Items.Add(firstInRibbonGallery);
var secondInRibbonGallery = new InRibbonGallery
{
MinItemsInRow = 1,
MaxItemsInRow = 5,
ItemHeight = 18,
GroupBy = "Group",
ResizeMode = ContextMenuResizeMode.Both,
ItemsSource = this.sampleDataItemsForDynamicWidth
};
groupBox.Items.Add(secondInRibbonGallery);
using (new TestRibbonWindow(ribbonGroupsContainer))
{
UIHelper.DoEvents();
ribbonGroupsContainer.Width = 620;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
for (var i = 0; i < 5; i++)
{
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
// open and close first
{
firstInRibbonGallery.IsDropDownOpen = true;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
firstInRibbonGallery.IsDropDownOpen = false;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
}
// open and close second
{
secondInRibbonGallery.IsDropDownOpen = true;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
secondInRibbonGallery.IsDropDownOpen = false;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
}
++ribbonGroupsContainer.Width;
}
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3));
Assert.That(groupBox.ActualWidth, Is.EqualTo(512));
ribbonGroupsContainer.Width = 670;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(323));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(323));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4));
Assert.That(groupBox.ActualWidth, Is.EqualTo(664));
ribbonGroupsContainer.Width = 900;
UIHelper.DoEvents();
Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(399));
Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(399));
Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5));
Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5));
Assert.That(groupBox.ActualWidth, Is.EqualTo(816));
}
}
private readonly SampleDataItem[] sampleDataItemsForFixedWidth =
{
new SampleDataItem("A", "Blue"),
new SampleDataItem("A", "Brown"),
new SampleDataItem("A", "Gray"),
new SampleDataItem("A", "Green"),
new SampleDataItem("A", "Orange"),
new SampleDataItem("B", "Pink"),
new SampleDataItem("B", "Red"),
new SampleDataItem("B", "Yellow")
};
private readonly SampleDataItem[] sampleDataItemsForDynamicWidth =
{
new SampleDataItem("A", "Blue"),
new SampleDataItem("A", "Brown"),
new SampleDataItem("A", "Hallo text text"),
new SampleDataItem("A", "Green"),
new SampleDataItem("A", "Orange"),
new SampleDataItem("B", "Pink"),
new SampleDataItem("B", "Red"),
new SampleDataItem("B", "Yellow")
};
private class SampleDataItem
{
public SampleDataItem(string group, string text)
{
this.Group = group;
this.Text = text;
}
public string Group { get; }
public string Text { get; }
/// <inheritdoc />
public override string ToString()
{
return this.Text;
}
}
}
}

View File

@@ -0,0 +1,54 @@
namespace Fluent.Tests.Internal
{
using Fluent.Internal;
using NUnit.Framework;
[TestFixture]
public class ScopeGuardTests
{
[Test]
public void IsActive_Marker_Should_Change_On_Dispose()
{
var guard = new ScopeGuard();
Assert.That(guard.IsActive, Is.False);
guard.Start();
Assert.That(guard.IsActive, Is.True);
guard.Dispose();
Assert.That(guard.IsActive, Is.False);
Assert.That(() => guard.Dispose(), Throws.Nothing);
Assert.That(guard.IsActive, Is.False);
}
[Test]
public void Actions_Should_Be_Called()
{
var entryActionCallCount = 0;
void EntryAction() => ++entryActionCallCount;
var disposeActionCallCount = 0;
void DisposeAction() => ++disposeActionCallCount;
var guard = new ScopeGuard(EntryAction, DisposeAction).Start();
Assert.That(entryActionCallCount, Is.EqualTo(1));
Assert.That(disposeActionCallCount, Is.EqualTo(0));
guard.Dispose();
Assert.That(entryActionCallCount, Is.EqualTo(1));
Assert.That(disposeActionCallCount, Is.EqualTo(1));
guard.Dispose();
Assert.That(entryActionCallCount, Is.EqualTo(1));
Assert.That(disposeActionCallCount, Is.EqualTo(1));
}
}
}

View File

@@ -0,0 +1,55 @@
namespace Fluent.Tests.Internal
{
using System.Windows.Controls;
using Fluent.Internal;
using Fluent.Tests.TestClasses;
using NUnit.Framework;
[TestFixture]
public class WhenLoadedTests
{
[Test]
public void Action_Should_Be_Called_When_Already_Loaded()
{
var control = new Control();
var loadedActionCallCount = 0;
using (new TestRibbonWindow(control))
{
control.WhenLoaded(x => ++loadedActionCallCount);
Assert.That(loadedActionCallCount, Is.EqualTo(1));
}
// Check that only one loaded event triggers the action
using (new TestRibbonWindow(control))
{
Assert.That(loadedActionCallCount, Is.EqualTo(1));
}
}
[Test]
public void Action_Should_Be_Called_When_Loaded_Later()
{
var control = new Control();
var loadedActionCallCount = 0;
control.WhenLoaded(x => ++loadedActionCallCount);
Assert.That(loadedActionCallCount, Is.EqualTo(0));
using (new TestRibbonWindow(control))
{
Assert.That(loadedActionCallCount, Is.EqualTo(1));
}
// Check that only one loaded event triggers the action
using (new TestRibbonWindow(control))
{
Assert.That(loadedActionCallCount, Is.EqualTo(1));
}
}
}
}

View File

@@ -0,0 +1,274 @@
namespace Fluent.Tests.Misc
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using Fluent.Helpers;
using NUnit.Framework;
using Ribbon = Fluent.Ribbon;
using RibbonControl = Fluent.RibbonControl;
[TestFixture]
public class LogicalTreeTests
{
[Test]
[TestCaseSource(nameof(GetTypesWithImplementedInterface), new object[]
{
typeof(IRibbonControl)
})]
public void LogicalTreeShouldWorkForIcon(Type controlType)
{
if (typeof(MenuItem).IsAssignableFrom(controlType))
{
TestLogicalTree(controlType, MenuItem.IconProperty);
}
else
{
TestLogicalTree(controlType, RibbonControl.IconProperty);
}
}
[Test]
[TestCaseSource(nameof(GetTypesWithImplementedInterface), new object[]
{
typeof(ILargeIconProvider)
})]
public void LogicalTreeShouldWorkForLargeIcon(Type controlType)
{
TestLogicalTree(controlType, LargeIconProviderProperties.LargeIconProperty);
}
[Test]
[TestCaseSource(nameof(GetTypesWithImplementedInterface), new object[]
{
typeof(IHeaderedControl)
})]
public void LogicalTreeShouldWorkForHeader(Type controlType)
{
if (typeof(HeaderedItemsControl).IsAssignableFrom(controlType))
{
TestLogicalTree(controlType, HeaderedItemsControl.HeaderProperty);
}
else
{
TestLogicalTree(controlType, RibbonControl.HeaderProperty);
}
}
[Test]
[TestCaseSource(nameof(GetTypesThatMustHaveLogicalChildSupport))]
public void CheckLogicalChildSupport(KeyValuePair<Type, DependencyProperty> item)
{
var controlType = item.Key;
var dependencyProperty = item.Value;
var control = (DependencyObject)Activator.CreateInstance(controlType, true);
Assert.That(control, Is.Not.Null);
if (excludedTypesForLogicalChildSupportTest.Contains(controlType))
{
Assert.That(control is ILogicalChildSupport, Is.False, "Type must NOT implement ILogicalChildSupport");
return;
}
else
{
Assert.That(control is ILogicalChildSupport, Is.True, "Type must implement ILogicalChildSupport");
}
var metadata = dependencyProperty.GetMetadata(control);
if (excludedPropertiesForLogicalChildSupportTest.Contains(dependencyProperty))
{
Assert.That(metadata.PropertyChangedCallback != LogicalChildSupportHelper.OnLogicalChildPropertyChanged, "PropertyChangedCallback must not be LogicalChildSupportHelper.OnLogicalChildPropertyChanged");
}
else
{
Assert.That(metadata.PropertyChangedCallback == LogicalChildSupportHelper.OnLogicalChildPropertyChanged, "PropertyChangedCallback must be LogicalChildSupportHelper.OnLogicalChildPropertyChanged");
}
if (dependencyProperty.ReadOnly)
{
var dependencyPropertykeyFieldName = dependencyProperty.Name + "PropertyKey";
var dependencyPropertyKeyField = controlType.GetField(dependencyPropertykeyFieldName, BindingFlags.Static | BindingFlags.NonPublic);
Assert.That(dependencyPropertyKeyField, Is.Not.Null, $"Field \"{dependencyPropertykeyFieldName}\" must exist.");
var dependencyPropertyKey = (DependencyPropertyKey)dependencyPropertyKeyField.GetValue(null);
TestLogicalTree(controlType, dependencyProperty, dependencyPropertyKey);
}
else
{
TestLogicalTree(controlType, dependencyProperty);
}
}
private static IEnumerable<Type> GetTypesWithImplementedInterface(Type type)
{
return typeof(Ribbon).Assembly.GetTypes()
.Where(x => type.IsAssignableFrom(x) && x.IsAbstract == false);
}
private static readonly Type[] excludedTypesForLogicalChildSupportTest =
{
typeof(LargeIconProviderProperties),
typeof(GalleryItem)
};
private static readonly DependencyProperty[] excludedPropertiesForLogicalChildSupportTest =
{
GalleryItem.CommandParameterProperty,
RibbonGroupBox.LauncherCommandParameterProperty,
RibbonGroupBox.LauncherToolTipProperty,
SplitButton.CommandParameterProperty,
SplitButton.DropDownToolTipProperty
};
private static IEnumerable<KeyValuePair<Type, DependencyProperty>> GetTypesThatMustHaveLogicalChildSupport()
{
foreach (var keyValuePair in GetDependencyPropertiesWithPropertyTypeObject())
{
yield return keyValuePair;
}
}
private static IEnumerable<KeyValuePair<Type, DependencyProperty>> GetDependencyPropertiesWithPropertyTypeObject()
{
var types = typeof(Ribbon).Assembly.GetTypes()
.Where(x => typeof(DependencyObject).IsAssignableFrom(x) && x.IsAbstract == false);
foreach (var type in types)
{
var properties = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
.Where(x => typeof(DependencyProperty).IsAssignableFrom(x.FieldType))
.Select(x => x.GetValue(null))
.Cast<DependencyProperty>();
foreach (var dependencyProperty in properties)
{
if (dependencyProperty.PropertyType == typeof(object))
{
yield return new KeyValuePair<Type, DependencyProperty>(type, dependencyProperty);
}
}
}
}
private static void TestLogicalTree(Type controlType, DependencyProperty property, DependencyPropertyKey propertyKey = null)
{
var control = (DependencyObject)Activator.CreateInstance(controlType, true);
Assert.That(control, Is.Not.Null);
{
var value = new object();
SetValue(value);
{
var children = LogicalTreeHelper.GetChildren(control);
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}
SetValue(null);
{
var children = LogicalTreeHelper.GetChildren(control);
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
}
{
var value = new DependencyObject();
SetValue(value);
{
var children = LogicalTreeHelper.GetChildren(control);
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}
{
var parent = LogicalTreeHelper.GetParent(value);
Assert.That(parent, Is.Null, "Dependency-Objects don't support logical parents.");
}
SetValue(null);
{
var children = LogicalTreeHelper.GetChildren(control);
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
}
{
var value = new FrameworkElement();
SetValue(value);
{
var children = LogicalTreeHelper.GetChildren(control);
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}
{
var parent = LogicalTreeHelper.GetParent(value);
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(parent, Is.Not.EqualTo(control), "Parent should match.");
}
else
{
Assert.That(parent, Is.EqualTo(control), "Parent should match.");
}
}
SetValue(null);
{
var children = LogicalTreeHelper.GetChildren(control);
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
}
void SetValue(object value)
{
if (propertyKey is null)
{
control.SetValue(property, value);
}
else
{
control.SetValue(propertyKey, value);
}
}
}
}
}

View File

@@ -0,0 +1,5 @@
using System;
[assembly: CLSCompliant(false)]
[assembly: NUnit.Framework.Apartment(System.Threading.ApartmentState.STA)]

View File

@@ -0,0 +1,25 @@
namespace Fluent.Tests.Services
{
using System.Linq;
using NUnit.Framework;
[TestFixture]
public class KeyTipServiceTests
{
[Test]
public void TestDefaultKeyTipKeys()
{
var ribbon = new Ribbon();
var keytipService = new KeyTipService(ribbon);
Assert.That(ribbon.KeyTipKeys, Is.Empty);
Assert.That(keytipService.KeyTipKeys, Is.EquivalentTo(KeyTipService.DefaultKeyTipKeys));
var defaultKeys = KeyTipService.DefaultKeyTipKeys.ToList();
keytipService.KeyTipKeys.RemoveAt(0);
Assert.That(KeyTipService.DefaultKeyTipKeys, Is.EquivalentTo(defaultKeys));
}
}
}

View File

@@ -0,0 +1,40 @@
namespace Fluent.Tests.TestClasses
{
using System;
using System.Diagnostics;
public sealed class TestRibbonWindow : RibbonWindow, IDisposable
{
public TestRibbonWindow()
: this(null)
{
}
public TestRibbonWindow(object content)
{
this.Width = 800;
this.Height = 600;
this.ShowActivated = false;
this.ShowInTaskbar = false;
if (Debugger.IsAttached == false)
{
this.Left = int.MinValue;
this.Top = int.MinValue;
}
// As Ribbon uses layout rounding we should use it here too
FrameworkHelper.SetUseLayoutRounding(this, true);
this.Content = content;
this.Show();
}
public void Dispose()
{
this.Close();
}
}
}

View File

@@ -0,0 +1,437 @@
// namespace Fluent.Tests.ThemeManager
// {
// using System;
// using System.Linq;
// using System.Windows;
// using System.Windows.Controls;
// using System.Windows.Data;
// using System.Windows.Media;
// using Fluent;
// using Fluent.Tests.TestClasses;
// using FluentTest.Helpers;
// using NUnit.Framework;
// [TestFixture]
// public class ThemeManagerTest
// {
// [SetUp]
// public void SetUp()
// {
// ThemeManager.ClearThemes();
// }
// [TearDown]
// public void TearDown()
// {
// ThemeManager.ClearThemes();
// }
// [Test]
// public void ChangeThemeForAppShouldThrowArgumentNullException()
// {
// Assert.Throws<ArgumentNullException>(() => ThemeManager.ChangeTheme((Application)null, ThemeManager.GetTheme("Light.Red")));
// Assert.Throws<ArgumentNullException>(() => ThemeManager.ChangeTheme(Application.Current, ThemeManager.GetTheme("UnknownTheme")));
// }
// [Test]
// public void ChangeThemeForWindowShouldThrowArgumentNullException()
// {
// using (var window = new TestRibbonWindow())
// {
// Assert.Throws<ArgumentNullException>(() => ThemeManager.ChangeTheme((Window)null, ThemeManager.GetTheme("Light.Red")));
// Assert.Throws<ArgumentNullException>(() => ThemeManager.ChangeTheme(Application.Current.MainWindow, ThemeManager.GetTheme("UnknownTheme")));
// }
// }
// [Test]
// public void CanAddThemeBeforeGetterIsCalled()
// {
// Assert.False(ThemeManager.AddTheme(new Uri("pack://application:,,,/Fluent;component/Themes/Themes/Dark.Cobalt.xaml")));
// var resource = new ResourceDictionary
// {
// {
// Theme.ThemeNameKey, "Runtime"
// },
// {
// Theme.ThemeDisplayNameKey, "Runtime"
// }
// };
// Assert.True(ThemeManager.AddTheme(resource));
// }
// [Test]
// public void NewThemeAddsNewBaseColorAndColorScheme()
// {
// var resource = new ResourceDictionary
// {
// {
// Theme.ThemeNameKey, "Runtime"
// },
// {
// Theme.ThemeDisplayNameKey, "Runtime"
// },
// {
// Theme.ThemeBaseColorSchemeKey, "Foo"
// },
// {
// Theme.ThemeColorSchemeKey, "Bar"
// },
// };
// Assert.True(ThemeManager.AddTheme(resource));
// Assert.That(ThemeManager.BaseColors, Is.EqualTo(new[] { ThemeManager.BaseColorLight, ThemeManager.BaseColorDark, "Colorful", "Foo" }));
// Assert.That(ThemeManager.ColorSchemes.Select(x => x.Name), Does.Contain("Bar"));
// }
// [Test]
// public void ChangingAppThemeChangesWindowTheme()
// {
// using (var window = new TestRibbonWindow())
// {
// var expectedTheme = ThemeManager.GetTheme("Dark.Teal");
// ThemeManager.ChangeTheme(Application.Current, expectedTheme);
// Assert.That(ThemeManager.DetectTheme(Application.Current), Is.EqualTo(expectedTheme));
// Assert.That(ThemeManager.DetectTheme(window), Is.EqualTo(expectedTheme));
// }
// }
// [Test]
// public void ChangeBaseColor()
// {
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeThemeBaseColor(Application.Current, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme);
// Assert.That(ThemeManager.DetectTheme(Application.Current).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo(currentTheme.ColorScheme));
// }
// {
// using (var window = new TestRibbonWindow())
// {
// var currentTheme = ThemeManager.DetectTheme(window);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeThemeBaseColor(window, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme);
// Assert.That(ThemeManager.DetectTheme(window).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(window).ColorScheme, Is.EqualTo(currentTheme.ColorScheme));
// }
// }
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// var control = new Control();
// ThemeManager.ChangeThemeBaseColor(control.Resources, currentTheme, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme);
// Assert.That(ThemeManager.DetectTheme(control.Resources).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(control.Resources).ColorScheme, Is.EqualTo(currentTheme.ColorScheme));
// }
// }
// [Test]
// public void ChangeColorScheme()
// {
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeThemeColorScheme(Application.Current, "Yellow");
// Assert.That(ThemeManager.DetectTheme(Application.Current).BaseColorScheme, Is.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo("Yellow"));
// }
// {
// using (var window = new TestRibbonWindow())
// {
// var currentTheme = ThemeManager.DetectTheme(window);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeThemeColorScheme(window, "Green");
// Assert.That(ThemeManager.DetectTheme(window).BaseColorScheme, Is.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(window).ColorScheme, Is.EqualTo("Green"));
// }
// }
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// var control = new Control();
// ThemeManager.ChangeThemeColorScheme(control.Resources, currentTheme, "Red");
// Assert.That(ThemeManager.DetectTheme(control.Resources).BaseColorScheme, Is.EqualTo(currentTheme.BaseColorScheme));
// Assert.That(ThemeManager.DetectTheme(control.Resources).ColorScheme, Is.EqualTo("Red"));
// }
// Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo("Yellow"));
// }
// [Test]
// public void ChangeBaseColorAndColorScheme()
// {
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeTheme(Application.Current, ThemeManager.BaseColorDark, "Yellow");
// Assert.That(ThemeManager.DetectTheme(Application.Current).BaseColorScheme, Is.EqualTo(ThemeManager.BaseColorDark));
// Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo("Yellow"));
// }
// {
// using (var window = new TestRibbonWindow())
// {
// var currentTheme = ThemeManager.DetectTheme(window);
// Assert.That(currentTheme, Is.Not.Null);
// ThemeManager.ChangeTheme(window, ThemeManager.BaseColorLight, "Green");
// Assert.That(ThemeManager.DetectTheme(window).BaseColorScheme, Is.EqualTo(ThemeManager.BaseColorLight));
// Assert.That(ThemeManager.DetectTheme(window).ColorScheme, Is.EqualTo("Green"));
// }
// }
// {
// var currentTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(currentTheme, Is.Not.Null);
// var control = new Control();
// ThemeManager.ChangeTheme(control.Resources, currentTheme, ThemeManager.BaseColorDark, "Red");
// Assert.That(ThemeManager.DetectTheme(control.Resources).BaseColorScheme, Is.EqualTo(ThemeManager.BaseColorDark));
// Assert.That(ThemeManager.DetectTheme(control.Resources).ColorScheme, Is.EqualTo("Red"));
// }
// Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo("Yellow"));
// }
// [Test]
// public void GetInverseThemeReturnsDarkTheme()
// {
// var theme = ThemeManager.GetInverseTheme(ThemeManager.GetTheme("Light.Blue"));
// Assert.That(theme.Name, Is.EqualTo("Dark.Blue"));
// }
// [Test]
// public void GetInverseThemeReturnsLightTheme()
// {
// var theme = ThemeManager.GetInverseTheme(ThemeManager.GetTheme("Dark.Blue"));
// Assert.That(theme.Name, Is.EqualTo("Light.Blue"));
// }
// [Test]
// public void GetInverseThemeReturnsNullForMissingTheme()
// {
// var resource = new ResourceDictionary
// {
// {
// "Theme.Name", "Runtime"
// },
// {
// "Theme.DisplayName", "Runtime"
// }
// };
// var theme = new Theme(resource);
// var inverseTheme = ThemeManager.GetInverseTheme(theme);
// Assert.Null(inverseTheme);
// }
// [Test]
// public void GetThemeIsCaseInsensitive()
// {
// var theme = ThemeManager.GetTheme("Dark.Blue");
// Assert.NotNull(theme);
// Assert.That(theme.Resources.Source.ToString(), Is.EqualTo("pack://application:,,,/Fluent;component/Themes/Themes/Dark.Blue.xaml").IgnoreCase);
// }
// [Test]
// public void GetThemeWithUriIsCaseInsensitive()
// {
// var dic = new ResourceDictionary
// {
// Source = new Uri("pack://application:,,,/Fluent;component/Themes/Themes/daRK.Blue.xaml")
// };
// var theme = ThemeManager.GetTheme(dic);
// Assert.NotNull(theme);
// Assert.That(theme.Name, Is.EqualTo("Dark.Blue"));
// }
// [Test]
// public void GetThemes()
// {
// var expectedThemes = new[]
// {
// "Amber (Dark)",
// "Amber (Light)",
// "Blue (Colorful)",
// "Blue (Dark)",
// "Blue (Light)",
// "Brown (Dark)",
// "Brown (Light)",
// "Cobalt (Dark)",
// "Cobalt (Light)",
// "Crimson (Dark)",
// "Crimson (Light)",
// "Cyan (Dark)",
// "Cyan (Light)",
// "Emerald (Dark)",
// "Emerald (Light)",
// "Gray (Colorful)",
// "Green (Dark)",
// "Green (Light)",
// "Indigo (Dark)",
// "Indigo (Light)",
// "Lime (Dark)",
// "Lime (Light)",
// "Magenta (Dark)",
// "Magenta (Light)",
// "Mauve (Dark)",
// "Mauve (Light)",
// "Olive (Dark)",
// "Olive (Light)",
// "Orange (Dark)",
// "Orange (Light)",
// "Pink (Dark)",
// "Pink (Light)",
// "Purple (Dark)",
// "Purple (Light)",
// "Red (Dark)",
// "Red (Light)",
// "Sienna (Dark)",
// "Sienna (Light)",
// "Steel (Dark)",
// "Steel (Light)",
// "Taupe (Dark)",
// "Taupe (Light)",
// "Teal (Dark)",
// "Teal (Light)",
// "Violet (Dark)",
// "Violet (Light)",
// "Yellow (Dark)",
// "Yellow (Light)"
// };
// Assert.That(CollectionViewSource.GetDefaultView(ThemeManager.Themes).Cast<Theme>().Select(x => x.DisplayName).ToList(), Is.EqualTo(expectedThemes));
// }
// [Test]
// public void GetBaseColors()
// {
// ThemeManager.ClearThemes();
// Assert.That(ThemeManager.BaseColors, Is.Not.Empty);
// }
// [Test]
// public void GetColorSchemes()
// {
// ThemeManager.ClearThemes();
// Assert.That(ThemeManager.ColorSchemes, Is.Not.Empty);
// }
// [Test]
// public void CreateDynamicThemeWithColor()
// {
// var applicationTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(() => ThemeHelper.CreateTheme("Light", Colors.Red, Colors.Red, "CustomAccentRed", changeImmediately: true), Throws.Nothing);
// var detected = ThemeManager.DetectTheme(Application.Current);
// Assert.NotNull(detected);
// Assert.That(detected.Name, Is.EqualTo("CustomAccentRed"));
// Assert.That(() => ThemeHelper.CreateTheme("Dark", Colors.Green, Colors.Green, "CustomAccentGreen", changeImmediately: true), Throws.Nothing);
// detected = ThemeManager.DetectTheme(Application.Current);
// Assert.NotNull(detected);
// Assert.That(detected.Name, Is.EqualTo("CustomAccentGreen"));
// ThemeManager.ChangeTheme(Application.Current, applicationTheme);
// }
// [Test]
// public void CreateDynamicAccentWithColorAndChangeBaseColorScheme()
// {
// var applicationTheme = ThemeManager.DetectTheme(Application.Current);
// Assert.That(() => ThemeHelper.CreateTheme("Dark", Colors.Red, Colors.Orange), Throws.Nothing);
// Assert.That(() => ThemeHelper.CreateTheme("Light", Colors.Red, Colors.Orange, changeImmediately: true), Throws.Nothing);
// var detected = ThemeManager.DetectTheme(Application.Current);
// Assert.NotNull(detected);
// Assert.That(detected.ColorScheme, Is.EqualTo(Colors.Red.ToString().Replace("#", string.Empty)));
// var newTheme = ThemeManager.ChangeThemeBaseColor(Application.Current, "Dark");
// Assert.NotNull(newTheme);
// newTheme = ThemeManager.ChangeThemeBaseColor(Application.Current, "Light");
// Assert.NotNull(newTheme);
// ThemeManager.ChangeTheme(Application.Current, applicationTheme);
// }
// [Test]
// [TestCase("pack://application:,,,/Fluent;component/Themes/themes/dark.blue.xaml", "Dark", "#FF2B579A", "#FF086F9E")]
// [TestCase("pack://application:,,,/Fluent;component/Themes/themes/dark.green.xaml", "Dark", "#FF60A917", "#FF477D11")]
// [TestCase("pack://application:,,,/Fluent;component/Themes/themes/Light.blue.xaml", "Light", "#FF2B579A", "#FF086F9E")]
// [TestCase("pack://application:,,,/Fluent;component/Themes/themes/Light.green.xaml", "Light", "#FF60A917", "#FF477D11")]
// public void CompareGeneratedAppStyleWithShipped(string source, string baseColor, string color, string highlightColor)
// {
// var dic = new ResourceDictionary
// {
// Source = new Uri(source)
// };
// var newTheme = ThemeHelper.CreateTheme(baseColor, (Color)ColorConverter.ConvertFromString(color), (Color)ColorConverter.ConvertFromString(highlightColor));
// var ignoredKeyValues = new[]
// {
// "Theme.Name",
// "Theme.DisplayName",
// "Theme.ColorScheme",
// "Fluent.Ribbon.Colors.HighlightColor", // Ignored because it's hand crafted
// "Fluent.Ribbon.Brushes.HighlightBrush", // Ignored because it's hand crafted
// };
// CompareResourceDictionaries(dic, newTheme.Item2, ignoredKeyValues);
// CompareResourceDictionaries(newTheme.Item2, dic, ignoredKeyValues);
// }
// private static void CompareResourceDictionaries(ResourceDictionary first, ResourceDictionary second, params string[] ignoredKeyValues)
// {
// foreach (var key in first.Keys)
// {
// if (second.Contains(key) == false)
// {
// throw new Exception($"Key \"{key}\" is missing from {second.Source}.");
// }
// if (ignoredKeyValues.Contains(key) == false)
// {
// Assert.That(second[key].ToString(), Is.EqualTo(first[key].ToString()), $"Values for {key} should be equal.");
// }
// }
// }
// }
// }