public void Optimize_When_ThereAreNestedMergedResourceDictionaries_Then_ResultShouldBeExpectedResult(string rootType) { var input = $@"<{rootType} xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:d=""http://schemas.microsoft.com/expression/blend/2008"" xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006"" x:Class=""Sundew.Xaml.Sample.MainWindow"" mc:Ignorable=""d"" Title=""MainWindow"" Height=""450"" Width=""800""> <{rootType}.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </{rootType}.Resources> <Grid> <Grid.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls2.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Grid.Resources> </Grid> </{rootType}>"; var expectedResult = $@"<{rootType} xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:d=""http://schemas.microsoft.com/expression/blend/2008"" xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006"" xmlns:sxo=""clr-namespace:Sundew.Xaml.Optimizations;assembly=Sundew.Xaml.Wpf"" x:Class=""Sundew.Xaml.Sample.MainWindow"" mc:Ignorable=""d"" Title=""MainWindow"" Height=""450"" Width=""800""> <{rootType}.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <sxo:ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </{rootType}.Resources> <Grid> <Grid.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <sxo:ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls2.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Grid.Resources> </Grid> </{rootType}>"; var xDocument = XDocument.Parse(input); var testee = new ResourceDictionaryCachingOptimization(this.xamlPlatformInfo); var result = testee.Optimize(xDocument, null); result.XDocument.ToString().Should().Be(XDocument.Parse(expectedResult).ToString()); }
public void Optimize_When_ThereIsNothingToOptimize_Then_ResultShouldBeSameAsInput() { var input = $@"<ResourceDictionary xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> <ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries> <Style TargetType=""{{x:Type ComboBox}}""> <Setter Property=""BorderThickness"" Value=""6""/> </Style> </ResourceDictionary>"; var xDocument = XDocument.Parse(input); var testee = new ResourceDictionaryCachingOptimization(this.xamlPlatformInfo); var result = testee.Optimize(xDocument, null); result.XDocument.ToString().Should().Be(XDocument.Parse(input).ToString()); }
public void Optimize_When_ThereIsOneMergedResourceDictionary_Then_ResultShouldBeExpectedResult(string rootType) { var input = $@"<{rootType} x:Class=""Sundew.Xaml.Optimizer.Sample"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" StartupUri=""MainWindow.xaml""> <{rootType}.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </{rootType}.Resources> </{rootType}>"; var expectedResult = $@"<{rootType} x:Class=""Sundew.Xaml.Optimizer.Sample"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:sxo=""clr-namespace:Sundew.Xaml.Optimizations;assembly=Sundew.Xaml.Wpf"" StartupUri=""MainWindow.xaml""> <{rootType}.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <sxo:ResourceDictionary Source=""/Sundew.Xaml.Sample.Wpf;component/Controls.xaml"" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </{rootType}.Resources> </{rootType}>"; var xDocument = XDocument.Parse(input); var testee = new ResourceDictionaryCachingOptimization(this.xamlPlatformInfo); var result = testee.Optimize(xDocument, null); result.XDocument.ToString().Should().Be(XDocument.Parse(expectedResult).ToString()); }