public void ValidatesVisualTreeStructure() { var factory = FrameworkElementFactoryExtensions.Create <StackPanel>(); const int textBoxCount = 5; const int buttonCount = 3; factory = factory.AppendNew <TextBox>(textBoxCount).AppendNew <Button>(buttonCount); var coreFactory = FrameworkElementFactoryExtensions.Create <StackPanel>(); coreFactory.AppendChild(factory); var dt = new DataTemplate() { VisualTree = coreFactory }; using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\visualTreeValidator.xaml"))) { using (var textWriter = new IndentedTextWriter(streamWriter)) { System.Windows.Markup.XamlWriter.Save(dt, textWriter); } } var treeValidator = new VisualTreeValidator(dt.VisualTree); treeValidator.RootElementIs <StackPanel>(cfg => { Assert.True(cfg.Nodes <TextBox>().Count() == textBoxCount); Assert.True(cfg.Nodes <Button>().Count() == buttonCount); }); }
public void ChecksRootElement() { var factory = FrameworkElementFactoryExtensions.Create <StackPanel>(); var treeValidator = new VisualTreeValidator(factory); Assert.DoesNotThrow(treeValidator.RootElementIs <StackPanel>); }
public void ThrowsOnRootElementMismatch() { var factory = FrameworkElementFactoryExtensions.Create <DatePicker>(); var treeValidator = new VisualTreeValidator(factory); Assert.Throws <ArgumentException>(treeValidator.RootElementIs <StackPanel>); }
public void ValidatesVisualTreeStructure() { var factory = FrameworkElementFactoryExtensions.Create<StackPanel>(); const int textBoxCount = 5; const int buttonCount = 3; factory = factory.AppendNew<TextBox>(textBoxCount).AppendNew<Button>(buttonCount); var coreFactory = FrameworkElementFactoryExtensions.Create<StackPanel>(); coreFactory.AppendChild(factory); var dt = new DataTemplate() { VisualTree = coreFactory}; using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\visualTreeValidator.xaml"))) { using (var textWriter = new IndentedTextWriter(streamWriter)) { System.Windows.Markup.XamlWriter.Save(dt, textWriter); } } var treeValidator = new VisualTreeValidator(dt.VisualTree); treeValidator.RootElementIs<StackPanel>(cfg => { Assert.True(cfg.Nodes<TextBox>().Count() == textBoxCount); Assert.True(cfg.Nodes<Button>().Count() == buttonCount); }); }
public void ThrowsOnRootElementMismatch() { var factory = FrameworkElementFactoryExtensions.Create<DatePicker>(); var treeValidator = new VisualTreeValidator(factory); Assert.Throws<ArgumentException>(treeValidator.RootElementIs<StackPanel>); }
public void ChecksRootElement() { var factory = FrameworkElementFactoryExtensions.Create<StackPanel>(); var treeValidator = new VisualTreeValidator(factory); Assert.DoesNotThrow(treeValidator.RootElementIs<StackPanel>); }
public void ValidatesBindings() { var factory = FrameworkElementFactoryExtensions.Create<StackPanel>(); const int textBoxCount = 5; const int buttonCount = 3; factory.AppendNew<Button>(buttonCount).AppendNew<TextBox>(textBoxCount); var treeValidator = new VisualTreeValidator(factory); //treeValidator.RootElementIs<StackPanel>(cfg => // Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings)); }
public void ValidatesBindings() { var factory = FrameworkElementFactoryExtensions.Create <StackPanel>(); const int textBoxCount = 5; const int buttonCount = 3; factory.AppendNew <Button>(buttonCount).AppendNew <TextBox>(textBoxCount); var treeValidator = new VisualTreeValidator(factory); //treeValidator.RootElementIs<StackPanel>(cfg => // Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings)); }
public void GeneratesTextBlocks() { WrapInAThread(() => { control = new ListBox { DataContext = viewModel }; GenerateTemplate(control); using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\goodTemplate.xaml"))) { using (var textWriter = new IndentedTextWriter(streamWriter)) { System.Windows.Markup.XamlWriter.Save(control.ItemTemplate, textWriter); } } templateRoot = control.ItemTemplate.VisualTree; Assert.IsNotNull(templateRoot); var scalarPropertyCount = typeof(PersonViewModel).GetProperties().Length; var treeValidator = new VisualTreeValidator(templateRoot); try { treeValidator.RootElementIs <StackPanel>( cfg => { Assert.True(cfg.Nodes <TextBlock>().Count() == 2 * scalarPropertyCount); //Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings); }); } catch (Exception e) { } //todo: проверить содержимое дерева - в том числе bindings }); }
public void GeneratesTextBlocks() { WrapInAThread(() => { control = new ListBox { DataContext = viewModel }; GenerateTemplate(control); using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\goodTemplate.xaml"))) { using (var textWriter = new IndentedTextWriter(streamWriter)) { System.Windows.Markup.XamlWriter.Save(control.ItemTemplate, textWriter); } } templateRoot = control.ItemTemplate.VisualTree; Assert.IsNotNull(templateRoot); var scalarPropertyCount = typeof(PersonViewModel).GetProperties().Length; var treeValidator = new VisualTreeValidator(templateRoot); try { treeValidator.RootElementIs<StackPanel>( cfg => { Assert.True(cfg.Nodes<TextBlock>().Count() == 2 * scalarPropertyCount); //Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings); }); } catch (Exception e) { } //todo: проверить содержимое дерева - в том числе bindings }); }