Exemple #1
0
        public static void Save(string testListenersFile)
        {
            // Expand each assembly path.
            foreach (TestListenerDescriptor listener in _testListenersCollection)
            {
                string testlisteners = TestProperties.TestConfigs;
                listener.Assembly = TestProperties.FixupString(listener.Assembly, "TestListeners");
            }

            TestListenerCollection.SerializeToFile(_testListenersCollection, testListenersFile);
        }
        public static void SerializeToFile(TestListenerCollection testListeners, string filePath)
        {
            XmlWriter writer = null;

            try
            {
                // Fixup assembly path to TestListeners definition.
                foreach (TestListenerDescriptor descriptor in testListeners)
                {
                    if (!string.IsNullOrEmpty(descriptor.Assembly))
                    {
                        TestProperties.FixupString(descriptor.Assembly, "TestConfigs");
                    }
                }

                DataContractSerializer serializer = new DataContractSerializer(typeof(TestListenerCollection));

                var settings = new XmlWriterSettings()
                {
                    Indent = true
                };

                using (writer = XmlWriter.Create(filePath, settings))
                {
                    serializer.WriteObject(writer, testListeners);
                }

                writer.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    // Close file.
                    writer.Close();
                }
            }
        }