Browse Source

Update tests with "LoadGroup" method instead of assetloader hacks

pull/9537/head
Max Katz 3 years ago
parent
commit
c8120fbbe7
  1. 108
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs
  2. 44
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/ResourceIncludeTests.cs
  3. 44
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/StaticResourceExtensionTests.cs
  4. 51
      tests/Avalonia.Markup.Xaml.UnitTests/StyleIncludeTests.cs
  5. 22
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
  6. 22
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs
  7. 3
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml
  8. 3
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/Style2.xaml
  9. 184
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs
  10. 39
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs

108
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs

@ -250,30 +250,32 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void DynamicResource_Can_Be_Assigned_To_Setter_In_Styles_File()
{
var styleXaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Styles.Resources>
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
</Styles.Resources>
<Style Selector='Border'>
<Setter Property='Background' Value='{DynamicResource brush}'/>
</Style>
</Styles>";
using (StyledWindow(assets: ("test:style.xaml", styleXaml)))
{
var xaml = @"
</Styles>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style.xaml'/>
<StyleInclude Source='avares://Tests/Style.xaml'/>
</Window.Styles>
<Border Name='border'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
</Window>")
};
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[1]);
var border = window.FindControl<Border>("border");
var brush = (ISolidColorBrush)border.Background;
@ -284,13 +286,14 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void DynamicResource_Can_Be_Assigned_To_Property_In_ControlTemplate_In_Styles_File()
{
var styleXaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Styles.Resources>
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
</Styles.Resources>
<Style Selector='Button'>
<Setter Property='Template'>
<ControlTemplate>
@ -298,20 +301,21 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
</ControlTemplate>
</Setter>
</Style>
</Styles>";
using (StyledWindow(assets: ("test:style.xaml", styleXaml)))
{
var xaml = @"
</Styles>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style.xaml'/>
<StyleInclude Source='avares://Tests/Style.xaml'/>
</Window.Styles>
<Button Name='button'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
</Window>")
};
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[1]);
var button = window.FindControl<Button>("button");
window.Show();
@ -553,35 +557,37 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void DynamicResource_Can_Be_Found_Across_Xaml_Style_Files()
{
var style1Xaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style1.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<Color x:Key='Red'>Red</Color>
</Style.Resources>
</Style>";
var style2Xaml = @"
</Style>"),
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style2.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<SolidColorBrush x:Key='RedBrush' Color='{DynamicResource Red}'/>
</Style.Resources>
</Style>";
using (StyledWindow(
("test:style1.xaml", style1Xaml),
("test:style2.xaml", style2Xaml)))
{
var xaml = @"
</Style>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style1.xaml'/>
<StyleInclude Source='test:style2.xaml'/>
<StyleInclude Source='avares://Tests/Style1.xaml'/>
<StyleInclude Source='avares://Tests/Style2.xaml'/>
</Window.Styles>
<Border Name='border' Background='{DynamicResource RedBrush}'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
</Window>")
};
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[2]);
var border = window.FindControl<Border>("border");
var borderBrush = (ISolidColorBrush)border.Background;
@ -593,33 +599,35 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void DynamicResource_Can_Be_Found_In_Nested_Style_File()
{
var style1Xaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style1.xaml"), @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<StyleInclude Source='test:style2.xaml'/>
</Styles>";
var style2Xaml = @"
<StyleInclude Source='avares://Tests/Style2.xaml'/>
</Styles>"),
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style2.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<Color x:Key='Red'>Red</Color>
<SolidColorBrush x:Key='RedBrush' Color='{DynamicResource Red}'/>
</Style.Resources>
</Style>";
using (StyledWindow(
("test:style1.xaml", style1Xaml),
("test:style2.xaml", style2Xaml)))
{
var xaml = @"
</Style>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style1.xaml'/>
<StyleInclude Source='avares://Tests/Style1.xaml'/>
</Window.Styles>
<Border Name='border' Background='{DynamicResource RedBrush}'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
</Window>")
};
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[2]);
var border = window.FindControl<Border>("border");
var borderBrush = (ISolidColorBrush)border.Background;

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

