示例#1
0
        public void ReadTest()
        {
            // create sample data
            List <TestObject> data = new List <TestObject>();

            data.Add(new TestObject()
            {
                Label = "FIRST", Date = DateTime.UtcNow.Date
            });
            data.Add(new TestObject()
            {
                Label = "SECOND", Date = DateTime.UtcNow.AddDays(1).Date
            });
            data.Add(new TestObject()
            {
                Label = "THIRD", Date = DateTime.UtcNow.AddDays(2).Date
            });

            // initilaize reader
            XMLReaderWriter <List <TestObject> > xmlReader = new XMLReaderWriter <List <TestObject> >("XMLReaderTestFileRead.xml", _folderName);

            // save
            xmlReader.Save(data);

            // now load the data
            List <TestObject> readData = xmlReader.Read();

            // check for data inside
            Assert.AreEqual(3, readData.Count());
            for (int index = 0; index < 3; index++)
            {
                Assert.AreEqual(data[index].Date.Date, readData[index].Date.Date);
                Assert.AreEqual(data[index].Label, readData[index].Label);
            }
        }
示例#2
0
        /// <summary>
        /// Saves the days
        /// </summary>
        public void Save()
        {
            // get day data
            List <DayData> dayData = _dayDatas.Values.ToList();

            // save
            XMLReaderWriter <List <DayData> > writer = new XMLReaderWriter <List <DayData> >("DayData.xml", "AppData");

            writer.Save(dayData);
        }
示例#3
0
        /// <summary>
        /// Loads meta-data for all days..
        /// </summary>
        private void Initialize()
        {
            XMLReaderWriter <List <DayMetadatum> > reader = new XMLReaderWriter <List <DayMetadatum> >("DayMetadata.xml", "AppData");
            List <DayMetadatum> metadata = reader.Read();

            if (metadata != null)
            {
                foreach (DayMetadatum metadatum in metadata)
                {
                    _holidays.Add(metadatum.Date.Date, metadatum);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Loads data for all days..
        /// </summary>
        private void Initialize()
        {
            XMLReaderWriter <List <DayData> > reader = new XMLReaderWriter <List <DayData> >("DayData.xml", "AppData");
            List <DayData> dayDatas = reader.Read();

            if (dayDatas != null)
            {
                foreach (DayData dayData in dayDatas)
                {
                    _dayDatas.Add(dayData.Date.Date, dayData);
                }
            }
        }
示例#5
0
        public void SaveTest()
        {
            // create sample data
            List <TestObject> data = new List <TestObject>();

            data.Add(new TestObject()
            {
                Label = "FIRST", Date = DateTime.UtcNow.Date
            });
            data.Add(new TestObject()
            {
                Label = "SECOND", Date = DateTime.UtcNow.AddDays(1).Date
            });
            data.Add(new TestObject()
            {
                Label = "THIRD", Date = DateTime.UtcNow.AddDays(2).Date
            });

            // initilaize reader
            string folderPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            folderPath = Path.Combine(folderPath, _folderName);
            XMLReaderWriter <List <TestObject> > xmlReader = new XMLReaderWriter <List <TestObject> >("XMLReaderTestFileSave.xml", _folderName);

            // save
            xmlReader.Save(data);

            // file path + name
            string filePath = Path.Combine(folderPath, "XMLReaderTestFileSave.xml");

            // check if file exists
            Assert.IsTrue(File.Exists(filePath));
            // load
            XDocument document = XDocument.Load(filePath);
            XElement  xElement = document.Elements().First();

            // check for data inside
            Assert.AreEqual(3, xElement.Elements().Count());
            for (int index = 0; index < 3; index++)
            {
                Assert.AreEqual(data[index].Date.Date, Convert.ToDateTime(xElement.Elements().ElementAt(index).Element("Date").Value).Date);
                Assert.AreEqual(data[index].Label, xElement.Elements().ElementAt(index).Element("Label").Value.ToString());
            }
        }