-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Fluent.Ribbon.Tests/Converters/ObjectToImageConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Fluent.Internal | ||
{ | ||
using System; | ||
|
||
internal static class TypeHelper | ||
{ | ||
public static bool InheritsFrom(this Type type, string typeName) | ||
{ | ||
var currentType = type; | ||
|
||
do | ||
{ | ||
if (currentType.Name == typeName) | ||
{ | ||
return true; | ||
} | ||
|
||
currentType = currentType.BaseType; | ||
} | ||
while (currentType != null | ||
&& currentType != typeof(object)); | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters