SerializeTo() публичный Метод

Utility method for serializing the component.
public SerializeTo ( Stream stream ) : void
stream System.IO.Stream The stream to write the component to.
Результат void
        public void WriteErrors_StatusConfigurationFormatProblem()
        {
            CreateNeccessaryDir();

            var statusConfigContents = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                + "<Report xmlns=\"com.iinteractive.reporting\">"
                // The quotations after Type="Service is missing.
                + "<Service Name=\"SomeServiceName\" Type=\"Service />"
                + "</Report>";

            var component = new Component()
            {
                Name = "site-status.Test",
                Version = "0.1.123"
            };

            #region PREPARES FOR THE TEST
            var statusConfig = new Report();

            using (var writer = new StreamWriter(Path.Combine(SiteStatusDirectory, "Site.ver")))
            {
                component.SerializeTo(writer);
            }

            using (var writer = new StreamWriter(ConfigurationPath))
            {
                writer.Write(statusConfigContents);
            }
            #endregion

            var target = new SiteStatusRepository("");
            var result = "";
            using(var writer = new StringWriter())
            {
                target.WriteErrors(writer);
                result = writer.ToString();
            }

            var serializer = new XmlSerializer(typeof(List<SiteStatusIssue>), new Type[] { typeof(SiteStatusIssue) });
            using(var reader = new StringReader(result))
            {
                var actualErrors = (List<SiteStatusIssue>)serializer.Deserialize(reader);
                Assert.IsNotNull(actualErrors);
                Assert.AreNotEqual(0, actualErrors.Count);
            }
        }
        /// <summary>
        /// Writes the .ver file, and STatusConfiguration.xml for testing.
        /// </summary>
        /// <param name="component">The contents of the .ver file.</param>
        /// <param name="services">The contents of the StatusConfiguration.xml 
        /// file.</param>
        private void WriteFiles(Component component, List<Service> services = null)
        {
            #region PREPARES FOR THE TEST
            var statusConfig = new Report();
            if (services == null)
                services = new List<Service>();

            statusConfig.Service = services.ToArray();

            using (var writer = new StreamWriter(Path.Combine(SiteStatusDirectory, "Site.ver")))
            {
                component.SerializeTo(writer);
            }

            using (var writer = new StreamWriter(ConfigurationPath))
            {
                statusConfig.SerializeTo(writer);
            }
            #endregion
        }
        public void WriteErrors_StatusConfigurationDoesNotExistError()
        {
            DeleteDir();

            CreateNeccessaryDir();

            var component = new Component()
            {
                Name = "site-status.Test",
                Version = "0.1.123"
            };

            List<Service> services = new List<Service>()
            {
                new Service
                {
                    Name = "NoDbConnectionMonitor",
                    Type = ServiceType.Database
                }
            };

            #region PREPARES FOR THE TEST
            var statusConfig = new Report();
            if (services == null)
                services = new List<Service>();

            statusConfig.Service = services.ToArray();

            using (var writer = new StreamWriter(Path.Combine(SiteStatusDirectory, "Site.ver")))
            {
                component.SerializeTo(writer);
            }
            #endregion

            var target = new SiteStatusRepository("");
            var result = "";
            using (var writer = new StringWriter())
            {
                target.WriteErrors(writer);
                result = writer.ToString();
            }

            var serializer = new XmlSerializer(typeof(List<SiteStatusIssue>), new Type[] { typeof(SiteStatusIssue) });
            using (var reader = new StringReader(result))
            {
                var actualErrors = (List<SiteStatusIssue>)serializer.Deserialize(reader);
                Assert.IsNotNull(actualErrors);
                Assert.AreNotEqual(0, actualErrors.Count);
            }
        }