Esempio n. 1
0
        public void TestNullXmlSerialization()
        {
            var xmlData = ExternalCollection.Serialize(null);

            try
            {
                Assert.IsEmpty(xmlData, "Serialization of null should produce empty string output");
            }
            catch (Exception)
            {
                Trace.WriteLine("XML Data Dump");
                Trace.WriteLine(xmlData);
                throw;
            }
        }
Esempio n. 2
0
        public void TestEmptyXmlSerialization()
        {
            var xmlData = ExternalCollection.Serialize(new ExternalCollection());

            try
            {
                var xmlDoc = LoadXml(xmlData);
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection", "Serialization of empty collection should produce empty element output");
            }
            catch (Exception)
            {
                Trace.WriteLine("XML Data Dump");
                Trace.WriteLine(xmlData);
                throw;
            }
        }
Esempio n. 3
0
        public void TestSupportedXmlSerializationModes()
        {
            var external1 = new MockExternal {
                Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Data = "Data1"
            };
            var external2 = new MockXmlSerializableExternal {
                Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Data = "Data2"
            };

            Assert.IsFalse(typeof(IXmlSerializable).IsAssignableFrom(external1.GetType()), "One of the two externals should not be IXmlSerializable");
            Assert.IsTrue(typeof(IXmlSerializable).IsAssignableFrom(external2.GetType()), "One of the two externals should be IXmlSerializable");

            var xmlData = ExternalCollection.Serialize(new ExternalCollection {
                external1, external2
            });

            try
            {
                var xmlDoc = LoadXml(xmlData);

                AssertXmlNodeValue(typeof(MockExternal).FullName, xmlDoc, "/ExternalCollection/External[1]/@Type", "Type should be namespace qualified type name");
                AssertXmlNodeValue("external1", xmlDoc, "/ExternalCollection/External[1]/*/Name", "external1");
                AssertXmlNodeValue("Label1", xmlDoc, "/ExternalCollection/External[1]/*/Label", "external1");
                AssertXmlNodeValueIgnoreCase("true", xmlDoc, "/ExternalCollection/External[1]/*/Enabled", "external1");                 // ignore case - the default XML serializer is case insensitive for bools
                AssertXmlNodeValue("Normal", xmlDoc, "/ExternalCollection/External[1]/*/WindowStyle", "external1");
                AssertXmlNodeValue("Data1", xmlDoc, "/ExternalCollection/External[1]/*/Data", "external1");

                AssertXmlNodeValue(typeof(MockXmlSerializableExternal).FullName, xmlDoc, "/ExternalCollection/External[2]/@Type", "Type should be namespace qualified type name");
                AssertXmlNodeValue("external2", xmlDoc, "/ExternalCollection/External[2]/*/@Name", "external2");
                AssertXmlNodeValue("Label2", xmlDoc, "/ExternalCollection/External[2]/*/@Label", "external2");
                AssertXmlNodeValue("False", xmlDoc, "/ExternalCollection/External[2]/*/@Enabled", "external2");
                AssertXmlNodeValue("Hidden", xmlDoc, "/ExternalCollection/External[2]/*/@WindowStyle", "external2");
                AssertXmlNodeValue("Data2", xmlDoc, "/ExternalCollection/External[2]/*/Data", "external2");
            }
            catch (Exception)
            {
                Trace.WriteLine("XML Data Dump");
                Trace.WriteLine(xmlData);
                throw;
            }
        }
Esempio n. 4
0
        public void TestXmlSerialization()
        {
            var external1 = new CommandLineExternal {
                Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Command = @"C:\Temp\CommandA.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "", Username = "", Domain = "", AllowMultiValueFields = false
            };
            var external2 = new CommandLineExternal {
                Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Command = @"\ComputerA\ShareB\CommandC.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "\"$FILENAMEONLY$\"", Username = "******", Domain = "\u958B\u5C01\u5E9C", AllowMultiValueFields = true, MultiValueFieldSeparator = "\" \""
            };
            var external3 = new CommandLineExternal {
                Name = "external3"
            };
            var xmlData = ExternalCollection.Serialize(new ExternalCollection {
                external1, external2, external3
            });

            try
            {
                var xmlDoc = LoadXml(xmlData);

                AssertXmlNodeValue(typeof(CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[1]/@Type", "Type should be namespace qualified type name");
                AssertXmlNodeValue("external1", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Name", "external1");
                AssertXmlNodeValue("Label1", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Label", "external1");
                AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Enabled", "external1");
                AssertXmlNodeValue("Normal", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/WindowStyle", "external1");
                AssertXmlNodeValue("C:\\Temp\\CommandA.cmd", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Command", "external1");
                AssertXmlNodeValue("$DIRECTORY$", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/WorkingDirectory", "external1");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Arguments", "external1");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Username", "external1");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Domain", "external1");
                AssertXmlNodeValue("false", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/AllowMultiValueFields", "external1");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/MultiValueFieldSeparator", "external1");

                AssertXmlNodeValue(typeof(CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[2]/@Type", "Type should be namespace qualified type name");
                AssertXmlNodeValue("external2", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Name", "external2");
                AssertXmlNodeValue("Label2", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Label", "external2");
                AssertXmlNodeValue("false", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Enabled", "external2");
                AssertXmlNodeValue("Hidden", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/WindowStyle", "external2");
                AssertXmlNodeValue("\\ComputerA\\ShareB\\CommandC.cmd", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Command", "external2");
                AssertXmlNodeValue("$DIRECTORY$", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/WorkingDirectory", "external2");
                AssertXmlNodeValue("\"$FILENAMEONLY$\"", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Arguments", "external2");
                AssertXmlNodeValue("\u5305\u9752\u5929", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Username", "external2");
                AssertXmlNodeValue("\u958B\u5C01\u5E9C", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Domain", "external2");
                AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/AllowMultiValueFields", "external2");
                AssertXmlNodeValue("\" \"", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/MultiValueFieldSeparator", "external2");

                AssertXmlNodeValue(typeof(CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[3]/@Type", "Type should be namespace qualified type name");
                AssertXmlNodeValue("external3", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Name", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Label", "external3");
                AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Enabled", "external3");
                AssertXmlNodeValue("Normal", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/WindowStyle", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Command", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/WorkingDirectory", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Arguments", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Username", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Domain", "external3");
                AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/AllowMultiValueFields", "external3");
                AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/MultiValueFieldSeparator", "external3");
            }
            catch (Exception)
            {
                Trace.WriteLine("XML Data Dump");
                Trace.WriteLine(xmlData);
                throw;
            }
        }