public void VerifyOptionsAreHelpful() { var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, null); ProcessElement(new TextBlock() { Foreground = new SolidColorBrush(Colors.DarkGreen) }); ProcessElement(new Button() { BorderBrush = new SolidColorBrush(Colors.LightGreen), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.DarkGreen), Foreground = new SolidColorBrush(Colors.DarkGreen) }); ProcessElement(new Grid() { BorderBrush = new SolidColorBrush(Colors.LightGreen), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.DarkGreen) }); ProcessElement(new StackPanel() { BorderBrush = new SolidColorBrush(Colors.LightGreen), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.DarkGreen) }); ProcessElement(new TextBox() { BorderBrush = new SolidColorBrush(Colors.LightGreen), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.DarkGreen), Foreground = new SolidColorBrush(Colors.DarkGreen) }); ProcessElement(new Page() { BorderBrush = new SolidColorBrush(Colors.LightGreen), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.DarkGreen), Foreground = new SolidColorBrush(Colors.DarkGreen) }); void ProcessElement(FrameworkElement element) { App.Content = element; var snapshot = snapshotCreator.CreateSnapshot(element); int nonNullCount = 0; foreach (var property in snapshot.PropertyValues) { if (property != null) { nonNullCount++; } } Assert.IsTrue(nonNullCount >= 4, $"Non null properties was {nonNullCount} which is to low (less than two)."); } }
public void VerifyCreatesSimplePageTreeCorrectly() { var page = new SimplePage(); App.Content = page; var snapshotCreator = new ElementSnapshotCreator(testPropertyNames, page); var pageSnapshot = snapshotCreator.CreateSnapshot(); Assert.AreEqual(testPropertyNames, pageSnapshot.PropertyNames); Assert.AreEqual("SimplePageName", pageSnapshot.ElementName); Assert.AreEqual("VisualTreeAnalyzers.Tests.TestInfra.DemoVisualTrees.SimplePage", pageSnapshot.FullTypeName); Assert.AreEqual(1, pageSnapshot.Children.Count); var gridSnapshot = pageSnapshot.Children[0]; Assert.AreEqual(testPropertyNames, gridSnapshot.PropertyNames); Assert.AreEqual("RootGrid", gridSnapshot.ElementName); Assert.AreEqual("Windows.UI.Xaml.Controls.Grid", gridSnapshot.FullTypeName); Assert.AreEqual(1, gridSnapshot.Children.Count); Assert.AreEqual("#FFD3D3D3", (gridSnapshot.PropertyValues[3] as SolidColorBrush).Color.ToString()); var textBlockSnapshot = gridSnapshot.Children[0]; Assert.AreEqual(testPropertyNames, textBlockSnapshot.PropertyNames); Assert.AreEqual("ExampleTextBlock", textBlockSnapshot.ElementName); Assert.AreEqual("Windows.UI.Xaml.Controls.TextBlock", textBlockSnapshot.FullTypeName); Assert.AreEqual(0, textBlockSnapshot.Children.Count); Assert.AreEqual("#FF006400", (textBlockSnapshot.PropertyValues[4] as SolidColorBrush).Color.ToString()); Assert.AreEqual("Some text", textBlockSnapshot.PropertyValues[5]); }
public VisualTreeSnapshotDemoPage() { InitializeComponent(); snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, SampleControlsPanel); Loaded += VisualTreeSnapshotDemoPage_Loaded; }
public void VerifySinglePageJSONExport() { App.Content = new SimplePage(); var exporter = new JsonExporter(new StandardObjectToStringConverter()); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateJsonObject(snapshotCreator.CreateSnapshot(), false, true); Assert.IsNotNull(export); var jsonAsText = export.Stringify(); Assert.IsTrue(jsonAsText.Contains("VisualTreeAnalyzers.Tests.TestInfra.DemoVisualTrees.SimplePage")); Assert.IsTrue(jsonAsText.Contains("\"type\":\"Windows.UI.Xaml.Controls.Grid\",\"Name\":\"RootGrid\"")); }
public void VerifySinglePageXMLExport() { App.Content = new SimplePage(); var exporter = new XmlExporter(new StandardObjectToStringConverter()); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateXMLDocument(snapshotCreator.CreateSnapshot(), false, true); Assert.IsNotNull(export); var xmlAsText = export.GetXml(); Assert.IsTrue(xmlAsText.Contains("VisualTreeAnalyzers.Tests.TestInfra.DemoVisualTrees.SimplePage")); Assert.IsTrue(xmlAsText.Contains($"Windows.UI.Xaml.Controls.Grid Name=\"RootGrid\"")); }
public void ValidatesInput() { var element = new Button(); Assert.IsNotNull(new ElementSnapshotCreator( new List <string>() { "Visibility" }, null) ); Assert.ThrowsException <ArgumentNullException>(() => { _ = new ElementSnapshotCreator(null, element); }); }
public void VerifyButtonFormattedXMLExportWithNamespaces() { App.Content = new Button() { RequestedTheme = Windows.UI.Xaml.ElementTheme.Light }; var exporter = new XmlExporter(new StandardObjectToStringConverter()); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var exportFormatted = exporter.CreateFormattedXMLString(snapshotCreator.CreateSnapshot(), false, true); var expected = @"<Windows.UI.Xaml.Controls.Button Visibility=""Visible"" Margin=""0,0,0,0"" Padding=""8,4,8,5"" Background=""#33000000"" BorderBrush=""#00FFFFFF"" BorderThickness=""2,2,2,2"" Foreground=""#FF000000""> <Windows.UI.Xaml.Controls.ContentPresenter Name=""ContentPresenter"" Visibility=""Visible"" Margin=""0,0,0,0"" Padding=""8,4,8,5"" Background=""#33000000"" BorderBrush=""#00FFFFFF"" BorderThickness=""2,2,2,2"" Foreground=""#FF000000"" /> </Windows.UI.Xaml.Controls.Button>"; Assert.AreEqual(expected, exportFormatted); }
public void VerifyChildrenCountCorrect() { var panel = new StackPanel(); var childCount = new Random().Next(3, 15); for (int i = 0; i < childCount; i++) { panel.Children.Add(new TextBlock()); } App.Content = panel; var snapshotCreator = new ElementSnapshotCreator(new List <string>(), panel); var snapshot = snapshotCreator.CreateSnapshot(); Assert.AreEqual(childCount, snapshot.Children.Count); for (int i = 0; i < childCount; i++) { Assert.AreEqual(0, snapshot.Children[i].Children.Count); } }
public void VerifyButtonFormattedJSONExportWithoutNamespacesWithNullValues() { App.Content = new Button() { RequestedTheme = Windows.UI.Xaml.ElementTheme.Light }; var exporter = new JsonExporter(new StandardObjectToStringConverter()); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var exportFormatted = exporter.CreateFormattedJSONString(snapshotCreator.CreateSnapshot(), true, false); var expected = @"{ ""type"": ""Button"", ""Name"": """", ""Visibility"": ""Visible"", ""Margin"": ""0,0,0,0"", ""Padding"": ""8,4,8,5"", ""Background"": ""#33000000"", ""BorderBrush"": ""#00FFFFFF"", ""BorderThickness"": ""2,2,2,2"", ""Foreground"": ""#FF000000"", ""children"": [ { ""type"": ""ContentPresenter"", ""Name"": ""ContentPresenter"", ""Visibility"": ""Visible"", ""Margin"": ""0,0,0,0"", ""Padding"": ""8,4,8,5"", ""Background"": ""#33000000"", ""BorderBrush"": ""#00FFFFFF"", ""BorderThickness"": ""2,2,2,2"", ""Foreground"": ""#FF000000"", ""children"": [] } ] }"; Assert.AreEqual(expected, exportFormatted); }
public void VerifySingleWUXCControlIsCorrectNoConverterNoNullValues() { App.Content = new TextBlock() { Text = "Some text", Foreground = new SolidColorBrush(Colors.DarkGreen) }; var exporter = new JsonExporter(null); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateJsonObject(snapshotCreator.CreateSnapshot(), false, true); Assert.IsNotNull(export); Assert.AreEqual("Windows.UI.Xaml.Controls.TextBlock", export.GetNamedString("type")); var jsonAsText = export.Stringify(); Assert.IsTrue(jsonAsText.Contains("\"Visibility\":\"Visible\"")); Assert.IsTrue(jsonAsText.Contains("\"Margin\":\"0,0,0,0\"")); Assert.IsTrue(jsonAsText.Contains("\"Padding\":\"0,0,0,0\"")); Assert.IsFalse(jsonAsText.Contains("\"Background\"")); // Background should not be present in the export as it was not set. Assert.IsTrue(jsonAsText.Contains($"\"Foreground\":\"Windows.UI.Xaml.Media.SolidColorBrush\"")); }
public void VerifySingleWUXCControlIsCorrectDefaultOptions() { App.Content = new TextBlock() { Text = "Some text", Foreground = new SolidColorBrush(Colors.DarkGreen) }; var exporter = new JsonExporter(); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateJsonObject(snapshotCreator.CreateSnapshot(), true, false); Assert.IsNotNull(export); Assert.AreEqual("TextBlock", export.GetNamedString("type")); var jsonAsText = export.Stringify(); Assert.IsTrue(jsonAsText.Contains("\"Visibility\":\"Visible\"")); Assert.IsTrue(jsonAsText.Contains("\"Margin\":\"0,0,0,0\"")); Assert.IsTrue(jsonAsText.Contains("\"Padding\":\"0,0,0,0\"")); Assert.IsTrue(jsonAsText.Contains("\"Background\":\"[null]\"")); Assert.IsTrue(jsonAsText.Contains($"\"Foreground\":\"{Colors.DarkGreen}\"")); }
public void VerifySingleWUXCControlIsCorrectNoConverterNoNullValues() { App.Content = new TextBlock() { Text = "Some text", Foreground = new SolidColorBrush(Colors.DarkGreen) }; var exporter = new XmlExporter(null); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateXMLDocument(snapshotCreator.CreateSnapshot(), false, true); Assert.IsNotNull(export); Assert.AreEqual("Windows.UI.Xaml.Controls.TextBlock", export.FirstChild.NodeName); Assert.AreEqual(null, export.FirstChild.Prefix); var xmlAsText = export.GetXml(); Assert.IsTrue(xmlAsText.Contains("Visibility=\"Visible\"")); Assert.IsTrue(xmlAsText.Contains("Margin=\"0,0,0,0\"")); Assert.IsTrue(xmlAsText.Contains("Padding=\"0,0,0,0\"")); Assert.IsFalse(xmlAsText.Contains("Background")); // Background should not be present in the export as it was not set. Assert.IsTrue(xmlAsText.Contains($"Foreground=\"Windows.UI.Xaml.Media.SolidColorBrush\"")); }
public void VerifySingleWUXCControlIsCorrectDefaultOptions() { App.Content = new TextBlock() { Text = "Some text", Foreground = new SolidColorBrush(Colors.DarkGreen) }; var exporter = new XmlExporter(); var snapshotCreator = new ElementSnapshotCreator(StandardOptions.StandardPropertyNames, App.Content); var export = exporter.CreateXMLDocument(snapshotCreator.CreateSnapshot(), true, false); Assert.IsNotNull(export); Assert.AreEqual("TextBlock", export.FirstChild.NodeName); Assert.AreEqual(null, export.FirstChild.Prefix); var xmlAsText = export.GetXml(); Assert.IsTrue(xmlAsText.Contains("Visibility=\"Visible\"")); Assert.IsTrue(xmlAsText.Contains("Margin=\"0,0,0,0\"")); Assert.IsTrue(xmlAsText.Contains("Padding=\"0,0,0,0\"")); Assert.IsTrue(xmlAsText.Contains("Background=\"[null]\"")); Assert.IsTrue(xmlAsText.Contains($"Foreground=\"{Colors.DarkGreen}\"")); }