Browse Source

Add failing unit tests.

pull/4007/head
Dan Walmsley 6 years ago
parent
commit
455c899876
  1. 30
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs
  2. 44
      tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs

30
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs

@ -44,6 +44,36 @@ namespace Avalonia.Markup.Xaml.UnitTests.MakrupExtensions
}
}
[Fact]
public void Missing_ResourceKey_In_ResourceInclude_Does_Not_Cause_StackOverflow()
{
var styleXaml = @"
<ResourceDictionary xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<StaticResource x:Key='brush' ResourceKey='missing' />
</ResourceDictionary>";
using (StartWithResources(("test:style.xaml", styleXaml)))
{
var xaml = @"
<Application xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source='test:style.xaml'/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>";
var loader = new AvaloniaXamlLoader();
var app = Application.Current;
loader.Load(xaml, null, app);
}
}
private IDisposable StartWithResources(params (string, string)[] assets)
{
var assetLoader = new MockAssetLoader(assets);

44
tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs

@ -0,0 +1,44 @@
using System;
using Avalonia.UnitTests;
using Xunit;
namespace Avalonia.Markup.Xaml.UnitTests
{
public class StyleIncludeTests : XamlTestBase
{
[Fact]
public void Missing_ResourceKey_In_StyleInclude_Does_Not_Cause_StackOverflow()
{
var styleXaml = @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<StaticResource x:Key='brush' ResourceKey='missing' />
</Style.Resources>
</Style>";
using (StartWithResources(("test:style.xaml", styleXaml)))
{
var xaml = @"
<Application xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Application.Styles>
<StyleInclude Source='test:style.xaml'/>
</Application.Styles>
</Application>";
var loader = new AvaloniaXamlLoader();
var app = Application.Current;
loader.Load(xaml, null, app);
}
}
private IDisposable StartWithResources(params (string, string)[] assets)
{
var assetLoader = new MockAssetLoader(assets);
var services = new TestServices(assetLoader: assetLoader);
return UnitTestApplication.Start(services);
}
}
}
Loading…
Cancel
Save