示例#1
0
        public void ShouldHaveCorrectBindingsDefined()
        {
            Grid grid = _window.Content as Grid;
            IList <StackPanel> stackPanels = grid.FindVisualChildren <StackPanel>().ToList();

            Assert.That(stackPanels.Count, Is.EqualTo(2), "There should be exactly 2 StackPanel elements in the window.");

            for (int fighterNumber = 1; fighterNumber <= 2; fighterNumber++)
            {
                StackPanel        stackPanel = stackPanels[fighterNumber - 1];
                IList <TextBlock> textBlocks = stackPanel.FindVisualChildren <TextBlock>().ToList();
                Assert.That(textBlocks.Count, Is.EqualTo(2),
                            "There should be exactly 2 TextBlock elements " +
                            $"that are children of the StackPanel of fighter {fighterNumber}.");

                TextBlock nameTextBlock = textBlocks[0];
                AssertBinding(nameTextBlock, $"fighter {fighterNumber} name TextBlock", TextBlock.TextProperty,
                              $"Fighter{fighterNumber}.Name", BindingMode.OneWay);

                TextBlock healthTextBlock = textBlocks[1];
                AssertBinding(healthTextBlock, $"fighter {fighterNumber} health TextBlock", TextBlock.TextProperty,
                              $"Fighter{fighterNumber}.Health", BindingMode.OneWay);
            }
        }