private static string SerializeVisualTree(VisualTreeObject o) { var serializer = new XmlSerializer(typeof(VisualTreeObject)); using (var stringWriter = new StringWriter()) { serializer.Serialize(stringWriter, o); return stringWriter.ToString(); } }
private static void CompareVisualTree(VisualTreeObject actual, VisualTreeObject expected, bool compareProperty = true) { // compare actual.Name.ShouldBeEquivalentTo(expected.Name); if (compareProperty) { var filteredActual = actual.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); var filteredExpected = expected.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); var onlyInActual = filteredActual.Except(filteredExpected); var onlyInExpected = filteredExpected.Except(filteredActual); onlyInActual.Count().ShouldBeEquivalentTo(0); onlyInExpected.Count().ShouldBeEquivalentTo(0); } actual.Children.Count.ShouldBeEquivalentTo(expected.Children.Count); var sortedActualChildren = actual.Children.OrderBy(c => c.Name); var sortedExpectedChildren = expected.Children.OrderBy(c => c.Name); for (int i = 0; i < actual.Children.Count; i++) { CompareVisualTree(sortedActualChildren.ElementAt(i), sortedExpectedChildren.ElementAt(i), compareProperty); } }
private static string SerializeVisualTree(VisualTreeObject o) { var serializer = new XmlSerializer(typeof(VisualTreeObject)); using (var stringWriter = new StringWriter()) { serializer.Serialize(stringWriter, o); return(stringWriter.ToString()); } }
private static string SerializeVisualTree(VisualTreeObject o) { var serializer = new JsonSerializer(); using (var sw = new StringWriter()) { using (var writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; serializer.Serialize(writer, o); return sw.ToString(); } } }
private static void CompareVisualTreesImplementation(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { string testFileName = fileName + ".tree"; string testFilePath = fixture.GetDestinationPath(testFileName); var serializedActual = SerializeVisualTree(actual); string baselineFilePath = fixture.GetSourcePath(testFileName); if (_regenerateBaselineFiles) { TestFiles.UpdateBaseline(baselineFilePath, serializedActual); } else { TestFiles.CompareToBaseLine(baselineFilePath, serializedActual); } }
private static string SerializeVisualTree(VisualTreeObject o) { var serializer = new JsonSerializer(); using (var sw = new StringWriter()) { using (var writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; serializer.Serialize(writer, o); return(sw.ToString()); } } }
public static VisualTreeObject Create(DependencyObject o) { VisualTreeObject visualTreeObj = null; UIThreadHelper.Instance.Invoke(() => { visualTreeObj = new VisualTreeObject(); visualTreeObj.Name = o.GetType().Name; visualTreeObj.Properties = VisualTreeProperty.GetProperties(o).Where(p => SupportedWpfProperties.IsSupported(p.Name)).ToList(); visualTreeObj.Children = GetChildren(o); }); return visualTreeObj; }
public static VisualTreeObject Create(DependencyObject o) { VisualTreeObject visualTreeObj = null; UIThreadHelper.Instance.Invoke(() => { visualTreeObj = new VisualTreeObject(); visualTreeObj.Name = o.GetType().Name; visualTreeObj.Properties = VisualTreeProperty.GetProperties(o).Where(p => SupportedWpfProperties.IsSupported(p.Name)).ToList(); visualTreeObj.Children = GetChildren(o); }); return(visualTreeObj); }
public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { var testFileName = fileName + ".tree"; var serializedActual = SerializeVisualTree(actual); var baselineFilePath = fixture.GetSourcePath(testFileName); if (_regenerateBaselineFiles) { TestFiles.UpdateBaseline(baselineFilePath, serializedActual); } else { TestFiles.CompareToBaseLine(baselineFilePath, serializedActual); } }
private static void CompareVisualTree(VisualTreeObject actual, VisualTreeObject expected, bool compareProperty = true) { bool visible = true; // compare actual.Name.Should().Be(expected.Name); var visibility = actual.Properties.FirstOrDefault(p => p.Name == "Visibility"); if (visibility != null) { visible = (visibility.Value != "Collapsed"); } if (compareProperty && visible) { var filteredActual = actual.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); var filteredExpected = expected.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); filteredActual.Should().BeEquivalentTo(filteredExpected); } actual.Children.Count.ShouldBeEquivalentTo(expected.Children.Count); if (visible) { var sortedActualChildren = actual.Children.OrderBy(c => c.Name).ToList(); var sortedExpectedChildren = expected.Children.OrderBy(c => c.Name).ToList(); sortedActualChildren.Count.Should().Be(sortedExpectedChildren.Count); for (int i = 0; i < actual.Children.Count; i++) { CompareVisualTree(sortedActualChildren[i], sortedExpectedChildren[i], compareProperty); } } }
private static void CompareVisualTree(VisualTreeObject actual, VisualTreeObject expected, bool compareProperty = true) { // compare actual.Name.ShouldBeEquivalentTo(expected.Name); if (compareProperty) { var filteredActual = actual.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); var filteredExpected = expected.Properties.Where(p => SupportedWpfProperties.IsSupported(p.Name)); var onlyInActual = filteredActual.Except(filteredExpected); var onlyInExpected = filteredExpected.Except(filteredActual); onlyInActual.Count().ShouldBeEquivalentTo(0); onlyInExpected.Count().ShouldBeEquivalentTo(0); } actual.Children.Count.ShouldBeEquivalentTo(expected.Children.Count); var sortedActualChildren = actual.Children.OrderBy(c => c.Name); var sortedExpectedChildren = expected.Children.OrderBy(c => c.Name); for (int i = 0; i < actual.Children.Count; i++) { CompareVisualTree(sortedActualChildren.ElementAt(i), sortedExpectedChildren.ElementAt(i), compareProperty); } }
private static void CompareVisualTreesImplementation(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { string testFileName = fileName + ".tree"; string testFilePath = fixture.GetDestinationPath(testFileName); if (_regenerateBaselineFiles) { var serializedActual = SerializeVisualTree(actual); string baselineFilePath = fixture.GetSourcePath(testFileName); TestFiles.UpdateBaseline(baselineFilePath, serializedActual); } else { var deserializedExpected = DeserializeVisualTree(testFilePath); CompareVisualTree(actual, deserializedExpected); } }
public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { Action a = () => CompareVisualTreesImplementation(fixture, actual, fileName); a.ShouldNotThrow(); }
public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { CompareVisualTreesImplementation(fixture, actual, fileName); }
public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { CompareVisualTreesImplementation(fixture, actual, fileName); }
public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) { Action a = () => CompareVisualTreesImplementation(fixture, actual, fileName); a.ShouldNotThrow(); }