public static void DocumentAddTasksTest() { const int Max = 3; var doc = new Document(); for (int i = 0; i < Max; ++i) { doc.AddLast(); } Assert.AreEqual( Max, doc.CountDates ); Assert.AreEqual( Max, doc.CountTasks ); }
/// <summary> /// Ignoring the stored document, if it exists, loads a new document /// </summary> /// <param name="f">The file to load the document from.</param> public override Document Load(string f) { var xmlDoc = new XmlDocument(); var doc = new Document(); bool initialDateSet = false; xmlDoc.Load( f ); // Interpret nodes var mainNode = xmlDoc.DocumentElement; if ( mainNode.Name.ToLower() == TasksTag ) { foreach(XmlNode node in mainNode.ChildNodes) { var element = ( node as XmlElement ); if ( element != null ) { if ( element.Name.ToLower() == TaskTag ) { string task; var date = element.Attributes.GetNamedItem( DateTag ); if ( date != null ) { task = element.InnerText; } else { throw new XmlException( "missing date in task" ); } doc.AddLast(); doc.Modify( doc.CountDates - 1, DateTime.Parse( date.InnerText ), task ); } else if ( element.Name.ToLower() == StepsTag ) { doc.Steps.SetSteps( element.InnerText ); } else if ( element.Name.ToLower() == InitialDateTag ) { DateTime result; initialDateSet = DateTime.TryParseExact( element.InnerText, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out result ); if ( initialDateSet ) { doc.InitialDate = result; } } } } } else { throw new XmlException( "missing main node: " + TasksTag ); } // Finish document configuration if ( !initialDateSet ) { if ( doc.CountDates > 0 ) { doc.InitialDate = doc.GetDate( 0 ); } else { doc.InitialDate = DateTime.Now; } } this.Document = doc; return doc; }