Skip to content

Commit

Permalink
test: add test code for issue fluentribbon#1152
Browse files Browse the repository at this point in the history
  • Loading branch information
nishy2000 committed Jul 22, 2023
1 parent 66f71e4 commit 1bef9d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Fluent.Ribbon.Showcase/TestContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3588,6 +3588,9 @@
</GroupBox>
<GroupBox Header="Issue repros">
<WrapPanel>
<WrapPanel.Resources>
<Fluent:ObjectToImageConverter x:Key="StringToImageConvert"/>
</WrapPanel.Resources>
<Fluent:Button x:Name="SleepButton"
VerticalAlignment="Top"
Click="SleepButton_OnClick"
Expand All @@ -3602,6 +3605,13 @@
Change theme from thread
</Fluent:Button>

<Fluent:Button VerticalAlignment="Top"
Tag="/Images/Blue.png"
Icon="{Binding Path=Tag,RelativeSource={RelativeSource Self},Converter={StaticResource StringToImageConvert}}"
Size="Middle">
ObjectToImageConverter for issue #1152
</Fluent:Button>

<GroupBox Header="KeyTip issues #254">
<StackPanel Orientation="Vertical">
<formsInterop:WindowsFormsHost>
Expand Down
33 changes: 32 additions & 1 deletion Fluent.Ribbon.Tests/Converters/ObjectToImageConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,35 @@ public void TestDynamicResource()
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())));
}
}

private class DummyProvider : IServiceProvider
{
object IServiceProvider.GetService(Type serviceType)
{
return null;
}
}

[Test]
public void TestStaticResourceSequnece()
{
var fluentRibbonImagesApplicationmenuResourceKey = (object)"Fluent.Ribbon.Images.ApplicationMenu";

var expressionType = typeof(ResourceReferenceExpressionConverter).Assembly.GetType("System.Windows.ResourceReferenceExpression");

var expression = Activator.CreateInstance(expressionType, fluentRibbonImagesApplicationmenuResourceKey);

var converter = new ObjectToImageConverter();

converter.ProvideValue(new DummyProvider());

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>());
}
}

0 comments on commit 1bef9d9

Please sign in to comment.