public void IsVisibleTest() { // Arrange. var rootVisual = new StackPanel { Visibility = Visibility.Visible }; var visibleContainer = new StackPanel { Visibility = Visibility.Visible }; rootVisual.Children.Add(visibleContainer); var collapsedContainer = new StackPanel { Visibility = Visibility.Collapsed }; rootVisual.Children.Add(collapsedContainer); var textBoxInVisibleContainer = new TextBox { Visibility = Visibility.Visible }; visibleContainer.Children.Add(textBoxInVisibleContainer); var textBoxInCollapsedContainer = new TextBox { Visibility = Visibility.Visible }; collapsedContainer.Children.Add(textBoxInCollapsedContainer); var textBoxNotInVisualTree = new TextBox { Visibility = Visibility.Visible }; Mock.Arrange(() => Application.Current.RootVisual).Returns(rootVisual); // Act / Assert. Assert.IsTrue(rootVisual.IsVisibile()); Assert.IsTrue(visibleContainer.IsVisibile()); Assert.IsFalse(collapsedContainer.IsVisibile()); Assert.IsTrue(textBoxInVisibleContainer.IsVisibile()); Assert.IsFalse(textBoxInCollapsedContainer.IsVisibile()); Assert.IsFalse(textBoxNotInVisualTree.IsVisibile()); }