-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including a repro (`EnumToEnumerable`) from a customer. Looks like the problem can't be reproduced in unit tests.
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace Avalonia.Markup.Xaml.UnitTests | ||
{ | ||
public class EnumToEnumerable : MarkupExtension | ||
{ | ||
private readonly Type _enumType; | ||
|
||
public EnumToEnumerable(Type type) | ||
{ | ||
if (!type.IsEnum) | ||
throw new ArgumentException(nameof(type)); | ||
_enumType = type; | ||
} | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return Enum.GetValues(_enumType); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/MarkupExtensionTests.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,32 @@ | ||
using System.Collections; | ||
using Avalonia.Controls; | ||
using Avalonia.UnitTests; | ||
using Xunit; | ||
|
||
namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions | ||
{ | ||
public class MarkupExtensionTests : XamlTestBase | ||
{ | ||
[Fact] | ||
public void Markup_Extension_Can_Accept_Nested_Type() | ||
{ | ||
using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) | ||
{ | ||
var xaml = @" | ||
<Window xmlns='https://github.com/avaloniaui' | ||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' | ||
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'> | ||
<ListBox Items='{local:EnumToEnumerable {x:Type local:TestViewModel+NestedEnum}}'/> | ||
</Window>"; | ||
|
||
var window = AvaloniaRuntimeXamlLoader.Parse<Window>(xaml); | ||
var listBox = (ListBox)window.Content; | ||
var items = (IList)listBox.Items; | ||
|
||
Assert.Equal(2, items.Count); | ||
Assert.Equal(TestViewModel.NestedEnum.Item1, items[0]); | ||
Assert.Equal(TestViewModel.NestedEnum.Item2, items[1]); | ||
} | ||
} | ||
} | ||
} |
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