Esempio n. 1
0
        public void TestEmptyElementXmlDeserialization()
        {
            const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<ExternalCollection />";

            var collection = ExternalCollection.Deserialize(testXml);

            Assert.IsNotNull(collection, "Deserialization of empty element tag should produce empty collection");
            Assert.AreEqual(0, collection.Count, "Deserialization of empty element tag should produce empty collection");
        }
Esempio n. 2
0
        public void TestEmptyCollectionXmlDeserialization()
        {
            const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<ExternalCollection>\r\n"
                                   + "</ExternalCollection>";

            var collection2 = ExternalCollection.Deserialize(testXml);

            Assert.IsNotNull(collection2, "Deserialization of full element tag with no descendants should produce empty collection");
            Assert.AreEqual(0, collection2.Count, "Deserialization of full element tag with no descendants should produce empty collection");
        }
Esempio n. 3
0
        public void TestSupportedXmlDeserializationModes()
        {
            const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<ExternalCollection>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockExternal\">\r\n"
                                   + "    <MockExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
                                   + "      <Name>external1</Name>\r\n"
                                   + "      <Label>Label1</Label>\r\n"
                                   + "      <Enabled>true</Enabled>\r\n"
                                   + "      <WindowStyle>Normal</WindowStyle>\r\n"
                                   + "      <Data>Data1</Data>\r\n"
                                   + "    </MockExternal>\r\n"
                                   + "  </External>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external2\" Label=\"Label2\" Enabled=\"False\" WindowStyle=\"Hidden\">\r\n"
                                   + "      <Data>Data2</Data>\r\n"
                                   + "    </MockXmlSerializableExternal>\r\n"
                                   + "  </External>\r\n"
                                   + "</ExternalCollection>";

            var expectedExternal1 = new MockExternal {
                Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Data = "Data1"
            };
            var expectedExternal2 = new MockXmlSerializableExternal {
                Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Data = "Data2"
            };

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

            var collection = ExternalCollection.Deserialize(testXml);

            Assert.IsNotNull(collection, "Deserialization returned null");
            Assert.AreEqual(2, collection.Count, "Deserialization returned collection with wrong number of entries");

            var external1 = CollectionUtils.SelectFirst(collection, e => e.Name == "external1");

            Assert.IsNotNull(external1, "Failed to deserialize external1");
            Assert.IsInstanceOf(typeof(MockExternal), external1, "external1: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal1, (MockExternal)external1, "external1");

            var external2 = CollectionUtils.SelectFirst(collection, e => e.Name == "external2");

            Assert.IsNotNull(external2, "Failed to deserialize external2");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external2, "external2: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal2, (MockXmlSerializableExternal)external2, "external2");
        }
Esempio n. 4
0
        public void TestXmlDeserializationFaultTolerance()
        {
            // if you encounter "unspecified errors" during compile, reformat the test data - csc has a maximum line/statement length (particularly important during pdb generation)
            const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<ExternalCollection>\r\n"
                                   + "  <Junk>\r\n"
                                   + "    <Junk2>\r\n"
                                   + "      <Junk3>\r\n"
                                   + "        <Junk4 />\r\n"
                                   + "      </Junk3>\r\n"
                                   + "    </Junk2>\r\n"
                                   + "  </Junk>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external1\" Label=\"Label1\" Enabled=\"True\" WindowStyle=\"Normal\">\r\n"
                                   + "      <Data>Data1</Data>\r\n"
                                   + "    </MockXmlSerializableExternal>\r\n"
                                   + "  </External>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "    <badgarbled xml\"\">>>> ]]>\r\n"
                                   + "  </IExternal>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external3\" Label=\"\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\">\r\n"
                                   + "  </IExternal>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external4\" Label=\"\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "    <Junk>\r\n"
                                   + "      <Junk2 />\r\n"
                                   + "    </Junk>]]>\r\n"
                                   + "  </IExternal>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external5\" Label=\"\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal\">\r\n"
                                   + "    <MockBrokenExternal Name=\"bad1\" Label=\"dfdsfds\" Enabled=\"True\" WindowStyle=\"Normal\">\r\n"
                                   + "    </MockBrokenExternal>\r\n"
                                   + "  </External>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external6\" Label=\"\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal\" />\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal\">\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external7\" Label=\"\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <External Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockBrokenExternal\">\r\n"
                                   + "    <MockBrokenExternal Name=\"bad1\" Label=\"dfdsfds\" Enabled=\"True\" WindowStyle=\"Normal\" />\r\n"
                                   + "  </External>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.Tests.MockXmlSerializableExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "    <MockXmlSerializableExternal Name=\"external2\" Label=\"Label2\" Enabled=\"False\" WindowStyle=\"Hidden\">\r\n"
                                   + "      <Data>Data2</Data>\r\n"
                                   + "    </MockXmlSerializableExternal>]]>\r\n"
                                   + "  </IExternal>\r\n"
                                   + "</ExternalCollection>";

            var expectedExternal1 = new MockXmlSerializableExternal {
                Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Data = "Data1"
            };
            var expectedExternal2 = new MockXmlSerializableExternal {
                Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Data = "Data2"
            };
            var expectedExternal3 = new MockXmlSerializableExternal {
                Name = "external3", Label = ""
            };
            var expectedExternal4 = new MockXmlSerializableExternal {
                Name = "external4", Label = ""
            };
            var expectedExternal5 = new MockXmlSerializableExternal {
                Name = "external5", Label = ""
            };
            var expectedExternal6 = new MockXmlSerializableExternal {
                Name = "external6", Label = ""
            };
            var expectedExternal7 = new MockXmlSerializableExternal {
                Name = "external7", Label = ""
            };

            var collection = ExternalCollection.Deserialize(testXml);

            Assert.IsNotNull(collection, "Deserialization returned null");
            Assert.AreEqual(7, collection.Count, "Deserialization returned collection with wrong number of entries");

            var external1 = CollectionUtils.SelectFirst(collection, e => e.Name == "external1");

            Assert.IsNotNull(external1, "Failed to deserialize external1");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external1, "external1: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal1, (MockXmlSerializableExternal)external1, "external1");

            var external2 = CollectionUtils.SelectFirst(collection, e => e.Name == "external2");

            Assert.IsNotNull(external2, "Failed to deserialize external2");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external2, "external2: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal2, (MockXmlSerializableExternal)external2, "external2");

            var external3 = CollectionUtils.SelectFirst(collection, e => e.Name == "external3");

            Assert.IsNotNull(external3, "Failed to deserialize external3");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external3, "external3: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal3, (MockXmlSerializableExternal)external3, "external3");

            var external4 = CollectionUtils.SelectFirst(collection, e => e.Name == "external4");

            Assert.IsNotNull(external4, "Failed to deserialize external4");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external4, "external4: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal4, (MockXmlSerializableExternal)external4, "external4");

            var external5 = CollectionUtils.SelectFirst(collection, e => e.Name == "external5");

            Assert.IsNotNull(external5, "Failed to deserialize external5");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external5, "external5: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal5, (MockXmlSerializableExternal)external5, "external5");

            var external6 = CollectionUtils.SelectFirst(collection, e => e.Name == "external6");

            Assert.IsNotNull(external6, "Failed to deserialize external6");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external6, "external6: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal6, (MockXmlSerializableExternal)external6, "external6");

            var external7 = CollectionUtils.SelectFirst(collection, e => e.Name == "external7");

            Assert.IsNotNull(external7, "Failed to deserialize external7");
            Assert.IsInstanceOf(typeof(MockXmlSerializableExternal), external7, "external7: Wrong concrete implementation of IExternal");
            AssertMockExternal(expectedExternal7, (MockXmlSerializableExternal)external7, "external7");
        }
Esempio n. 5
0
        public void TestLegacyXmlDeserialization()
        {
            // if you encounter "unspecified errors" during compile, reformat the test data - csc has a maximum line/statement length (particularly important during pdb generation)
            const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<ExternalCollection>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
                                   + "  <Name>external1</Name>\r\n"
                                   + "  <Label>Label1</Label>\r\n"
                                   + "  <Enabled>true</Enabled>\r\n"
                                   + "  <WindowStyle>Normal</WindowStyle>\r\n"
                                   + "  <Command>C:\\Temp\\CommandA.cmd</Command>\r\n"
                                   + "  <WorkingDirectory>$DIRECTORY$</WorkingDirectory>\r\n"
                                   + "  <Arguments />\r\n"
                                   + "  <Username />\r\n"
                                   + "  <Domain />\r\n"
                                   + "  <AllowMultiValueFields>false</AllowMultiValueFields>\r\n"
                                   + "</CommandLineExternal>]]></IExternal>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
                                   + "  <Name>external2</Name>\r\n"
                                   + "  <Label>Label2</Label>\r\n"
                                   + "  <Enabled>false</Enabled>\r\n"
                                   + "  <WindowStyle>Hidden</WindowStyle>\r\n"
                                   + "  <Command>\\ComputerA\\ShareB\\CommandC.cmd</Command>\r\n"
                                   + "  <WorkingDirectory>$DIRECTORY$</WorkingDirectory>"
                                   + "  <Arguments>\"$FILENAMEONLY$\"</Arguments>"
                                   + "  <Username>\u5305\u9752\u5929</Username>"
                                   + "  <Domain>\u958B\u5C01\u5E9C</Domain>"
                                   + "  <AllowMultiValueFields>true</AllowMultiValueFields>\r\n"
                                   + "  <MultiValueFieldSeparator>\" \"</MultiValueFieldSeparator>\r\n"
                                   + "</CommandLineExternal>]]></IExternal>\r\n"
                                   + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
                                   + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
                                   + "  <Name>external3</Name>\r\n"
                                   + "</CommandLineExternal>]]></IExternal>\r\n"
                                   + "</ExternalCollection>";

            var expectedExternal1 = new CommandLineExternal {
                Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Command = @"C:\Temp\CommandA.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "", Username = "", Domain = "", AllowMultiValueFields = false
            };
            var expectedExternal2 = 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 expectedExternal3 = new CommandLineExternal {
                Name = "external3"
            };

            var collection = ExternalCollection.Deserialize(testXml);

            Assert.IsNotNull(collection, "Deserialization returned null");
            Assert.AreEqual(3, collection.Count, "Deserialization returned collection with wrong number of entries");

            var external1 = CollectionUtils.SelectFirst(collection, e => e.Name == "external1");

            Assert.IsNotNull(external1, "Failed to deserialize external1");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external1, "external1: Wrong concrete implementation of IExternal");
            AssertCommandLineExternal(expectedExternal1, (CommandLineExternal)external1, "external1");

            var external2 = CollectionUtils.SelectFirst(collection, e => e.Name == "external2");

            Assert.IsNotNull(external2, "Failed to deserialize external2");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external2, "external2: Wrong concrete implementation of IExternal");
            AssertCommandLineExternal(expectedExternal2, (CommandLineExternal)external2, "external2");

            var external3 = CollectionUtils.SelectFirst(collection, e => e.Name == "external3");

            Assert.IsNotNull(external3, "Failed to deserialize external3");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external3, "external3: Wrong concrete implementation of IExternal");
            AssertCommandLineExternal(expectedExternal3, (CommandLineExternal)external3, "external3");
        }
Esempio n. 6
0
        public void TestNullXmlDeserialization()
        {
            var collection = ExternalCollection.Deserialize(string.Empty);

            Assert.IsNull(collection, "Deserialization of null should produce null output");
        }