コード例 #1
0
        /// <summary>
        /// Compares two object trees.
        /// </summary>
        private void _CompareObjectTree(object firstTree, object secondTree)
        {
            TreeCompareResult result = TreeComparer.CompareLogical(firstTree, secondTree);

            if (CompareResult.Different == result.Result)
            {
                throw new Exception("Failure occurred while comparing object trees.");
            }
        }
コード例 #2
0
        /// <summary>
        ///  1. Take existing xaml test data
        ///  2. Generate WPF object using XamlReader.Load
        ///  3. Use XamlWriter.Save to serialize the Object into Xaml
        ///  4. Verify this generated Xaml matched the expected xaml provided to the test
        ///  5. Use XamlReader.Load to generate a WPF Object using the serialized XAML
        ///  6. Verify that this new object is identical to object created with the original XAML
        /// </summary>
        /// <param name="userCreatedXaml">string containing XAML that has to be RoundTripped</param>
        /// <param name="preSerializedXaml">string containing XAML that we should get if the RoundTrip was successful</param>
        /// <returns>True if RoundTrip is successful otherwise False</returns>
        public static bool Verify(string userCreatedXaml, string preSerializedXaml)
        {
            object wpfObject = null;

            using (Stream userCreatedXamlStream = CreateMemoryStream(userCreatedXaml))
            {
                wpfObject = XamlReader.Load(CreateMemoryStream(userCreatedXaml));
                if (wpfObject == null)
                {
                    Variation.Current.LogMessage("UNEXPECTED: Unable to create wpfObject using XamlReader.Load");
                    return(false);
                }

                Variation.Current.LogMessage("Created wpfObject");
            }

            string newSerializedXaml = XamlWriter.Save(wpfObject);

            Variation.Current.LogMessage("Serialized wpfObject -> newSerializedXaml");

            if (!newSerializedXaml.Equals(preSerializedXaml))
            {
                Variation.Current.LogMessage("UNEXPECTED: newSerializedXaml and test data(preSerializedXaml)do not match");
                SaveFileToLogFolder("Serialized.xaml", newSerializedXaml);
                return(false);
            }

            Variation.Current.LogMessage("newSerializedXaml and test data(preSerializedXaml) match");

            object roundTrippedWpfObject = XamlReader.Load(CreateMemoryStream(newSerializedXaml));

            if (roundTrippedWpfObject == null)
            {
                Variation.Current.LogMessage("UNEXPECTED: Unable to create Round Tripped wpfObject XamlReader.Load(newSerializedXaml)");
                return(false);
            }

            Variation.Current.LogMessage("Created Round Tripped wpfObject");

            TreeCompareResult objectComparisonResult = TreeComparer.CompareLogical(wpfObject, roundTrippedWpfObject);

            if (objectComparisonResult.Result == CompareResult.Different)
            {
                Variation.Current.LogMessage("UNEXPECTED: RoundTripped WPF Object and Original WPF object no not match");
                return(false);
            }

            Variation.Current.LogMessage("RoundTripped WPF Object and Original WPF object match");
            return(true);
        }