public void DeserializeBrokenXml()
        {
            string sXml = "<tasks><task>&</task></tasks>";

            ITaskCollection taskCollection = TaskCollectionSerializer.Deserialize(new StringReader(sXml));

            Assert.IsNull(taskCollection);
        }
        public void DeserializeWrongRoot()
        {
            string sXml = "<projects><task name=\"Name\"></task></projects>";

            ITaskCollection taskCollection = TaskCollectionSerializer.Deserialize(new StringReader(sXml));

            Assert.AreEqual(0, taskCollection.Count);
        }
        public void SerializeWithNullWriter()
        {
            StringBuilder sb = new StringBuilder();

            Log.Writer = new StringWriter(sb);
            ITaskCollection taskCollection = new TaskCollection();

            TaskCollectionSerializer.Serialize(taskCollection, null);
            Assert.That(sb.ToString().Contains("Could not serialize tasks because writer is null"));
        }
        public void Serialize()
        {
            TaskCollection taskCollection = new TaskCollection();

            taskCollection.Add(new Task("task_name"));

            XmlNode xml = TaskCollectionSerializer.Serialize(taskCollection);

            Assert.IsTrue(xml.InnerXml.Contains("task_name"));
        }
        public void Deserialize()
        {
            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateElement("tasks")).InnerXml =
                TaskSerializer.Serialize(new Task("task1")).OuterXml;

            ITaskCollection taskCollection = TaskCollectionSerializer.Deserialize(doc);

            Assert.IsTrue(taskCollection.Contains("task1"));
        }
        public void SerializeWithNullTaskCollection()
        {
            StringBuilder sb = new StringBuilder();

            Log.Writer = new StringWriter(sb);
            ITaskCollection taskCollection = new TaskCollection();

            TaskCollectionSerializer.Serialize(null, Log.Writer);

            Assert.That(sb.ToString().Contains("Could not serialize null tasks collection"));
        }
        public void SerializeTwoTasks()
        {
            TaskCollection taskCollection = new TaskCollection();

            taskCollection.AddRange(new Task[] { new Task("task1"), new Task("task2") });

            XmlNode xml = TaskCollectionSerializer.Serialize(taskCollection);

            Assert.IsTrue(xml.InnerXml.Contains("task1"));
            Assert.IsTrue(xml.InnerXml.Contains("task2"));
        }
        public void SerializeToWriter()
        {
            ITaskCollection taskCollection = new TaskCollection();

            taskCollection.Add(new Task("task1"));
            StringBuilder sb     = new StringBuilder();
            TextWriter    writer = new StringWriter(sb);

            TaskCollectionSerializer.Serialize(taskCollection, writer);
            writer.Close();

            Assert.IsTrue(sb.ToString().Contains("task1"));
        }