Example #1
0
 private static string SerializeVisualTree(VisualTreeObject o) {
     var serializer = new XmlSerializer(typeof(VisualTreeObject));
     using (var stringWriter = new StringWriter()) {
         serializer.Serialize(stringWriter, o);
         return stringWriter.ToString();
     }
 }
Example #2
0
        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);
            }
        }
Example #3
0
        private static string SerializeVisualTree(VisualTreeObject o)
        {
            var serializer = new XmlSerializer(typeof(VisualTreeObject));

            using (var stringWriter = new StringWriter()) {
                serializer.Serialize(stringWriter, o);
                return(stringWriter.ToString());
            }
        }
Example #4
0
 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();
         }
     }
 }
Example #5
0
        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);
            }
        }
Example #6
0
        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());
                }
            }
        }
Example #7
0
        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;
        }
Example #8
0
        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);
        }
Example #9
0
        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);
            }
        }
Example #10
0
        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);
                }
            }
        }
Example #11
0
        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);
            }
        }
Example #12
0
        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);
            }
        }
Example #13
0
        public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName)
        {
            Action a = () => CompareVisualTreesImplementation(fixture, actual, fileName);

            a.ShouldNotThrow();
        }
Example #14
0
 public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) {
     CompareVisualTreesImplementation(fixture, actual, fileName);
 }
Example #15
0
 public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName)
 {
     CompareVisualTreesImplementation(fixture, actual, fileName);
 }
Example #16
0
 public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName) {
     Action a = () => CompareVisualTreesImplementation(fixture, actual, fileName);
     a.ShouldNotThrow();
 }