Exemplo n.º 1
0
 public void op_Xml_FileInfoMissing()
 {
     using (var temp = new TempDirectory())
     {
         Assert.NotNull(ConfigXml.Load <DataCollection>(temp.Info.ToFile("example.xml")));
     }
 }
Exemplo n.º 2
0
        public void op_OnCreated()
        {
            using (var temp = new TempDirectory())
            {
                var file     = temp.Info.ToFile("example.xml");
                var expected = new DataCollection
                {
                    {
                        "foo", "bar"
                    }
                };

                ConfigXml.Load <DataCollection>(file);
                file.Create(expected.XmlSerialize());
            }
        }
Exemplo n.º 3
0
        public static T Xml <T>(FileInfo file) where T : new()
        {
            Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty);
            if (null == file)
            {
                throw new ArgumentNullException("file");
            }

            if (_types.ContainsKey(typeof(T)))
            {
                return((T)_types[typeof(T)]);
            }

#if NET20
            _xml = _xml ?? new List <ConfigXml>();
            var count = _xml.Count;
            for (var i = 0; i < count; i++)
            {
                var item = _xml[count - 1 - i];
                if (item.Changed)
                {
                    _xml.Remove(item);
                }
            }

            ConfigXml xml = null;
            foreach (var item in _xml)
            {
                if (string.Equals(item.Info.FullName, file.FullName, StringComparison.OrdinalIgnoreCase))
                {
                    xml = item;
                    break;
                }
            }
#else
            _xml = _xml ?? new HashSet <ConfigXml>();
            _xml.RemoveWhere(x => x.Changed);
            var xml = _xml.FirstOrDefault(x => string.Equals(x.Info.FullName, file.FullName, StringComparison.OrdinalIgnoreCase));
#endif
            if (null == xml)
            {
                xml = ConfigXml.Load <T>(file);
                _xml.Add(xml);
            }

            return((T)xml.Value);
        }
Exemplo n.º 4
0
        public void op_Xml_FileInfo()
        {
            using (var temp = new TempDirectory())
            {
                var file     = temp.Info.ToFile("example.xml");
                var expected = new DataCollection
                {
                    {
                        "foo", "bar"
                    }
                };

                file.Create(expected.XmlSerialize());
                var actual = ConfigXml.Load <DataCollection>(file);

                Assert.Equal(expected, actual.Value);
            }
        }
Exemplo n.º 5
0
 public void op_Xml_FileInfoNull()
 {
     Assert.Throws <ArgumentNullException>(() => ConfigXml.Load <DataCollection>(null));
 }