@ -14,29 +14,32 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void ResourceInclude_Loads_ResourceDictionary()
{
var includeXaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Resource.xaml"), @"
<ResourceDictionary xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
</ResourceDictionary>
";
using (StartWithResources(("test:include.xaml", includeXaml)))
{
var xaml = @"
</ResourceDictionary>"),
new RuntimeXamlLoaderDocument(@"
<UserControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source='test:include.xaml'/>
<ResourceInclude Source='avares://Tests/Resource.xaml'/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border Name='border' Background='{StaticResource brush}'/>
</UserControl>";
</UserControl>")
};
var userControl = (UserControl)AvaloniaRuntimeXamlLoader.Load(xaml);
using (StartWithResources())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var userControl = Assert.IsType<UserControl>(compiled[1]);
var border = userControl.FindControl<Border>("border");
var brush = (ISolidColorBrush)border.Background;
@ -47,31 +50,32 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void Missing_ResourceKey_In_ResourceInclude_Does_Not_Cause_StackOverflow()
{
var styleXaml = @"
var app = Application.Current;
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Resource.xaml"), @"
<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 = @"
</ResourceDictionary>"),
new RuntimeXamlLoaderDocument(app, @"
<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'/>
<ResourceInclude Source='avares://Tests/Resource.xaml'/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>";
var app = Application.Current;
</Application>")
};
using (StartWithResources())
{
try
{
AvaloniaRuntimeXamlLoader.Load(xaml, null, app);
AvaloniaRuntimeXamlLoader.LoadGroup(documents);
}
catch (KeyNotFoundException)
{

44
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/StaticResourceExtensionTests.cs

@ -238,7 +238,9 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void StaticResource_Can_Be_Assigned_To_Setter_In_Styles_File()
{
var styleXaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Styles.Resources>
@ -248,20 +250,21 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
<Style Selector='Border'>
<Setter Property='Background' Value='{StaticResource brush}'/>
</Style>
</Styles>";
using (StyledWindow(assets: ("test:style.xaml", styleXaml)))
{
var xaml = @"
</Styles>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style.xaml'/>
<StyleInclude Source='avares://Tests/Style.xaml'/>
</Window.Styles>
<Border Name='border'/>
</Window>";
</Window>")
};
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[1]);
var border = window.FindControl<Border>("border");
var brush = (ISolidColorBrush)border.Background;
@ -311,7 +314,9 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Fact]
public void StaticResource_Can_Be_Assigned_To_Property_In_ControlTemplate_In_Styles_File()
{
var styleXaml = @"
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Styles.Resources>
@ -325,20 +330,21 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
</ControlTemplate>
</Setter>
</Style>
</Styles>";
using (StyledWindow(assets: ("test:style.xaml", styleXaml)))
{
var xaml = @"
</Styles>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<StyleInclude Source='test:style.xaml'/>
<StyleInclude Source='avares://Tests/Style.xaml'/>
</Window.Styles>
<Button Name='button'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
</Window>")
};
using (StyledWindow())
{
var compiled = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(compiled[1]);
var button = window.FindControl<Button>("button");
window.Show();

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

@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
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 app = Application.Current;
try
{
AvaloniaRuntimeXamlLoader.Load(xaml, null, app);
}
catch (KeyNotFoundException)
{
}
}
}
private IDisposable StartWithResources(params (string, string)[] assets)
{
var assetLoader = new MockAssetLoader(assets);
var services = new TestServices(assetLoader: assetLoader);
return UnitTestApplication.Start(services);
}
}
}

22
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

@ -18,6 +18,7 @@ using System.Xml;
using Xunit;
using Avalonia.Controls.Documents;
using Avalonia.Metadata;
using Avalonia.Themes.Simple;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
{
@ -458,27 +459,6 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
Assert.Equal(10.0, d);
}
[Fact]
public void StyleInclude_Is_Built()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = @"
<Styles xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<StyleInclude Source='avares://Avalonia.Themes.Simple/Controls/UserControl.xaml'/>
</Styles>";
var styles = AvaloniaRuntimeXamlLoader.Parse<Styles>(xaml);
Assert.True(styles.Count == 1);
var styleInclude = styles.First() as IStyle;
Assert.NotNull(styleInclude);
}
}
[Fact]
public void Simple_Xaml_Binding_Is_Operational()
{

22
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs

@ -33,29 +33,32 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
[Fact]
public void DynamicResource_Finds_Resource_In_Parent_Dictionary()
{
var dictionaryXaml = @"
using (StyledWindow())
{
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Avalonia.Markup.Xaml.UnitTests/dict.xaml"), @"
<ResourceDictionary xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<SolidColorBrush x:Key='RedBrush' Color='{DynamicResource Red}'/>
</ResourceDictionary>";
using (StyledWindow(assets: ("test:dict.xaml", dictionaryXaml)))
{
var xaml = @"
</ResourceDictionary>"),
new RuntimeXamlLoaderDocument(@"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source='test:dict.xaml'/>
<ResourceInclude Source='avares://Avalonia.Markup.Xaml.UnitTests/dict.xaml'/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Color x:Key='Red'>Red</Color>
</Window.Resources>
<Button Name='button' Background='{DynamicResource RedBrush}'/>
</Window>";
</Window>")
};
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var loaded = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var window = Assert.IsType<Window>(loaded[1]);
var button = window.FindControl<Button>("button");
var brush = Assert.IsType<SolidColorBrush>(button.Background);
@ -276,7 +279,6 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
private IDisposable StyledWindow(params (string, string)[] assets)
{
var services = TestServices.StyledWindow.With(
assetLoader: new MockAssetLoader(assets),
theme: () => new Styles
{
WindowStyle(),

3
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml

@ -1,6 +1,5 @@
<Style xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Precompile="False">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style.Resources>
<Color x:Key="Red">Red</Color>
<Color x:Key="Green">Green</Color>

3
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/Style2.xaml

@ -1,6 +1,5 @@
<Style xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Precompile="False">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style.Resources>
<SolidColorBrush x:Key="RedBrush" Color="{DynamicResource Red}"/>
<SolidColorBrush x:Key="GreenBrush" Color="{DynamicResource Green}"/>

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

@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Styling;
using Avalonia.Themes.Simple;
using Avalonia.UnitTests;
using Xunit;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml;
public class StyleIncludeTests
{
[Fact]
public void StyleInclude_Is_Built()
{
using (UnitTestApplication.Start(TestServices.StyledWindow
.With(theme: () => new Styles())))
{
var xaml = @"
<ContentControl xmlns='https://github.com/avaloniaui'>
<ContentControl.Styles>
<StyleInclude Source='avares://Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml'/>
</ContentControl.Styles>
</ContentControl>";
var window = AvaloniaRuntimeXamlLoader.Parse<ContentControl>(xaml);
Assert.IsType<Style>(window.Styles[0]);
}
}
[Fact]
public void StyleInclude_Is_Built_Resources()
{
using (UnitTestApplication.Start(TestServices.StyledWindow
.With(theme: () => new Styles())))
{
var xaml = @"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Resources>
<StyleInclude x:Key='Include' Source='avares://Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml'/>
</ContentControl.Resources>
</ContentControl>";
var contentControl = AvaloniaRuntimeXamlLoader.Parse<ContentControl>(xaml);
Assert.IsType<Style>(contentControl.Resources["Include"]);
}
}
[Fact]
public void StyleInclude_Is_Resolved_With_Two_Files()
{
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<Color x:Key='Red'>Red</Color>
</Style.Resources>
</Style>"),
new RuntimeXamlLoaderDocument(@"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Resources>
<StyleInclude x:Key='Include' Source='avares://Tests/Style.xaml'/>
</ContentControl.Resources>
</ContentControl>")
};
var objects = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var style = Assert.IsType<Style>(objects[0]);
var contentControl = Assert.IsType<ContentControl>(objects[1]);
Assert.IsType<Style>(contentControl.Resources["Include"]);
}
[Fact]
public void Relative_StyleInclude_Is_Resolved_With_Two_Files()
{
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<Color x:Key='Red'>Red</Color>
</Style.Resources>
</Style>"),
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Folder/Root.xaml"), @"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Resources>
<StyleInclude x:Key='Include' Source='/../Style.xaml'/>
</ContentControl.Resources>
</ContentControl>")
};
var objects = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var style = Assert.IsType<Style>(objects[0]);
var contentControl = Assert.IsType<ContentControl>(objects[1]);
Assert.IsType<Style>(contentControl.Resources["Include"]);
}
[Fact]
public void NonLatin_StyleInclude_Is_Resolved_With_Two_Files()
{
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://アセンブリ/スタイル.xaml"), @"
<Style xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style.Resources>
<Color x:Key='Red'>Red</Color>
</Style.Resources>
</Style>"),
new RuntimeXamlLoaderDocument(@"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Resources>
<StyleInclude x:Key='Include' Source='avares://アセンブリ/スタイル.xaml'/>
</ContentControl.Resources>
</ContentControl>")
};
var objects = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
var style = Assert.IsType<Style>(objects[0]);
var contentControl = Assert.IsType<ContentControl>(objects[1]);
Assert.IsType<Style>(contentControl.Resources["Include"]);
}
[Fact]
public void Missing_ResourceKey_In_StyleInclude_Does_Not_Cause_StackOverflow()
{
var documents = new[]
{
new RuntimeXamlLoaderDocument(new Uri("avares://Tests/Style.xaml"), @"
<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>"),
new RuntimeXamlLoaderDocument(@"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Styles>
<StyleInclude Source='avares://Tests/Style.xaml'/>
</ContentControl.Styles>
</ContentControl>")
};
try
{
_ = AvaloniaRuntimeXamlLoader.LoadGroup(documents);
}
catch (KeyNotFoundException)
{
}
}
[Fact]
public void StyleInclude_Should_Be_Replaced_With_Direct_Call()
{
var control = (ContentControl)AvaloniaRuntimeXamlLoader.Load(@"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:themes='clr-namespace:Avalonia.Themes.Simple;assembly=Avalonia.Themes.Simple'>
<ContentControl.Styles>
<themes:SimpleTheme />
<StyleInclude Source='avares://Avalonia.Themes.Simple/SimpleTheme.xaml'/>
</ContentControl.Styles>
</ContentControl>");
Assert.IsType<SimpleTheme>(control.Styles[0]);
Assert.IsType<SimpleTheme>(control.Styles[1]);
}
}

39
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs

@ -109,45 +109,6 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
}
}
[Fact]
public void StyleInclude_Is_Built()
{
using (UnitTestApplication.Start(TestServices.StyledWindow
.With(theme: () => new Styles())))
{
var xaml = @"
<ContentControl xmlns='https://github.com/avaloniaui'>
<ContentControl.Styles>
<StyleInclude Source='avares://Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml'/>
</ContentControl.Styles>
</ContentControl>";
var window = AvaloniaRuntimeXamlLoader.Parse<ContentControl>(xaml);
Assert.IsType<Style>(window.Styles[0]);
}
}
[Fact]
public void StyleInclude_Is_Built_Resources()
{
using (UnitTestApplication.Start(TestServices.StyledWindow
.With(theme: () => new Styles())))
{
var xaml = @"
<ContentControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ContentControl.Resources>
<StyleInclude x:Key='Include' Source='avares://Avalonia.Markup.Xaml.UnitTests/Xaml/Style1.xaml'/>
</ContentControl.Resources>
</ContentControl>";
var window = AvaloniaRuntimeXamlLoader.Parse<ContentControl>(xaml);
Assert.IsType<Style>(window.Resources["Include"]);
}
}
[Fact]
public void Setter_Can_Contain_Template()
{

Loading…
Cancel
Save